问题描述
我一直在寻找的答案过网,但我似乎并没有能够找到可供我与他们确切的显示名称应用的所有语言的完整列表。 (我发现很多名单,但他们都不相匹配的语言字符串我有阅读上。)最近的一个,我发现是的是不完整的。
我编码在C#中的插件,其中文本从SDL Trados Studio中导出到Word和语言在Word中相应的设置。
我需要写蒙上这些语言名与其相关的 Word.Language
相当于一个自定义的方法。这是因为TRADOS(使用Windows文化和.NET Framework 4.5)比 Word.Language
名称不同的语言(区域)的名字。
在匈牙利是一样的, TraditionalChinese ( Word.Language
)的中国(繁体)在TRADOS。
我确实有字.Languages 已
公共静态类LanguageList
{
公共静态只读的HashSet< LanguageItem> _languageList =新的HashSet< LanguageItem>(新[]
{
新LanguageItem(阿拉伯(沙特阿拉伯),1025),
新LanguageItem(保加利亚1026),
新LanguageItem(加泰罗尼亚,1027),
新LanguageItem(中国(台湾),1028),
新LanguageItem(捷,1029),
新LanguageItem( 丹麦,1030),
新LanguageItem(德国(德国),1031),
新LanguageItem(希腊,1032),
新LanguageItem(英语(美国) ,1033),
新LanguageItem(西班牙语(西班牙 - 传统风格),1034),
新LanguageItem(芬兰,1035)
新LanguageItem(法国(法国),1036),
新LanguageItem(希伯来文1037),
新LanguageItem(匈牙利,1038),
新LanguageItem(冰岛,1039年),
新LanguageItem(意大利(意大利),1040),
新LanguageItem(日本1041),
新LanguageItem(韩国1042),
新LanguageItem( 荷兰语(荷兰)1043),
新LanguageItem(挪威(挪威语)1044),
新LanguageItem(波兰,1045),
新LanguageItem(葡萄牙(巴西)1046),
新LanguageItem(罗曼拉丁语1047),
新LanguageItem(罗马尼亚语(罗马尼亚)1048),
新LanguageItem(俄罗斯(俄罗斯),1049),
新LanguageItem(克罗地亚,1050),
新LanguageItem(斯洛伐克,1051),
新LanguageItem(阿,1052),
新LanguageItem(瑞典(瑞典),1053),
新LanguageItem(泰,1054),
新LanguageItem(土耳其,1055),
新LanguageItem(乌尔都语,1056),
新LanguageItem(印尼语,1057),
新LanguageItem(乌克兰,1058),
新LanguageItem(白俄罗斯,1059) ,
新LanguageItem(斯洛文尼亚,1060),
新LanguageItem(爱沙尼亚语1061)
新LanguageItem(拉脱维亚,1062),,
新LanguageItem( 立陶宛,1063),
新LanguageItem(塔吉克,1064),
新LanguageItem(波斯1065),
新LanguageItem(越南1066),
新LanguageItem(亚美尼亚,1067),
新LanguageItem(里人(拉丁),1068),
新LanguageItem(巴斯克,1069),
新LanguageItem (索布语,1070),
新LanguageItem(马其顿语,1071),
新LanguageItem(苏图,1072),
新LanguageItem(特松加,1073) ,
新LanguageItem(茨瓦纳语,1074),
新LanguageItem(文达,1075),
新LanguageItem(科萨,1076),
新LanguageItem( 祖鲁1077),
新LanguageItem(南非荷兰语1078),
新LanguageItem(格鲁吉亚1079),
新LanguageItem(法罗,1080),
新LanguageItem(印地文1081),
新LanguageItem(马耳他1082),
新LanguageItem(萨米(拉普),1083年),
新LanguageItem (盖尔语(苏格兰),1084年),
新LanguageItem(意第绪语1085),
新LanguageItem(马来1086),
新LanguageItem(哈, 1087),
新LanguageItem(吉,1088),
新LanguageItem(斯瓦希里语,1089),
新LanguageItem(土库曼斯坦,1090),
新LanguageItem(乌兹别克语(拉丁)1091),
新LanguageItem(鞑靼,1092年),
新LanguageItem(孟加拉语1093),
新LanguageItem(旁遮普语 ,1094),
新LanguageItem(古吉拉特语,1095),
新LanguageItem(奥里雅语,1096),
新LanguageItem(泰米尔,1097),
新LanguageItem(泰卢固语1098),
新LanguageItem(卡纳达语,1099),
新LanguageItem(马来亚,1100),
新LanguageItem(阿萨姆1101 ),
新LanguageItem(马拉,1102),
新LanguageItem(梵语,1103),
新LanguageItem(蒙,1104),
新LanguageItem (西藏(PRC),1105),
新LanguageItem(威尔士,1106),
新LanguageItem(高棉,1107),
新LanguageItem(老子 1108),
新LanguageItem(缅甸,1109),
新LanguageItem(加利西亚,1110),
新LanguageItem(孔卡尼语,1111),
新LanguageItem(曼尼普尔,1112),
新LanguageItem(信德(梵文),1113),
新LanguageItem(叙利亚,1114),
新LanguageItem(僧伽罗语 ,1115),
新LanguageItem(切诺基,1116),
新LanguageItem(因纽特语,1117),
新LanguageItem(阿姆哈拉语,1118),
新LanguageItem(柏柏尔语,1119),
新LanguageItem(克什米尔(阿拉伯语),1120),
新LanguageItem(尼泊尔,1121年),
新LanguageItem(弗里斯兰(荷兰)1122),
新LanguageItem(普什图语,1123),
新LanguageItem(菲佣,1124),
新LanguageItem(迪维希文,1125年),
新LanguageItem(江户1126),
新LanguageItem(福福德文号,第1127),
新LanguageItem(豪萨语,1128),
新LanguageItem(伊比比奥语,1129),
新LanguageItem(约鲁巴人,1130),
新LanguageItem(克丘亚语(玻利维亚),1131),
新LanguageItem(塞佩蒂语,1132) ,
新LanguageItem(巴什基尔(俄罗斯),1133年),
新LanguageItem(卢森堡(卢森堡)1134),
新LanguageItem(格陵兰(格陵兰)1135 ),
新LanguageItem(伊博语,1136),
新LanguageItem(卡努里,1137),
新LanguageItem(奥罗莫,1138),
新LanguageItem (提格雷(埃塞俄比亚)1139),
新LanguageItem(瓜拉尼1140),
新LanguageItem(夏威夷号1141),
新LanguageItem(拉丁 1142),
新LanguageItem(索马里,第1143),
新LanguageItem(易传1144),
新LanguageItem(Papiamentu1145),
新LanguageItem(马普切语(智利),1146),
新LanguageItem(莫霍克(Mohawk公司),1148),
新LanguageItem(布列塔尼(法国),1150),
新LanguageItem(维吾尔(PRC),1152),
新LanguageItem(毛利,1153),
新LanguageItem(奥克(法国),1154),
新LanguageItem (科西嘉(法国),1155),
新LanguageItem(阿尔萨斯(法国),1156),
新LanguageItem(雅库特(俄罗斯),1157),
新LanguageItem(K'iche(危地马拉),1158),
新LanguageItem(卢旺达语(卢旺达),1159),
新LanguageItem(沃洛夫语(塞内加尔),1160),
新LanguageItem(达里语(阿富汗),1164),
新LanguageItem(苏格兰盖尔语(英国),1169),
新LanguageItem(阿拉伯语(伊拉克),2049) ,
新LanguageItem(中文(中国),2052),
新LanguageItem(德国(瑞士),2055),
新LanguageItem(英语(英国),2057 ),
新LanguageItem(西班牙(墨西哥),2058),
新LanguageItem(法语(比利时),2060),
新LanguageItem(意大利(瑞士), 2064),
新LanguageItem(荷兰语(比利时),2067),
新LanguageItem(挪威(挪威语),2068),
新LanguageItem(葡萄牙语(葡萄牙) 2070),
新LanguageItem(罗马尼亚语(摩尔多瓦)2072),
新LanguageItem(俄语(摩尔多瓦),2073年),
新LanguageItem(塞尔维亚语(拉丁) ,2074),
新LanguageItem(瑞典语(芬兰),2077),
新LanguageItem(里人(西里尔文),2092),
新LanguageItem(下索布(德国),2094),
新LanguageItem(北萨米语(瑞典),2107),
新LanguageItem(盖尔语(爱尔兰),2108),
新LanguageItem( 马来语(文莱),2110),
新LanguageItem(乌兹别克语(西里尔文),2115),
新LanguageItem(孟加拉语(孟加拉),2117),
新LanguageItem(旁遮普语(巴基斯坦),2118),
新LanguageItem(蒙(蒙),2128),
新LanguageItem(西藏(不丹),2129),
新LanguageItem(信德(阿拉伯语),2137),
新LanguageItem(因纽特语(拉丁语,加拿大),2141),
新LanguageItem(柏柏尔语(拉丁),2143),
新LanguageItem(克什米尔,2144),
新LanguageItem(尼泊尔语(印度),2145),
新LanguageItem(克丘亚语(厄瓜多尔),2155),
新LanguageItem(提格雷(厄立特里亚),2163年),
新LanguageItem(阿拉伯语(埃及),3073),
新LanguageItem(中国(香港特区),3076),
新LanguageItem(德语(奥地利),3079),
新LanguageItem(英语(澳大利亚),3081),
新LanguageItem(西班牙语(西班牙 - 现代排序) ,3082),
新LanguageItem(法语(加拿大),3084),
新LanguageItem(塞尔维亚语(西里尔文),3098),
新LanguageItem(北萨米语(芬兰),3131),
新LanguageItem(克丘亚语(秘鲁),3179),
新LanguageItem(阿拉伯语(利比亚),4097),
新LanguageItem(中国(新加坡),4100),
新LanguageItem(德语(卢森堡),4103),
新LanguageItem(英语(加拿大),4105),
新LanguageItem(西班牙语(危地马拉),4106),
新LanguageItem(法语(瑞士),4108),
新LanguageItem(克罗地亚语(拉丁文,波斯尼亚和黑塞哥维那),4122),
新LanguageItem(萨米,临近Lule(挪威),4155),
新LanguageItem(阿拉伯语(阿尔及利亚),5121),
新LanguageItem(中国(澳门特别行政区),5124) ,
新LanguageItem(德语(列支敦士登),5127),
新LanguageItem(英语(新西兰),5129),
新LanguageItem(西班牙语(哥斯达黎加) ,5130),
新LanguageItem(法语(卢森堡),5132),
新LanguageItem(波斯尼亚(拉丁语,波斯尼亚和黑塞哥维那),5146),
新LanguageItem(萨米,临近Lule(瑞典),5179),
新LanguageItem(阿拉伯语(摩洛哥),6145),
新LanguageItem(英语(爱尔兰),6153),
新LanguageItem(西班牙语(巴拿马),6154),
新LanguageItem(法国(摩纳哥),6156),
新LanguageItem(塞尔维亚语(拉丁语,波斯尼亚和黑塞哥维那),6170),
新LanguageItem(萨米,南(挪威),6203),
新LanguageItem(阿拉伯语(突尼斯),7169),
新LanguageItem(英语(南非) ,7177),
新LanguageItem(西班牙语(多明尼加共和国),7178),
新LanguageItem(法语(西印度群岛),7180),
新LanguageItem(塞尔维亚语(西里尔文,波斯尼亚和黑塞哥维那),7194),
新LanguageItem(萨米,南(瑞典),7227),
新LanguageItem(阿拉伯语(阿曼),8193),
新LanguageItem(英语(牙买加),8201),
新LanguageItem(西班牙语(委内瑞拉),8202),
新LanguageItem(法语(留尼汪),8204),
新LanguageItem(波斯尼亚语(西里尔文,波斯尼亚和黑塞哥维那),8218),
新LanguageItem(萨米,斯科尔特萨米(芬兰),8251),
新LanguageItem(阿拉伯语(也门) ,9217),
新LanguageItem(英语(加勒比海),9225),
新LanguageItem(西班牙语(哥伦比亚),9226),
新LanguageItem(法语(刚果(DRC)),9228),
新LanguageItem(塞尔维亚语(拉丁,塞尔维亚),9242),
新LanguageItem(萨米,稻荷(芬兰),9275),
新LanguageItem(阿拉伯语(叙利亚),10241),
新LanguageItem(英语(伯利兹),10249),
新LanguageItem(西班牙语(秘鲁),10250),
新LanguageItem(法语(塞内加尔),10252),
新LanguageItem(塞尔维亚语(西里尔文,塞尔维亚),10266),
新LanguageItem(阿拉伯语(约旦),11265) ,
新LanguageItem(英语(特立尼达和多巴哥),11273),
新LanguageItem(西班牙语(阿根廷),11274),
新LanguageItem(法语(喀麦隆) ,11276),
新LanguageItem(塞尔维亚语(拉丁语,黑山),11290),
新LanguageItem(阿拉伯语(黎巴嫩),12289),
新LanguageItem(英语(津巴布韦),12297),
新LanguageItem(西班牙语(厄瓜多尔),12298),
新LanguageItem(法语(科特迪瓦),12300),
新LanguageItem (塞尔维亚语(西里尔文,黑山),12314),
新LanguageItem(阿拉伯语(科威特),13313),
新LanguageItem(英语(菲律宾),13321),
新LanguageItem(西班牙语(智利),13322),
新LanguageItem(法语(马里),13324),
新LanguageItem(阿拉伯语(阿联酋),14337),
新LanguageItem(英语(印度尼西亚),14345),
新LanguageItem(西班牙语(乌拉圭),14346),
新LanguageItem(法语(摩洛哥),14348),
新LanguageItem(阿拉伯语(巴林),15361),
新LanguageItem(英语(香港特别行政区),15369),
新LanguageItem(西班牙语(巴拉圭),15370 ),
新LanguageItem(法语(海地),15372),
新LanguageItem(阿拉伯语(卡塔尔),16385),
新LanguageItem(英语(印度), 16393),
新LanguageItem(西班牙语(玻利维亚),16394),
新LanguageItem(英语(马来西亚),17417),
新LanguageItem(西班牙语(萨尔瓦多) ,17418),
新LanguageItem(英语(新加坡),18441),
新LanguageItem(西班牙语(洪都拉斯),18442),
新LanguageItem(西班牙语(尼加拉瓜),19466),
新LanguageItem(西班牙语(波多黎各),20490),
新LanguageItem(西班牙语(美国),21514),
});
公共静态LanguageItem GetLanguageItem(字符串languageName)
{
返回_languageList.SingleOrDefault(LI = GT; li.Name.Equals(languageName));
}
}
我试图找到语言环境的综合列表在Windows培养使用。关键的一点是, ZH-TW 必须中国(繁体)并没有别的东西。我没能找到,尽管已经广泛的搜索这样的列表
编辑:
-
要澄清,我的问题是,如何检索我的代码的确切名单?我相信这是应该是介于Windows的文化,如
CultureInfo.DisplayName
或相似。任何想法? -
什么是最有效的方法,然后过度投他们的
Word.LanguageID
更新:
见回答下面贴我解决这些的问题。还是希望任何其他建议。
可以从返回的所有语言的完整列表的CultureInfo
:
的CultureInfo [] =文化CultureInfo.GetCultures(CultureTypes>。 AllCultures)
的foreach(CultureInfo的文化,文化)
{
的Debug.WriteLine(culture.EnglishName);
}
由于在这个岗位:的
和作为的。
和经过广泛搜索和测试,我发现语言的集合,所使用的SDL
$ b $:Trados Studio中是的CultureInfo
这是通过API的访问b
字符串strTgtLocaleId = EditorController.ActiveDocument.ActiveFile.Language.ToString();
串strTgtLanguage = EditorController.ActiveDocument.ActiveFile.Language.DisplayName.ToString();
INT strTgtLanguageId = EditorController.ActiveDocument.ActiveFile.Language.CultureInfo.LCID;
这样的完整列表实际上,我需要为我的插件(承认@ Jenszcz的从传统的串观察早期的产品)实际上可以从所列举的的CultureInfo
。
我的目标是不过直接翻译这些代码该ID的Word版。所以,我跑了代码,以两个列表进行比较。我使用的是张贴在OP的 Word.Language
枚举:
使用系统;
使用System.Collections.Generic;使用System.Diagnostics程序
;
使用System.Linq的;
使用System.Text;使用System.Threading.Tasks
;使用Word =的Microsoft.Office.Interop.Word
;
命名ConsoleApplication1
{
类节目
{
静态无效的主要(字串[] args)
{
对象oMissing = System.Reflection.Missing.Value;
对象oEndOfDoc =\\endofdoc; / * \endofdoc是虚实
对象oTrue = TRUE预定义的书签* /
//物体;
对象oFalse = FALSE;
// CREATING WORD和文件
Word.Application oWord =新Word.Application对象();
VAR测试= oWord.Application.Languages;
的foreach(在System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures VAR项目))
{
如果(LanguageList._languageList.SingleOrDefault(I => ; i.Id.Equals(item.LCID))= NULL)
{
的Debug.WriteLine!(LanguageList._languageList.SingleOrDefault(I => i.Id.Equals(item.LCID)) 。名称+
- +
item.EnglishName +
- +
((int)的item.LCID)的ToString()
) ;
}
,否则如果(LanguageList._languageList.SingleOrDefault(I => i.Id.Equals(item.Parent.LCID))!= NULL)
{
调试。缩进();
的Debug.WriteLine(--------家长MATCH:+ item.EnglishName + - +((int)的item.Parent.LCID)的ToString());
Debug.Unindent();
}
,否则
{
Debug.Indent();
的Debug.WriteLine(!!!!!!!!不匹配:+ item.EnglishName + - +((int)的item.LCID)的ToString());
Debug.Unindent();
}
}
}
}
和结果对我来说很幸运。事实上, Word.WdLanguageID
匹配所有的 CultureInfo.LCID
值一对一,除了传统和奇风异俗(这是不需要我的插件)。
所以我结束了,甚至不需要通过 item.EnglishName 返回语言字符串列表code>如中国(繁体)
所以我跳过枚举全棉布。代码相比,它最初走上遍历所有语言中的 Word.Languages
分钟以毫秒为单位现在运行。我用下面的代码来设置Word文档的语言:
试
{
oWord。 Selection.LanguageID =(Word.WdLanguageID)strTgtLanguageId;
}
赶上(例外)
{
oWord.Selection.LanguageID =(Word.WdLanguageID)0;
}
这会将所有匹配的语言,铸造 LCID
到正确的 Word.WdLanguageID
不变。对于那些不匹配,它设置为未设置。
I've been searching for the answer over the net, but I don't seem to be able to find a comprehensive list of all languages available for my app with their exact display name. (I find many lists, but none of them seem to match the language strings I have. Read on.) The closest one I found is this one, but is not complete.
I am coding a plugin in C# where the text is exported from SDL Trados Studio to Word and the language is set accordingly in Word.
I need to write a custom method that casts these language names to their relevant Word.Language
equivalent. This is because Trados (using the Windows cultures and .NET framework 4.5) has different language (locale) names than the Word.Language
names.
While Hungarian is the same, TraditionalChinese (Word.Language
) is Chinese (Traditional, Taiwan) in Trados.
I do have a comprehensive list for Word.Languages
already:
public static class LanguageList
{
public static readonly HashSet<LanguageItem> _languageList = new HashSet<LanguageItem>(new[]
{
new LanguageItem("Arabic (Saudi Arabia)", 1025),
new LanguageItem("Bulgarian", 1026),
new LanguageItem("Catalan", 1027),
new LanguageItem("Chinese (Taiwan)", 1028),
new LanguageItem("Czech", 1029),
new LanguageItem("Danish", 1030),
new LanguageItem("German (Germany)", 1031),
new LanguageItem("Greek", 1032),
new LanguageItem("English (U.S.)", 1033),
new LanguageItem("Spanish (Spain-Traditional Sort)", 1034),
new LanguageItem("Finnish", 1035),
new LanguageItem("French (France)", 1036),
new LanguageItem("Hebrew", 1037),
new LanguageItem("Hungarian", 1038),
new LanguageItem("Icelandic", 1039),
new LanguageItem("Italian (Italy)", 1040),
new LanguageItem("Japanese", 1041),
new LanguageItem("Korean", 1042),
new LanguageItem("Dutch (Netherlands)", 1043),
new LanguageItem("Norwegian (Bokmål)", 1044),
new LanguageItem("Polish", 1045),
new LanguageItem("Portuguese (Brazil)", 1046),
new LanguageItem("Rhaeto-Romanic", 1047),
new LanguageItem("Romanian (Romania)", 1048),
new LanguageItem("Russian (Russia)", 1049),
new LanguageItem("Croatian", 1050),
new LanguageItem("Slovak", 1051),
new LanguageItem("Albanian", 1052),
new LanguageItem("Swedish (Sweden)", 1053),
new LanguageItem("Thai", 1054),
new LanguageItem("Turkish", 1055),
new LanguageItem("Urdu", 1056),
new LanguageItem("Indonesian", 1057),
new LanguageItem("Ukrainian", 1058),
new LanguageItem("Belarusian", 1059),
new LanguageItem("Slovenian", 1060),
new LanguageItem("Estonian", 1061),
new LanguageItem("Latvian", 1062),
new LanguageItem("Lithuanian", 1063),
new LanguageItem("Tajik", 1064),
new LanguageItem("Farsi", 1065),
new LanguageItem("Vietnamese", 1066),
new LanguageItem("Armenian", 1067),
new LanguageItem("Azeri (Latin)", 1068),
new LanguageItem("Basque", 1069),
new LanguageItem("Sorbian", 1070),
new LanguageItem("FYRO Macedonian", 1071),
new LanguageItem("Sutu", 1072),
new LanguageItem("Tsonga", 1073),
new LanguageItem("Tswana", 1074),
new LanguageItem("Venda", 1075),
new LanguageItem("Xhosa", 1076),
new LanguageItem("Zulu", 1077),
new LanguageItem("Afrikaans", 1078),
new LanguageItem("Georgian", 1079),
new LanguageItem("Faeroese", 1080),
new LanguageItem("Hindi", 1081),
new LanguageItem("Maltese", 1082),
new LanguageItem("Sami (Lappish)", 1083),
new LanguageItem("Gaelic (Scotland)", 1084),
new LanguageItem("Yiddish", 1085),
new LanguageItem("Malay", 1086),
new LanguageItem("Kazakh", 1087),
new LanguageItem("Kyrgyz", 1088),
new LanguageItem("Swahili", 1089),
new LanguageItem("Turkmen", 1090),
new LanguageItem("Uzbek (Latin)", 1091),
new LanguageItem("Tatar", 1092),
new LanguageItem("Bengali", 1093),
new LanguageItem("Punjabi", 1094),
new LanguageItem("Gujarati", 1095),
new LanguageItem("Oriya", 1096),
new LanguageItem("Tamil", 1097),
new LanguageItem("Telugu", 1098),
new LanguageItem("Kannada", 1099),
new LanguageItem("Malayalam", 1100),
new LanguageItem("Assamese", 1101),
new LanguageItem("Marathi", 1102),
new LanguageItem("Sanskrit", 1103),
new LanguageItem("Mongolian", 1104),
new LanguageItem("Tibetan (PRC)", 1105),
new LanguageItem("Welsh", 1106),
new LanguageItem("Khmer", 1107),
new LanguageItem("Lao", 1108),
new LanguageItem("Burmese", 1109),
new LanguageItem("Galician", 1110),
new LanguageItem("Konkani", 1111),
new LanguageItem("Manipuri", 1112),
new LanguageItem("Sindhi (Devanagari)", 1113),
new LanguageItem("Syriac", 1114),
new LanguageItem("Sinhalese", 1115),
new LanguageItem("Cherokee", 1116),
new LanguageItem("Inuktitut", 1117),
new LanguageItem("Amharic", 1118),
new LanguageItem("Tamazight", 1119),
new LanguageItem("Kashmiri (Arabic)", 1120),
new LanguageItem("Nepali", 1121),
new LanguageItem("Frisian (Netherlands)", 1122),
new LanguageItem("Pashto", 1123),
new LanguageItem("Filipino", 1124),
new LanguageItem("Divehi", 1125),
new LanguageItem("Edo", 1126),
new LanguageItem("Fulfulde", 1127),
new LanguageItem("Hausa", 1128),
new LanguageItem("Ibibio", 1129),
new LanguageItem("Yoruba", 1130),
new LanguageItem("Quechua (Bolivia)", 1131),
new LanguageItem("Sepedi", 1132),
new LanguageItem("Bashkir (Russia)", 1133),
new LanguageItem("Luxembourgish (Luxembourg)", 1134),
new LanguageItem("Greenlandic (Greenland)", 1135),
new LanguageItem("Igbo", 1136),
new LanguageItem("Kanuri", 1137),
new LanguageItem("Oromo", 1138),
new LanguageItem("Tigrigna (Ethiopia)", 1139),
new LanguageItem("Guarani", 1140),
new LanguageItem("Hawaiian", 1141),
new LanguageItem("Latin", 1142),
new LanguageItem("Somali", 1143),
new LanguageItem("Yi", 1144),
new LanguageItem("Papiamentu", 1145),
new LanguageItem("Mapudungun (Chile)", 1146),
new LanguageItem("Mohawk (Mohawk)", 1148),
new LanguageItem("Breton (France)", 1150),
new LanguageItem("Uyghur (PRC)", 1152),
new LanguageItem("Maori", 1153),
new LanguageItem("Occitan (France)", 1154),
new LanguageItem("Corsican (France)", 1155),
new LanguageItem("Alsatian (France)", 1156),
new LanguageItem("Yakut (Russia)", 1157),
new LanguageItem("K'iche (Guatemala)", 1158),
new LanguageItem("Kinyarwanda (Rwanda)", 1159),
new LanguageItem("Wolof (Senegal)", 1160),
new LanguageItem("Dari (Afghanistan)", 1164),
new LanguageItem("Scottish Gaelic (United Kingdom)", 1169),
new LanguageItem("Arabic (Iraq)", 2049),
new LanguageItem("Chinese (PRC)", 2052),
new LanguageItem("German (Switzerland)", 2055),
new LanguageItem("English (U.K.)", 2057),
new LanguageItem("Spanish (Mexico)", 2058),
new LanguageItem("French (Belgium)", 2060),
new LanguageItem("Italian (Switzerland)", 2064),
new LanguageItem("Dutch (Belgium)", 2067),
new LanguageItem("Norwegian (Nynorsk)", 2068),
new LanguageItem("Portuguese (Portugal)", 2070),
new LanguageItem("Romanian (Moldova)", 2072),
new LanguageItem("Russian (Moldova)", 2073),
new LanguageItem("Serbian (Latin)", 2074),
new LanguageItem("Swedish (Finland)", 2077),
new LanguageItem("Azeri (Cyrillic)", 2092),
new LanguageItem("Lower Sorbian (Germany)", 2094),
new LanguageItem("Sami, Northern (Sweden)", 2107),
new LanguageItem("Gaelic (Ireland)", 2108),
new LanguageItem("Malay (Brunei Darussalam)", 2110),
new LanguageItem("Uzbek (Cyrillic)", 2115),
new LanguageItem("Bengali (Bangladesh)", 2117),
new LanguageItem("Punjabi (Pakistan)", 2118),
new LanguageItem("Mongolian (Mongolian)", 2128),
new LanguageItem("Tibetan (Bhutan)", 2129),
new LanguageItem("Sindhi (Arabic)", 2137),
new LanguageItem("Inuktitut (Latin, Canada)", 2141),
new LanguageItem("Tamazight (Latin)", 2143),
new LanguageItem("Kashmiri", 2144),
new LanguageItem("Nepali (India)", 2145),
new LanguageItem("Quechua (Ecuador)", 2155),
new LanguageItem("Tigrigna (Eritrea)", 2163),
new LanguageItem("Arabic (Egypt)", 3073),
new LanguageItem("Chinese (Hong Kong S.A.R.)", 3076),
new LanguageItem("German (Austria)", 3079),
new LanguageItem("English (Australia)", 3081),
new LanguageItem("Spanish (Spain-Modern Sort)", 3082),
new LanguageItem("French (Canada)", 3084),
new LanguageItem("Serbian (Cyrillic)", 3098),
new LanguageItem("Sami, Northern (Finland)", 3131),
new LanguageItem("Quechua (Peru)", 3179),
new LanguageItem("Arabic (Libya)", 4097),
new LanguageItem("Chinese (Singapore)", 4100),
new LanguageItem("German (Luxembourg)", 4103),
new LanguageItem("English (Canada)", 4105),
new LanguageItem("Spanish (Guatemala)", 4106),
new LanguageItem("French (Switzerland)", 4108),
new LanguageItem("Croatian (Latin, Bosnia and Herzegovina)", 4122),
new LanguageItem("Sami, Lule (Norway)", 4155),
new LanguageItem("Arabic (Algeria)", 5121),
new LanguageItem("Chinese (Macao S.A.R.)", 5124),
new LanguageItem("German (Liechtenstein)", 5127),
new LanguageItem("English (New Zealand)", 5129),
new LanguageItem("Spanish (Costa Rica)", 5130),
new LanguageItem("French (Luxembourg)", 5132),
new LanguageItem("Bosnian (Latin, Bosnia and Herzegovina)", 5146),
new LanguageItem("Sami, Lule (Sweden)", 5179),
new LanguageItem("Arabic (Morocco)", 6145),
new LanguageItem("English (Ireland)", 6153),
new LanguageItem("Spanish (Panama)", 6154),
new LanguageItem("French (Monaco)", 6156),
new LanguageItem("Serbian (Latin, Bosnia and Herzegovina)", 6170),
new LanguageItem("Sami, Southern (Norway)", 6203),
new LanguageItem("Arabic (Tunisia)", 7169),
new LanguageItem("English (South Africa)", 7177),
new LanguageItem("Spanish (Dominican Republic)", 7178),
new LanguageItem("French (West Indies)", 7180),
new LanguageItem("Serbian (Cyrillic, Bosnia and Herzegovina)", 7194),
new LanguageItem("Sami, Southern (Sweden)", 7227),
new LanguageItem("Arabic (Oman)", 8193),
new LanguageItem("English (Jamaica)", 8201),
new LanguageItem("Spanish (Venezuela)", 8202),
new LanguageItem("French (Reunion)", 8204),
new LanguageItem("Bosnian (Cyrillic, Bosnia and Herzegovina)", 8218),
new LanguageItem("Sami, Skolt (Finland)", 8251),
new LanguageItem("Arabic (Yemen)", 9217),
new LanguageItem("English (Caribbean)", 9225),
new LanguageItem("Spanish (Colombia)", 9226),
new LanguageItem("French (Congo (DRC))", 9228),
new LanguageItem("Serbian (Latin, Serbia)", 9242),
new LanguageItem("Sami, Inari (Finland)", 9275),
new LanguageItem("Arabic (Syria)", 10241),
new LanguageItem("English (Belize)", 10249),
new LanguageItem("Spanish (Peru)", 10250),
new LanguageItem("French (Senegal)", 10252),
new LanguageItem("Serbian (Cyrillic, Serbia)", 10266),
new LanguageItem("Arabic (Jordan)", 11265),
new LanguageItem("English (Trinidad and Tobago)", 11273),
new LanguageItem("Spanish (Argentina)", 11274),
new LanguageItem("French (Cameroon)", 11276),
new LanguageItem("Serbian (Latin, Montenegro)", 11290),
new LanguageItem("Arabic (Lebanon)", 12289),
new LanguageItem("English (Zimbabwe)", 12297),
new LanguageItem("Spanish (Ecuador)", 12298),
new LanguageItem("French (Cote d'Ivoire)", 12300),
new LanguageItem("Serbian (Cyrillic, Montenegro)", 12314),
new LanguageItem("Arabic (Kuwait)", 13313),
new LanguageItem("English (Philippines)", 13321),
new LanguageItem("Spanish (Chile)", 13322),
new LanguageItem("French (Mali)", 13324),
new LanguageItem("Arabic (U.A.E)", 14337),
new LanguageItem("English (Indonesia)", 14345),
new LanguageItem("Spanish (Uruguay)", 14346),
new LanguageItem("French (Morocco)", 14348),
new LanguageItem("Arabic (Bahrain)", 15361),
new LanguageItem("English (Hong Kong S.A.R.)", 15369),
new LanguageItem("Spanish (Paraguay)", 15370),
new LanguageItem("French (Haiti)", 15372),
new LanguageItem("Arabic (Qatar)", 16385),
new LanguageItem("English (India)", 16393),
new LanguageItem("Spanish (Bolivia)", 16394),
new LanguageItem("English (Malaysia)", 17417),
new LanguageItem("Spanish (El Salvador)", 17418),
new LanguageItem("English (Singapore)", 18441),
new LanguageItem("Spanish (Honduras)", 18442),
new LanguageItem("Spanish (Nicaragua)", 19466),
new LanguageItem("Spanish (Puerto Rico)", 20490),
new LanguageItem("Spanish (United States)", 21514),
});
public static LanguageItem GetLanguageItem(string languageName)
{
return _languageList.SingleOrDefault(li => li.Name.Equals(languageName));
}
}
I am trying to find a comprehensive list of the locales used in the Windows cultures. The key point is that zh-TW needs to be Chinese (Traditional, Taiwan) and not something else. I did not manage to find such a list despite extensive searching already.
Edit:
To clarify, my question is, how to retrieve the the exact list in my code? I believe it is should be somewhere in the Windows cultures, such as
CultureInfo.DisplayName
or similar. Any idea?What is the most effective method then to cast them over to the
Word.LanguageID
?
Update:See answer posted below for my solution to these questions. Still would appreciate any other suggestions.
The complete list of all languages can be returned from CultureInfo
:
using System.Globalization
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures)
foreach (CultureInfo culture in cultures)
{
Debug.WriteLine(culture.EnglishName);
}
As in this post: Programmatic way to get all the available languages (in satellite assemblies)
And as covered on msdn.
And after extensive searching and testing, I found that the language collection that is used by the SDL Trados Studio is the CultureInfo
.
It is accessed by through the API as:
string strTgtLocaleId = EditorController.ActiveDocument.ActiveFile.Language.ToString();
string strTgtLanguage = EditorController.ActiveDocument.ActiveFile.Language.DisplayName.ToString();
int strTgtLanguageId = EditorController.ActiveDocument.ActiveFile.Language.CultureInfo.LCID;
Thus the full list actually that I need for my plugin (acknowledging @Jenszcz's observation on the legacy strings from earlier products) is in fact can be enumerated from the CultureInfo
.
My goal was however to directly translate these codes to the Word version of the IDs. So I ran a code to compare the two lists. I used the Word.Language
enumeration that I posted in the OP:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Word = Microsoft.Office.Interop.Word;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Object oMissing = System.Reflection.Missing.Value;
Object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
//OBJECTS OF FALSE AND TRUE
Object oTrue = true;
Object oFalse = false;
//CREATING OBJECTS OF WORD AND DOCUMENT
Word.Application oWord = new Word.Application();
var test = oWord.Application.Languages;
foreach (var item in System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures))
{
if (LanguageList._languageList.SingleOrDefault(i => i.Id.Equals(item.LCID)) != null)
{
Debug.WriteLine(LanguageList._languageList.SingleOrDefault(i => i.Id.Equals(item.LCID)).Name +
" -- " +
item.EnglishName +
" -- " +
((int)item.LCID).ToString()
);
}
else if (LanguageList._languageList.SingleOrDefault(i => i.Id.Equals(item.Parent.LCID)) != null)
{
Debug.Indent();
Debug.WriteLine("-------- PARENT MATCH: " + item.EnglishName + " -- " + ((int)item.Parent.LCID).ToString());
Debug.Unindent();
}
else
{
Debug.Indent();
Debug.WriteLine("!!!!!!!! NO MATCH: " + item.EnglishName + " -- " + ((int)item.LCID).ToString());
Debug.Unindent();
}
}
}
}
And the result was very lucky for me. In fact the Word.WdLanguageID
matched all the CultureInfo.LCID
values one for one, except for the legacy and exotic locales (which is not needed for my plugin).
Therefore I ended up not even needing the list of language strings returned by item.EnglishName
such as Chinese (Traditional, Taiwan).
So I skipped the enumeration whole cloth. The code now runs in milliseconds as compared to the minutes it originally took to loop through all languages in the Word.Languages
. I used the following code to set the language in the Word Document:
try
{
oWord.Selection.LanguageID = (Word.WdLanguageID)strTgtLanguageId;
}
catch (Exception)
{
oWord.Selection.LanguageID = (Word.WdLanguageID)0;
}
This sets all matching languages, casting the LCID
to the correct Word.WdLanguageID
constant. For those that are not matched, it sets it to "Not set".
这篇关于对于Windows .NET框架的所有可用语言列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!