多语言适配
阅读原文时间:2021年04月21日阅读:1
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为英文,加入后缀后变为相应国家)

en 英文

en_US 英文 (美国)

ar 阿拉伯文

ar_AE 阿拉伯文 (阿拉伯联合酋长国)

ar_BH 阿拉伯文 (巴林)

ar_DZ 阿拉伯文 (阿尔及利亚)

ar_EG 阿拉伯文 (埃及)

ar_IQ 阿拉伯文 (伊拉克)

ar_JO 阿拉伯文 (约旦)

ar_KW 阿拉伯文 (科威特)

ar_LB 阿拉伯文 (黎巴嫩)

ar_LY 阿拉伯文 (利比亚)

ar_MA 阿拉伯文 (摩洛哥)

ar_OM 阿拉伯文 (阿曼)

ar_QA 阿拉伯文 (卡塔尔)

ar_SA 阿拉伯文 (沙特阿拉伯)

ar_SD 阿拉伯文 (苏丹)

ar_SY 阿拉伯文 (叙利亚)

ar_TN 阿拉伯文 (突尼斯)

ar_YE 阿拉伯文 (也门)

be 白俄罗斯文

be_BY 白俄罗斯文 (白俄罗斯)

bg 保加利亚文

bg_BG 保加利亚文 (保加利亚)

ca 加泰罗尼亚文

ca_ES 加泰罗尼亚文 (西班牙)

ca_ES_EURO 加泰罗尼亚文 (西班牙,Euro)

cs 捷克文

cs_CZ 捷克文 (捷克共和国)

da 丹麦文

da_DK 丹麦文 (丹麦)

de 德文

de_AT 德文 (奥地利)

de_AT_EURO 德文 (奥地利,Euro)

de_CH 德文 (瑞士)

de_DE 德文 (德国)

de_DE_EURO 德文 (德国,Euro)

de_LU 德文 (卢森堡)

de_LU_EURO 德文 (卢森堡,Euro)

el 希腊文

el_GR 希腊文 (希腊)

en_AU 英文 (澳大利亚)

en_CA 英文 (加拿大)

en_GB 英文 (英国)

en_IE 英文 (爱尔兰)

en_IE_EURO 英文 (爱尔兰,Euro)

en_NZ 英文 (新西兰)

en_ZA 英文 (南非)

es 西班牙文

es_BO 西班牙文 (玻利维亚)

es_AR 西班牙文 (阿根廷)

es_CL 西班牙文 (智利)

es_CO 西班牙文 (哥伦比亚)

es_CR 西班牙文 (哥斯达黎加)

es_DO 西班牙文 (多米尼加共和国)

es_EC 西班牙文 (厄瓜多尔)

es_ES 西班牙文 (西班牙)

es_ES_EURO 西班牙文 (西班牙,Euro)

es_GT 西班牙文 (危地马拉)

es_HN 西班牙文 (洪都拉斯)

es_MX 西班牙文 (墨西哥)

es_NI 西班牙文 (尼加拉瓜)

et 爱沙尼亚文

es_PA 西班牙文 (巴拿马)

es_PE 西班牙文 (秘鲁)

es_PR 西班牙文 (波多黎哥)

es_PY 西班牙文 (巴拉圭)

es_SV 西班牙文 (萨尔瓦多)

es_UY 西班牙文 (乌拉圭)

es_VE 西班牙文 (委内瑞拉)

et_EE 爱沙尼亚文 (爱沙尼亚)

fi 芬兰文

fi_FI 芬兰文 (芬兰)

fi_FI_EURO 芬兰文 (芬兰,Euro)

fr 法文

fr_BE 法文 (比利时)

fr_BE_EURO 法文 (比利时,Euro)

fr_CA 法文 (加拿大)

fr_CH 法文 (瑞士)

fr_FR 法文 (法国)

fr_FR_EURO 法文 (法国,Euro)

fr_LU 法文 (卢森堡)

fr_LU_EURO 法文 (卢森堡,Euro)

hr 克罗地亚文

hr_HR 克罗地亚文 (克罗地亚)

hu 匈牙利文

hu_HU 匈牙利文 (匈牙利)

is 冰岛文

is_IS 冰岛文 (冰岛)

it 意大利文

it_CH 意大利文 (瑞士)

it_IT 意大利文 (意大利)

it_IT_EURO 意大利文 (意大利,Euro)

iw 希伯来文

iw_IL 希伯来文 (以色列)

ja 日文

ja_JP 日文 (日本)

ko 朝鲜文

ko_KR 朝鲜文 (南朝鲜)

lt 立陶宛文

lt_LT 立陶宛文 (立陶宛)

lv 拉托维亚文(列托)

lv_LV 拉托维亚文(列托) (拉脱维亚)

mk 马其顿文

mk_MK 马其顿文 (马其顿王国)

nl 荷兰文

nl_BE 荷兰文 (比利时)

nl_BE_EURO 荷兰文 (比利时,Euro)

nl_NL 荷兰文 (荷兰)

nl_NL_EURO 荷兰文 (荷兰,Euro)

no 挪威文

no_NO 挪威文 (挪威)

no_NO_NY 挪威文 (挪威,Nynorsk)

pl 波兰文

pl_PL 波兰文 (波兰)

pt 葡萄牙文

pt_BR 葡萄牙文 (巴西)

pt_PT 葡萄牙文 (葡萄牙)

pt_PT_EURO 葡萄牙文 (葡萄牙,Euro)

ro 罗马尼亚文

ro_RO 罗马尼亚文 (罗马尼亚)

ru 俄文

ru_RU 俄文 (俄罗斯)

sh 塞波尼斯-克罗地亚文

sh_YU 塞波尼斯-克罗地亚文 (南斯拉夫)

sk 斯洛伐克文

sk_SK 斯洛伐克文 (斯洛伐克)

sl 斯洛文尼亚文

sl_SI 斯洛文尼亚文 (斯洛文尼亚)

sq 阿尔巴尼亚文

sq_AL 阿尔巴尼亚文 (阿尔巴尼亚)

sr 塞尔维亚文

sr_YU 塞尔维亚文 (南斯拉夫)

sv 瑞典文

sv_SE 瑞典文 (瑞典)

th 泰文

th_TH 泰文 (泰国)

tr 土耳其文

tr_TR 土耳其文 (土耳其)

uk 乌克兰文

uk_UA 乌克兰文 (乌克兰)

zh 中文

zh_CN 中文 (中国)

zh_HK 中文 (香港)

zh_TW 中文 (台湾)

下面的表格中列出了所有可用于各种系统设置的语言代码。

语言代码

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 祖鲁语

国家代号与区号


Countries and Regions

国家或地区

国际域名缩写

电话代码

时差

Angola

安哥拉

AO

244

-7

Afghanistan

阿富汗

AF

93

0

Albania

阿尔巴尼亚

AL

355

-7

Algeria

阿尔及利亚

DZ

213

-8

Andorra

安道尔共和国

AD

376

-8

Anguilla

安圭拉岛

AI

1264

-12

Antigua and Barbuda

安提瓜和巴布达

AG

1268

-12

Argentina

阿根廷

AR

54

-11

Armenia

亚美尼亚

AM

374

-6

Ascension

阿森松

247

-8

Australia

澳大利亚

AU

61

+2

Austria

奥地利

AT

43

-7

Azerbaijan

阿塞拜疆

AZ

994

-5

Bahamas

巴哈马

BS

1242

-13

Bahrain

巴林

BH

973

-5

Bangladesh

孟加拉国

BD

880

-2

Barbados

巴巴多斯

BB

1246

-12

Belarus

白俄罗斯

BY

375

-6

Belgium

比利时

BE

32

-7

Belize

伯利兹

BZ

501

-14

Benin

贝宁

BJ

229

-7

Bermuda Is.

百慕大群岛

BM

1441

-12

Bolivia

玻利维亚

BO

591

-12

Botswana

博茨瓦纳

BW

267

-6

Brazil

巴西

BR

55

-11

Brunei

文莱

BN

673

0

Bulgaria

保加利亚

BG

359

-6

Burkina-faso

布基纳法索

BF

226

-8

Burma

缅甸

MM

95

-1.3

Burundi

布隆迪

BI

257

-6

Cameroon

喀麦隆

CM

237

-7

Canada

加拿大

CA

1

-13

Cayman Is.

开曼群岛

1345

-13

Central African Republic

中非共和国

CF

236

-7

Chad

乍得

TD

235

-7

Chile

智利

CL

56

-13

China

中国

CN

86

0

Colombia

哥伦比亚

CO

57

0

Congo

刚果

CG

242

-7

Cook Is.

库克群岛

CK

682

-18.3

Costa Rica

哥斯达黎加

CR

506

-14

Cuba

古巴

CU

53

-13

Cyprus

塞浦路斯

CY

357

-6

Czech Republic

捷克

CZ

420

-7

Denmark

丹麦

DK

45

-7

Djibouti

吉布提

DJ

253

-5

Dominica Rep.

多米尼加共和国

DO

1890

-13

Ecuador

厄瓜多尔

EC

593

-13

Egypt

埃及

EG

20

-6

EI Salvador

萨尔瓦多

SV

503

-14

Estonia

爱沙尼亚

EE

372

-5

Ethiopia

埃塞俄比亚

ET

251

-5

Fiji

斐济

FJ

679

+4

Finland

芬兰

FI

358

-6

France

法国

FR

33

-8

French Guiana

法属圭亚那

GF

594

-12

Gabon

加蓬

GA

241

-7

Gambia

冈比亚

GM

220

-8

Georgia

格鲁吉亚

GE

995

0

Germany

德国

DE

49

-7

Ghana

加纳

GH

233

-8

Gibraltar

直布罗陀

GI

350

-8

Greece

希腊

GR

30

-6

Grenada

格林纳达

GD

1809

-14

Guam

关岛

GU

1671

+2

Guatemala

危地马拉

GT

502

-14

Guinea

几内亚

GN

224

-8

Guyana

圭亚那

GY

592

-11

Haiti

海地

HT

509

-13

Honduras

洪都拉斯

HN

504

-14

Hongkong

香港

HK

852

0

Hungary

匈牙利

HU

36

-7

Iceland

冰岛

IS

354

-9

India

印度

IN

91

-2.3

Indonesia

印度尼西亚

ID

62

-0.3

Iran

伊朗

IR

98

-4.3

Iraq

伊拉克

IQ

964

-5

Ireland

爱尔兰

IE

353

-4.3

Israel

以色列

IL

972

-6

Italy

意大利

IT

39

-7

Ivory Coast

科特迪瓦

225

-6

Jamaica

牙买加

JM

1876

-12

Japan

日本

JP

81

+1

Jordan

约旦

JO

962

-6

Kampuchea (Cambodia )

柬埔寨

KH

855

-1

Kazakstan

哈萨克斯坦

KZ

327

-5

Kenya

肯尼亚

KE

254

-5

Korea

韩国

KR

82

+1

Kuwait

科威特

KW

965

-5

Kyrgyzstan

吉尔吉斯坦

KG

331

-5

Laos

老挝

LA

856

-1

Latvia

拉脱维亚

LV

371

-5

Lebanon

黎巴嫩

LB

961

-6

Lesotho

莱索托

LS

266

-6

Liberia

利比里亚

LR

231

-8

Libya

利比亚

LY

218

-6

Liechtenstein

列支敦士登

LI

423

-7

Lithuania

立陶宛

LT

370

也可参考 : http://www.oschina.net/code/explore/glibc-2.9/localedata/locales

实例参照:

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) {
                }
            }
        }
    }




}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章