ar-阿拉伯语
de -德语
es 西班牙
hi 印地语
in 印度语
fr 法语
bn 孟加拉语
it 意大利
ja 日本
pt 葡萄牙
zh 中文
ru 俄罗斯
bg 保加利亚文
ca 加泰罗尼亚文
cs 捷克文
cy 塞浦路斯(土耳其语或者希腊)
da 丹麦语
el 希腊语
et 爱沙尼亚语
fa 波斯语
fi 芬兰语
ht 海地语
hu 胸牙利语
id 印度尼西亚语
iw 希伯来语
ko 韩语
lt 立陶宛语
lv 拉脱维尼亚语
ms 马来语
mt 马耳他语
nl 荷兰语
no 挪威语
pl 波兰语
ro 罗马尼亚语(没有话写葡萄牙)
sk 斯洛伐克语
sl 斯洛文尼亚语
sv 瑞典语
th 泰语
tr 土耳其语
uk 乌克兰语
ur 乌尔都语
vi 越南语
hu 匈牙利文
af 南非荷兰语
kaz 哈萨克斯坦
tr 土耳其
el 希腊语
pl 波兰语
th 泰语
ro 罗马尼亚
sw 肯尼亚 斯瓦希里语
tl 菲律宾
vi 越南
ms 马拉语
ne 尼泊尔
public class Change {
//
public static void main(String[] args) {
//你可以单独复制出来一个Strings.xml来进行操作
String pathname = "C:\\Users\\liuan\\Desktop\\fanyi\\strings.xml";
String myText = "MyText.txt";
String newText = "newText.txt";
String finalText = "finalText.txt";
String otherStr = "..........."; // 先执行步骤1 然后翻译完毕 然后执行步骤2
// one(pathname, myText, newText, otherStr);
two(pathname, myText, newText, otherStr, finalText);
}
private static void two(String fileName, String myText, String newText, String otherStr, String finalText) {
//读取翻译好的文件 和带特殊字符的文件 然后合成 新的文件
//new 是带...的
File newfile = new File(fileName+newText);
File myTextfile = new File(fileName+myText);
BufferedReader newreader = null;
BufferedReader myTextreader = null;
StringBuffer stringBuffer = new StringBuffer();
try {
newreader = new BufferedReader(new FileReader(newfile));
myTextreader = new BufferedReader(new FileReader(myTextfile));
String tempString = null;
// 一次读入一行,直到读入null为文件结束
while ((tempString = newreader.readLine()) != null) {
String translate = myTextreader.readLine();
if (tempString.contains("string") && tempString.contains("name") && tempString.contains("=") && tempString.contains(">")) {
//把文件的其他字符 替换成myText中的字符
String replace = tempString.replace(otherStr, translate);
stringBuffer.append(replace+" \n");
}
}
String text = stringBuffer.toString();
File file1 = new File(fileName + finalText);
if (file1.exists()) {
file1.delete();
}
FileOutputStream fileOutputStream = new FileOutputStream(file1);
fileOutputStream.write(text.getBytes());
fileOutputStream.close();
System.out.println(text);
newreader.close();
myTextreader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (newreader != null) {
try {
newreader.close();
} catch (IOException e1) {
}
}
if (myTextreader != null) {
try {
myTextreader.close();
} catch (IOException e1) {
}
}
}
}
private static void one(String pathname, String myText, String newText, String otherStr) {
//步骤1 读取xml文件 并且翻译完毕 生成.txt 并且手动替换翻译过的文件
readFileByLines(pathname, myText);
//步骤2
//生成 带转义符的...........文件
produceDianDianDian(pathname, newText, otherStr);
}
private static void produceDianDianDian( String fileName, String newText,String otherStr) {
File file = new File(fileName);
BufferedReader reader = null;
StringBuffer stringBuffer = new StringBuffer();
try {
System.out.println("生成 带特殊符" + otherStr + "的文件 本目录生成的" + newText);
reader = new BufferedReader(new FileReader(file));
String tempString = null;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
if (tempString.contains("esources>")) {
continue;
}
String bgStr = tempString;
;
if (tempString.contains("string") && tempString.contains("name") && tempString.contains("=") && tempString.contains(">")) {
tempString = tempString.replace("</string>", "");
String substring = bgStr.substring(0, bgStr.indexOf(">") + 1);
stringBuffer.append(substring + otherStr + "</string> \n");
} else {
stringBuffer.append(tempString + " \n");
}
}
String text = stringBuffer.toString();
FileOutputStream fileOutputStream = new FileOutputStream(fileName + newText);
fileOutputStream.write(text.getBytes());
fileOutputStream.close();
System.out.println(text);
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
public static void readFileByLines(String fileName, String text2) {
File file = new File(fileName);
BufferedReader reader = null;
StringBuffer stringBuffer = new StringBuffer();
try {
System.out.println("复制以下内容,去谷歌翻译 翻译后替换 本目录生成的" + text2);
reader = new BufferedReader(new FileReader(file));
String tempString = null;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
// 显示行号
if (tempString.contains("esources>")) {
continue;
}
if (tempString.contains("string") && tempString.contains("name") && tempString.contains("=") && tempString.contains(">")) {
tempString = tempString.substring(tempString.indexOf(">") + 1);
tempString = tempString.replace("</string>", "");
} else {
stringBuffer.append(" \n");
}
stringBuffer.append(tempString + " \n");
}
String text = stringBuffer.toString();
File file1 = new File(fileName + text2);
if (file1.exists()) {
file1.delete();
}
FileOutputStream fileOutputStream = new FileOutputStream(file1);
fileOutputStream.write(text.getBytes());
fileOutputStream.close();
System.out.println(text);
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
}
谷歌翻译地址:点击打开链接 {需要谷歌浏览器 并且翻墙}
ps 1 法语中有单引号的字符串 可以用双引号把整个字符串包裹起来
2 执行完步骤1 就不用再执行步骤1 了 只需要翻译后替换mytext.txt中的文本 然后再执行步骤2 就可以了
3 执行完打印台会输出结果 也可以直接复制
*********************************************更多国家语言****************************************************
bn_BD孟加拉语(孟加拉)
bo_CN 博多语(中国)
bo_IN 博多语(印度)
ce_PH 塞布安诺语(菲律宾)
de_LI 德语(列支敦士登)
fa_AF 波斯语(阿富汗)
fa_IR 波斯语(伊朗)
gu_IN 古吉拉特语(印度)
ha_GH 豪萨语(加纳)
ha_NE 豪萨语(尼日尔)
ha_NG 豪萨语(尼日利亚)
he_IL 希伯来语(以色列)
in
iw 希伯来语
ka_GE 南高加索语(格鲁吉亚)
kk_KZ 哈萨克语(哈萨克斯坦)
km_KH 高棉语(柬埔寨)
lo_LA 寮语(老挝)
lt_LT 立陶宛语(立陶宛)
lv_LV 拉托维亚语(列托)(拉脱维亚)
ms_MY 马来西亚语(马来西亚)
my_MM 缅甸语(缅甸)
nb_NO 挪威语 (挪威)
nl_BE 荷兰语 (比利时)
nl_NL 荷兰语 (荷兰)
pa_IN 旁遮普语(印度)
pa_PK 旁遮普语(巴基斯坦)
pl_PL 波兰语 (波兰)
pt_BR 葡萄牙语 (巴西)
pt_PT 葡萄牙文 (葡萄牙)
rm_CH 拉丁罗曼语(瑞士)
ro_RO 罗马尼亚语 (罗马尼亚)
ru_RU 俄文 (俄罗斯)
sk_SK 斯洛伐克文 (斯洛伐克)
sl_SI 斯洛文尼亚文 (斯洛文尼亚)
sr_RS 塞尔维亚语(塞尔维亚)
sv_SE 瑞典语 (瑞典)
sw_KE 瓦西里语(肯尼亚)
sw_TZ 瓦西里语(坦桑尼亚)
ta_IN 泰米尔语(印度)
te_IN 泰卢固语(印度)
th_TH 泰语 (泰国)
tl_PH 塔加洛语(菲律宾)
tr_TR 土耳其语 (土耳其)
ug_CN 维吾尔语(中国)
uk_UA 乌克兰语 (乌克兰)
ur_IN 乌尔都语(印度)
ur_PK 乌尔都语(巴基斯坦)
vi_VN 越南语(越南)
zh_CN 简体中语(中国)
zh_TW 繁体中语(台湾)
以下转自: http://hi.baidu.com/snowmelody1020/item/58aad9c3abcd9322e80f2ec0
用于Android的国际化。在res目录下的对应字符 串目录。例如中文的话就在工程res目录下新建一个values-zh-rCN目录,然后将你翻译的strings.xml,或者arrays.xml放 在下面就可以了。下面给出国家的文件目录名称(应用中默认文件夹名为values为英文,加入后缀后变为相应国家)
下面的表格中列出了所有可用于各种系统设置的语言代码。
语言代码
af 南非荷兰语 | sq 阿尔巴尼亚语 |
ar-sa 阿拉伯语(沙特阿拉伯) | ar-iq 阿拉伯语(伊拉克) |
ar-eg 阿拉伯语(埃及) | ar-ly 阿拉伯语(利比亚) |
ar-dz 阿拉伯语(阿尔及利亚) | ar-ma 阿拉伯语(摩洛哥) |
ar-tn 阿拉伯语(突尼斯) | ar-om 阿拉伯语(阿曼) |
ar-ye 阿拉伯语(也门) | ar-sy 阿拉伯语(叙利亚) |
ar-jo 阿拉伯语(约旦) | ar-lb 阿拉伯语(黎巴嫩) |
ar-kw 阿拉伯语(科威特) | ar-ae 阿拉伯语(阿拉伯联合酋长国) |
ar-bh 阿拉伯语(巴林) | ar-qa 阿拉伯语(卡塔尔) |
eu 巴斯克语 | bg 保加利亚语 |
be 贝劳语 | ca 加泰罗尼亚语 |
zh-tw 中文(中国台湾) | zh-cn 中文(中华人民共和国) |
zh-hk 中文(中国香港特别行政区) | zh-sg 中文(新加坡) |
hr 克罗地亚语 | cs 捷克语 |
da 丹麦语 | nl 荷兰语(标准) |
nl-be 荷兰语(比利时) | en 英语 |
en-us 英语(美国) | en-gb 英语(英国) |
en-au 英语(澳大利亚) | en-ca 英语(加拿大) |
en-nz 英语(新西兰) | en-ie 英语(爱尔兰) |
en-za 英语(南非) | en-jm 英语(牙买加) |
en 英语(加勒比) | en-bz 英语(伯利兹) |
en-tt 英语(特立尼达) | et 爱沙尼亚语 |
fo 法罗语 | fa 波斯语 |
fi 芬兰语 | fr 法语(标准) |
fr-be 法语(比利时) | fr-ca 法语(加拿大) |
fr-ch 法语(瑞士) | fr-lu 法语(卢森堡) |
gd 盖尔语(苏格兰) | gd-ie 盖尔语(爱尔兰) |
de 德语(标准) | de-ch 德语(瑞士) |
de-at 德语(奥地利) | de-lu 德语(卢森堡) |
de-li 德语(列支敦士登) | el 希腊语 |
he 希伯来语 | hi 北印度语 |
hu 匈牙利语 | is 冰岛语 |
in 印度尼西亚语 | it 意大利语(标准) |
it-ch 意大利语(瑞士) | ja 日语 |
ko 朝鲜语 | ko 朝鲜语(韩国) |
lv 拉脱维亚语 | lt 立陶宛语 |
mk FYRO 马其顿语 | ms 马来西亚语 |
mt 马耳他语 | no 挪威语(博克马尔) |
no 挪威语(尼诺斯克) | pl 波兰语 |
pt-br 葡萄牙语(巴西) | pt 葡萄牙语(葡萄牙) |
rm 拉丁语系 | ro 罗马尼亚语 |
ro-mo 罗马尼亚语(摩尔达维亚) | ru 俄语 |
ru-mo 俄语(摩尔达维亚) | sz 萨摩斯语(拉普兰) |
sr 塞尔维亚语(西里尔) | sr 塞尔维亚语(拉丁) |
sk 斯洛伐克语 | sl 斯洛文尼亚语 |
sb 索布语 | es 西班牙语(西班牙传统) |
es-mx 西班牙语(墨西哥) | es 西班牙语(西班牙现代) |
es-gt 西班牙语(危地马拉) | es-cr 西班牙语(哥斯达黎加) |
es-pa 西班牙语(巴拿马) | es-do 西班牙语(多米尼加共和国) |
es-ve 西班牙语(委内瑞拉) | es-co 西班牙语(哥伦比亚) |
es-pe 西班牙语(秘鲁) | es-ar 西班牙语(阿根廷) |
es-ec 西班牙语(厄瓜多尔) | es-cl 西班牙语(智利) |
es-uy 西班牙语(乌拉圭) | es-py 西班牙语(巴拉圭) |
es-bo 西班牙语(玻利维亚) | es-sv 西班牙语(萨尔瓦多) |
es-hn 西班牙语(洪都拉斯) | es-ni 西班牙语(尼加拉瓜) |
es-pr 西班牙语(波多黎各) | sx 苏图语 |
sv 瑞典语 | sv-fi 瑞典语(芬兰) |
th 泰语 | ts 汤加语 |
tn 瓦纳语 | tr 土耳其语 |
uk 乌克兰语 | ur 乌尔都语 |
ve 文达语 | vi 越南语 |
xh 科萨语 | ji 依地语 |
zu 祖鲁语 |
国家代号与区号 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
android多国语言文件夹文件汇总如下:
Arabic, Egypt (ar_EG) -----------------------------阿拉伯语,埃及
Arabic, Israel (ar_IL) -------------------------------阿拉伯语,以色列
Bulgarian, Bulgaria (bg_BG) ---------------------保加利亚语,保加利亚
Catalan, Spain (ca_ES) ---------------------------加泰隆语,西班牙
Czech, Czech Republic (cs_CZ) -----------------捷克语,捷克共和国
Danish, Denmark(da_DK) ------------------------丹麦语,丹麦
German, Austria (de_AT) -------------------------德语,奥地利
German, Switzerland (de_CH) -------------------德语,瑞士
German, Germany (de_DE) ----------------------德语,德国
German, Liechtenstein (de_LI) ------------------德语,列支敦士登的
Greek, Greece (el_GR) ----------------------------希腊语,希腊
English, Australia (en_AU) -------------------------英语,澳大利亚
English, Canada (en_CA) --------------------------英语,加拿大
English, Britain (en_GB) ----------------------------英语,英国
English, Ireland (en_IE) -----------------------------英语,爱尔兰
English, India (en_IN) --------------------------------英语,印度
English, New Zealand (en_NZ) ---------------------英语,新西兰
English, Singapore(en_SG) --------------------------英语,新加坡
English, US (en_US) -----------------------------------英语,美国
English, Zimbabwe (en_ZA) --------------------------英语,津巴布韦
Spanish (es_ES) ----------------------------------------西班牙
Spanish, US (es_US) -----------------------------------西班牙语,美国
Finnish, Finland (fi_FI) ---------------------------------芬兰语,芬兰
French, Belgium (fr_BE) -------------------------------法语,比利时
French, Canada (fr_CA) -------------------------------法语,加拿大
French, Switzerland (fr_CH) --------------------------法语,瑞士
French, France (fr_FR) --------------------------------法语,法国
Hebrew, Israel (he_IL) ---------------------------------希伯来语,以色列
Hindi, India (hi_IN) -------------------------------------印地语,印度
Croatian, Croatia (hr_HR) ----------------------------克罗地亚语,克罗地亚
Hungarian, Hungary (hu_HU) ------------------------匈牙利语,匈牙利
Indonesian, Indonesia (id_ID) ------------------------印尼语,印尼
Italian, Switzerland (it_CH) ----------------------------意大利语,瑞士
Italian, Italy (it_IT) ---------------------------------------意大利语,意大利
Japanese (ja_JP) ----------------------------------------日语
Korean (ko_KR) ------------------------------------------朝鲜语
Lithuanian, Lithuania (lt_LT) --------------------------立陶宛语,立陶宛
Latvian, Latvia (lv_LV) ---------------------------------拉托维亚语,拉托维亚
Norwegian-Bokmol, Norway(nb_NO) ---------------挪威语,挪威
Dutch, Belgium (nl_BE) --------------------------------荷兰语,比利时
Dutch, Netherlands (nl_NL) ---------------------------荷兰语,荷兰
Polish (pl_PL) -------------------------------------------波兰
Portuguese, Brazil (pt_BR) ---------------------------葡萄牙语,巴西
Portuguese, Portugal (pt_PT) ------------------------葡萄牙语,葡萄牙
Romanian, Romania (ro_RO) ------------------------罗马尼亚语,罗马尼亚
Russian (ru_RU) ----------------------------------------俄语
Slovak, Slovakia (sk_SK) ------------------------------斯洛伐克语,斯洛伐克
Slovenian, Slovenia (sl_SI) ---------------------------斯洛文尼亚语,斯洛文尼亚
Serbian (sr_RS) ----------------------------------------塞尔维亚语
Swedish, Sweden (sv_SE) ----------------------------瑞典语,瑞典
Thai, Thailand (th_TH) --------------------------------泰语,泰国
Tagalog, Philippines (tl_PH) --------------------------菲律宾语,菲律宾
Turkish, Turkey (tr_TR) -------------------------------土耳其语,土耳其
Ukrainian, Ukraine (uk_UA) --------------------------联合王国
Vietnamese, Vietnam (vi_VN) -----------------------越南语,越南
Chinese, PRC (zh_CN)--------------------------------中文,中国
Chinese, Taiwan (zh_TW)-----------------------------中文,台湾
- 顶
http://www.aipai.com/c41/OjgjIiEqICVqJWQsIg.html 自己写的一个工具
package com.tools.dbattery.common;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
/**
* Created by liuan on 2018/1/11.
*/
public class multiLanguageA {
public static void main(String[] args) {
//脱壳
// int buzhou = 1;
//群翻译 也可以单翻译 注意格式en----
int buzhou = 2;
//生成翻译文本 af----ar----cs----de----en----es----fr----hi----hr----in----it----ja----ms----pt----ro----sv----th----tl----zh----
// int buzhou = 3;
// 根据yuyan22生成翻译目录 valus-ar/string.xml
// int buzhou = 4;
String pathname = System.getProperty("user.dir") + "\\app\\src\\main\\java\\com\\tools\\dbattery\\common\\originTextView";
String myText = "MyText";
String myTextEx = "MyTextEx";
String newText = "newText";
String finalText = "finalText";
String xmlPath = "xmlPath";
String otherStr = "..........."; // 先执行步骤1 然后翻译完毕 然后执行步骤2
String yuyan22 = "bn----"; // 先执行步骤1 然后翻译完毕 然后执行步骤2
// String overStrXml = "D:\\work\\battery\\battery5\\battery\\app\\src\\main\\res"; // 先执行步骤1 然后翻译完毕 然后执行步骤2
String overStrXml = "D:\\work\\antivirus\\antivirus7\\Security\\app\\src\\main\\res"; // 先执行步骤1 然后翻译完毕 然后执行步骤2
if (buzhou == 1) {
one(pathname, myText, newText, otherStr);
} else if (buzhou == 2) {
System.out.println(yuyan22 + "Ready to copy");
two_22(pathname, myTextEx, newText, otherStr, finalText, yuyan22, overStrXml);
System.out.println(yuyan22 + "Copy completed");
} else if (buzhou == 3) {
System.out.println("Please copy the following to yuyan22 Then go to step 2");
extractMultipleLanguageNames(overStrXml);
} else if (buzhou == 4) {
System.out.println("Create initial documents based on multilingual countries and <yuan22>");
createValuesFils(yuyan22, overStrXml);
System.out.println("Create sucess");
}
}
private static void createValuesFils(String yuyan22, String overStrXml) {
String[] split = yuyan22.split("----");
for (int i = 0; i < split.length; i++) {
File file = new File(overStrXml, "values-" + split[i]);
if (file.exists()) {
System.out.println("Do not need to create");
} else {
file.mkdir();
FileOutputStream fileOutputStream = null;
try {
File file1 = new File(file.getAbsolutePath(), "strings.xml");
file1.createNewFile();
fileOutputStream = new FileOutputStream(file1);
fileOutputStream.write(("<resources>\n" + "</resources>").getBytes());
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Created " + file.getName() + " Sucess");
}
}
}
private static void extractMultipleLanguageNames(String overStrXml) {
StringBuffer stringBuffer = new StringBuffer();
File file = new File(overStrXml);
File[] files = file.listFiles();
for (File file1 : files) {
String name = file1.getName();
if (name.contains("values-")) {
String replace = name.replace("values-", "");
stringBuffer.append(replace + "----");
}
}
System.out.println(stringBuffer.toString());
}
private static final String TAG = "multiLanguage";
private static void two_22(String fileName, String myTextEx, String newText, String otherStr, String finalText, String yuyan22, String overStrXml) {
String[] multiLanguage = yuyan22.split("----");
System.out.println("You have to do it " + multiLanguage.length + "multi-language");
System.out.println("I ask you for the first time I can help you format it Well you then copied to<originTextViewMyTextEx.xml>file");
System.out.println("If it is the first time to do so, please deduct 1 and press Enter");
String separated = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
File myTextfile = new File(fileName + myTextEx);
Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();
if (i == 1) {
createMutiLauguageMyTextEx(myTextfile, multiLanguage, separated);
System.out.println("Once created, please put the translated content in originTextViewMyTextEx.xml\nExecute the following java program again\n" +
"Do not press 1 next time!~~~");
return;
}
//翻译脚本开始了
//读取文本并且分割
String contentText = readToString(myTextfile.getAbsolutePath());
String newTextStr = readToString(fileName + newText);
String[] multiLanguageContent = contentText.split(separated);
if (multiLanguage.length != multiLanguageContent.length - 1) {
System.out.println("The current parameters do not match");
return;
}
String[] newTextContent = newTextStr.split("\n");
// System.out.println("multiLanguageContent" + Arrays.toString(multiLanguageContent));
// System.out.println("newTextContent" + Arrays.toString(newTextContent));
StringBuffer stringBuffer = new StringBuffer();
for (int i1 = 0; i1 < multiLanguage.length; i1++) {
//对于单个多语言操作
//读取翻译好的文件 和带特殊字符的文件 然后合成 新的文件
//new 是带...的
String tempString = null;
StringBuffer sbCurrentText = new StringBuffer();
try {
//new 是带...的
String[] myTextreader = multiLanguageContent[i1 + 1].split("\n");
// System.out.println("myTextreader" + Arrays.toString(myTextreader));
for (int i2 = 0; i2 < myTextreader.length; i2++) {
// 为了过滤分隔符号
String translate = myTextreader[i2];
if (i2 == 0 && myTextreader.length != 1 && multiLanguage[i2].equals(multiLanguage[i1])) {
System.out.println("" + multiLanguage[i2]);
String str = "The current multilingual translation is " + ">>>>>>>>>>" + multiLanguage[i1] + "<<<<<<<<<<";
System.out.println(str);
stringBuffer.append(str + "\n");
continue;
} else if (i2 == 0 && myTextreader.length != 1) {
String str = "IMHO At present, there are mistakes in multiple languages" + ">>>>>>>>>>" + multiLanguage[i1] + "<<<<<<<<<<";
System.out.println(str);
continue;
}
if (myTextreader.length == 1) {
String str = "The current multilingual translation is " + ">>>>>>>>>>" + multiLanguage[i1] + "<<<<<<<<<<";
System.out.println(str);
tempString = newTextContent[i2];
} else {
tempString = newTextContent[i2 - 1];
}
// System.out.println("tempString" + tempString);
translate = translate.replace("%1 $ d", "%1$d");
translate = translate.replace("? 1 $ d", "%1$d");
translate = translate.replace("%2 $ d", "%2$d");
translate = translate.replace("? 2 $ d", "%2$d");
translate = translate.replace("% 1 $ d", "%1$d");
translate = translate.replace("% 2 $ d", "%2$d");
translate = translate.replace("%d", "%d");
translate = translate.replace("? D", "%d");
translate = translate.replace("% D", "%d");
//google有一些固定的翻译格式 改成正确的
translate = translate.replace("% 1 $ s", "%1$s");
translate = translate.replace("%1 $ S", "%1$s");
translate = translate.replace("% 1 $ s", "%1$s");
translate = translate.replace("%1 $ s", "%1$s");
translate = translate.replace("1% $ s", "%1$s");
translate = translate.replace("% 1 $", "%1$s");
translate = translate.replace("? 1 $ s", "%1$s");
translate = translate.replace("% 2 $", "%2$s");
translate = translate.replace("% 2 $", "%2$s");
translate = translate.replace("%2 $ s", "%2$s");
translate = translate.replace("? 2 $ s", "%2$s");
translate = translate.replace("% 2 $ s", "%2$s");
translate = translate.replace("% 2 $ s", "%2$s");
translate = translate.replace("2% $ s", "%2$s");
translate = translate.replace("& amp", "&");
translate = translate.replace("& \u200B\u200Bamp", "&");
translate = translate.replace("%s", "%s");
translate = translate.replace("% s", "%s");
translate = translate.replace("% s", "%s");
translate = translate.replace("% S", "%s");
translate = translate.replace("? s", "%s");
translate = translate.replace("? S", "%s");
translate = translate.replace("%S", "%s");
translate = translate.replace("</ i>", "</i>");
translate = translate.replace("\\ \"", "\\\"");
translate = translate.replace("\\ r\\ n", "\\r\\n");
translate = translate.replace("\\ n", "\\n");
translate = translate.replace("\\ N", "\\n");
translate = translate.replace("\\ п", "\\n");
translate = translate.replace("? ?", "%s");
translate = translate.replace("? 1S", "%1s");
translate = translate.replace("% 1s", "%1s");
translate = translate.replace("% 1s", "%1s");
translate = translate.replace("%1s", "%1s");
translate = translate.replace("\\ r \\n", "\\r\\n");
if (tempString.contains("string") && tempString.contains("name") && tempString.contains("=") && tempString.contains(">")) {
//把文件的其他字符 替换成myText中的字符
translate = "\"" + translate.trim() + "\"";
String replace = tempString.replace(otherStr, translate);
stringBuffer.append(replace + " \n");
sbCurrentText.append(replace + " \n");
}
//写出到xml
}
File file = new File(overStrXml + "\\values-" + multiLanguage[i1], "strings.xml");
// System.out.println(overStrXml + "\\values-" + multiLanguage[i1]+ "strings.xml");
writeToXml(file, multiLanguage[i1], sbCurrentText);
write2Local(fileName, finalText, stringBuffer);
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void writeToXml(File file, String s, StringBuffer sbCurrentText) throws IOException {
File file2 = file;
if (!file2.exists()) {
System.out.println("What to do ghost >>>>>>>>>>" + s + "<<<<<<<<<< resource file does not exist can not be copied replacement");
return;
} else {
//去掉文件最后的resources
StringBuffer stringBuffer3 = new StringBuffer();
BufferedReader bufferedReader2 = new BufferedReader(new FileReader(file2));
String tempString2 = null;
// 一次读入一行,直到读入null为文件结束
while ((tempString2 = bufferedReader2.readLine()) != null) {
if (tempString2.contains("</resources>")) {
tempString2 = tempString2.replace("</resources>", "");
stringBuffer3.append(tempString2 + " \n");
} else if (tempString2.contains("\n")) {
stringBuffer3.append(tempString2);
} else {
stringBuffer3.append(tempString2 + " \n");
}
}
//补上
FileOutputStream fileOutputStream3 = new FileOutputStream(file2, false);
fileOutputStream3.write(stringBuffer3.toString().getBytes());
fileOutputStream3.close();
bufferedReader2.close();
//补上
FileOutputStream fileOutputStream2 = new FileOutputStream(file2, true);
fileOutputStream2.write((sbCurrentText + "</resources>").getBytes());
// System.out.println("sbCurrentText" + sbCurrentText);
fileOutputStream2.close();
System.out.println(s + " It's Ok");
}
}
private static void write2Local(String fileName, String finalText, StringBuffer stringBuffer) throws IOException {
String text = stringBuffer.toString();
//写到最终的文件里
File file1 = new File(fileName + finalText);
if (file1.exists()) {
file1.delete();
}
FileOutputStream fileOutputStream = new FileOutputStream(file1);
fileOutputStream.write(text.getBytes());
fileOutputStream.close();
}
public static String readToString(String fileName) {
File file = new File(fileName);
Long filelength = file.length();
byte[] filecontent = new byte[filelength.intValue()];
try {
FileInputStream in = new FileInputStream(file);
in.read(filecontent);
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
return new String(filecontent);
} catch (Exception e) {
// System.err.println("The OS does not support " + encoding);
e.printStackTrace();
return null;
}
}
private static void createMutiLauguageMyTextEx(File myTextfile, String[] multiLanguage, String separated) {
FileOutputStream fileOutputStream3 = null;
try {
fileOutputStream3 = new FileOutputStream(myTextfile, false);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
for (int i = 0; i < multiLanguage.length; i++) {
try {
fileOutputStream3.write((separated + multiLanguage[i] + "\n").getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
try {
fileOutputStream3.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void one(String pathname, String myText, String newText, String otherStr) {
//步骤1 读取xml文件 并且翻译完毕 生成.txt 并且手动替换翻译过的文件
readFileByLines(pathname, myText);
//步骤2
//生成 带转义符的...........文件
produceDianDianDian(pathname, newText, otherStr);
}
public static void readFileByLines(String fileName, String myText) {
File file = new File(fileName);
BufferedReader reader = null;
StringBuffer stringBuffer = new StringBuffer();
try {
System.out.println("Copy the following content to google translation.............." + myText);
reader = new BufferedReader(new FileReader(file));
String tempString = null;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
// 显示行号
if (tempString.contains("esources>")) {
continue;
}
if (tempString.contains("string") && tempString.contains("name") && tempString.contains("=") && tempString.contains(">")) {
tempString = tempString.substring(tempString.indexOf(">") + 1);
tempString = tempString.replace("</string>", "");
// System.out.println("提出出的字符串|" + tempString + "| 长度为" + tempString.length());
System.out.println(tempString);
//去掉分号
if (tempString.substring(0, 1).equals("\"") && (tempString.substring(tempString.length() - 1, tempString.length()).equals("\""))) {
tempString = tempString.substring(1, tempString.length() - 1);
}
if (tempString.substring(0, 1).equals("\"") && (tempString.substring(tempString.length() - 4, tempString.length()).equals("\" "))) {
tempString = tempString.substring(1, tempString.length() - 4);
}
} else {
stringBuffer.append("\n");
}
stringBuffer.append(tempString + "\n");
}
write2Local(fileName, myText, stringBuffer);
// System.out.println(text);
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
private static void produceDianDianDian(String fileName, String newText, String otherStr) {
File file = new File(fileName);
BufferedReader reader = null;
StringBuffer stringBuffer = new StringBuffer();
try {
System.out.println("Generate special characters " + otherStr + "The file generated by this directory " + newText);
reader = new BufferedReader(new FileReader(file));
String tempString = null;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
if (tempString.contains("esources>")) {
continue;
}
String bgStr = tempString;
;
if (tempString.contains("string") && tempString.contains("name") && tempString.contains("=") && tempString.contains(">")) {
tempString = tempString.replace("</string>", "");
String substring = bgStr.substring(0, bgStr.indexOf(">") + 1);
stringBuffer.append(substring + otherStr + "</string> \n");
} else {
stringBuffer.append(tempString + " \n");
}
}
String text = stringBuffer.toString();
FileOutputStream fileOutputStream = new FileOutputStream(fileName + newText);
fileOutputStream.write(text.getBytes());
fileOutputStream.close();
System.out.println(text);
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
}