Windows .NET 框架的所有可用语言列表
List of all available languages for Windows .NET framework
我一直在网上寻找答案,但我似乎无法找到可用于我的应用程序的所有语言及其确切显示名称的完整列表。 (我找到了很多列表,但其中 none 似乎与我拥有的语言字符串匹配。请继续阅读。)我找到的最接近的列表是 this one,,但并不完整。
我正在用 C# 编写一个插件,将文本从 SDL Trados Studio 导出到 Word,并在 Word 中相应地设置语言。
我需要编写一个自定义方法,将这些语言名称转换为相关的 Word.Language
等价物。这是因为 Trados(使用 Windows 文化和 .NET Framework 4.5)的语言(区域设置)名称与 Word.Language
名称不同。
虽然匈牙利语是一样的,但繁体中文(Word.Language
)是中文(繁体,台湾) 在 Trados 中。
我已经有了 Word.Languages
的综合清单:
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));
}
}
我正在尝试查找 Windows 文化中使用的语言环境的完整列表。关键是 zh-TW 需要 Chinese (Traditional, Taiwan) 而不是其他东西。尽管已经进行了广泛的搜索,但我没有设法找到这样的列表。
编辑:
澄清一下,我的问题是,如何在我的代码中检索确切的列表?我相信它应该在 Windows 文化中的某个地方,例如 CultureInfo.DisplayName
或类似的。有什么想法吗?
什么是最有效的方法将它们转换到Word.LanguageID
?
更新:
请参阅下面发布的答案以了解我对这些问题的解决方案。仍然会感谢任何其他建议。
我认为您正在查找 Microsoft 的区域设置 ID (LCID) 列表:https://msdn.microsoft.com/en-us/goglobal/bb964664.aspx
这些字符串可能取自 SDL Studio 嵌入式资源,来自 Sdl.LanguagePlatform.Lingua.dll。我快速尝试找到您的台湾示例,但没有成功。不过,为了向您展示如何不这样做,这是我的代码:
static void Main(string[] args)
{
// forced enum iteration
for (int n = 0; n < 6; ++n)
{
var localInfoSet = Sdl.LanguagePlatform.Lingua.Locales.LocaleInfoSet.GetLocaleInfoSet((Sdl.LanguagePlatform.Lingua.Locales.LocaleSource)n);
var tradLocaleInfo = localInfoSet.Where(item => item.Name.Contains("Traditional,"));
foreach (var item in tradLocaleInfo)
{
System.Diagnostics.Debug.WriteLine(item.Name);
}
}
}
我故意留下了完整的命名空间,而不是 using
。也许这可以作为您访问这些列表的起点。或许不是,但值得一试。
可以从 CultureInfo
返回所有语言的完整列表:
using System.Globalization;
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (CultureInfo culture in cultures)
{
Debug.WriteLine(culture.EnglishName);
}
如此 post:Programmatic way to get all the available languages (in satellite assemblies)
经过广泛的搜索和测试,我发现 SDL Trados Studio 使用的语言集合是 CultureInfo
。
它通过 API 访问为:
string strTgtLocaleId = EditorController.ActiveDocument.ActiveFile.Language.ToString();
string strTgtLanguage = EditorController.ActiveDocument.ActiveFile.Language.DisplayName.ToString();
int intTgtLanguageId = EditorController.ActiveDocument.ActiveFile.Language.CultureInfo.LCID;
因此我的插件实际上需要的完整列表(承认@Jenszcz 对早期产品遗留字符串的观察)实际上可以从 CultureInfo
.
中枚举出来
然而,我的目标是直接将这些代码转换为 ID 的 Word 版本。运行所以我 运行 一个代码来比较两个列表。我使用了我在 OP 中 post 编辑的 Word.Language
枚举:
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();
}
}
}
}
结果对我来说非常幸运。事实上 Word.WdLanguageID
与所有 CultureInfo.LCID
值一对一匹配,除了遗留和异国情调的语言环境(我的插件不需要)。
因此我最终甚至不需要 item.EnglishName
返回的语言字符串列表,例如 Chinese (Traditional, Taiwan).
所以我跳过了整个布料的枚举。与最初循环遍历 Word.Languages
中的所有语言所花费的分钟相比,代码现在的运行时间为毫秒。我使用以下代码设置Word文档中的语言:
try
{
oWord.Selection.LanguageID = (Word.WdLanguageID)intTgtLanguageId;
}
catch (Exception)
{
oWord.Selection.LanguageID = (Word.WdLanguageID)0;
}
这会设置所有匹配的语言,将 LCID
转换为正确的 Word.WdLanguageID
常量。对于那些不匹配的,它将其设置为 "Not set".
我一直在网上寻找答案,但我似乎无法找到可用于我的应用程序的所有语言及其确切显示名称的完整列表。 (我找到了很多列表,但其中 none 似乎与我拥有的语言字符串匹配。请继续阅读。)我找到的最接近的列表是 this one,,但并不完整。
我正在用 C# 编写一个插件,将文本从 SDL Trados Studio 导出到 Word,并在 Word 中相应地设置语言。
我需要编写一个自定义方法,将这些语言名称转换为相关的 Word.Language
等价物。这是因为 Trados(使用 Windows 文化和 .NET Framework 4.5)的语言(区域设置)名称与 Word.Language
名称不同。
虽然匈牙利语是一样的,但繁体中文(Word.Language
)是中文(繁体,台湾) 在 Trados 中。
我已经有了 Word.Languages
的综合清单:
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));
}
}
我正在尝试查找 Windows 文化中使用的语言环境的完整列表。关键是 zh-TW 需要 Chinese (Traditional, Taiwan) 而不是其他东西。尽管已经进行了广泛的搜索,但我没有设法找到这样的列表。
编辑:
澄清一下,我的问题是,如何在我的代码中检索确切的列表?我相信它应该在 Windows 文化中的某个地方,例如
CultureInfo.DisplayName
或类似的。有什么想法吗?什么是最有效的方法将它们转换到
Word.LanguageID
?
更新: 请参阅下面发布的答案以了解我对这些问题的解决方案。仍然会感谢任何其他建议。
我认为您正在查找 Microsoft 的区域设置 ID (LCID) 列表:https://msdn.microsoft.com/en-us/goglobal/bb964664.aspx
这些字符串可能取自 SDL Studio 嵌入式资源,来自 Sdl.LanguagePlatform.Lingua.dll。我快速尝试找到您的台湾示例,但没有成功。不过,为了向您展示如何不这样做,这是我的代码:
static void Main(string[] args)
{
// forced enum iteration
for (int n = 0; n < 6; ++n)
{
var localInfoSet = Sdl.LanguagePlatform.Lingua.Locales.LocaleInfoSet.GetLocaleInfoSet((Sdl.LanguagePlatform.Lingua.Locales.LocaleSource)n);
var tradLocaleInfo = localInfoSet.Where(item => item.Name.Contains("Traditional,"));
foreach (var item in tradLocaleInfo)
{
System.Diagnostics.Debug.WriteLine(item.Name);
}
}
}
我故意留下了完整的命名空间,而不是 using
。也许这可以作为您访问这些列表的起点。或许不是,但值得一试。
可以从 CultureInfo
返回所有语言的完整列表:
using System.Globalization;
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (CultureInfo culture in cultures)
{
Debug.WriteLine(culture.EnglishName);
}
如此 post:Programmatic way to get all the available languages (in satellite assemblies)
经过广泛的搜索和测试,我发现 SDL Trados Studio 使用的语言集合是 CultureInfo
。
它通过 API 访问为:
string strTgtLocaleId = EditorController.ActiveDocument.ActiveFile.Language.ToString();
string strTgtLanguage = EditorController.ActiveDocument.ActiveFile.Language.DisplayName.ToString();
int intTgtLanguageId = EditorController.ActiveDocument.ActiveFile.Language.CultureInfo.LCID;
因此我的插件实际上需要的完整列表(承认@Jenszcz 对早期产品遗留字符串的观察)实际上可以从 CultureInfo
.
然而,我的目标是直接将这些代码转换为 ID 的 Word 版本。运行所以我 运行 一个代码来比较两个列表。我使用了我在 OP 中 post 编辑的 Word.Language
枚举:
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();
}
}
}
}
结果对我来说非常幸运。事实上 Word.WdLanguageID
与所有 CultureInfo.LCID
值一对一匹配,除了遗留和异国情调的语言环境(我的插件不需要)。
因此我最终甚至不需要 item.EnglishName
返回的语言字符串列表,例如 Chinese (Traditional, Taiwan).
所以我跳过了整个布料的枚举。与最初循环遍历 Word.Languages
中的所有语言所花费的分钟相比,代码现在的运行时间为毫秒。我使用以下代码设置Word文档中的语言:
try
{
oWord.Selection.LanguageID = (Word.WdLanguageID)intTgtLanguageId;
}
catch (Exception)
{
oWord.Selection.LanguageID = (Word.WdLanguageID)0;
}
这会设置所有匹配的语言,将 LCID
转换为正确的 Word.WdLanguageID
常量。对于那些不匹配的,它将其设置为 "Not set".