我一直在网上搜索答案,但我似乎无法找到我的应用程序所有可用语言的完整列表及其确切的显示名称。 (我发现很多列表,但它们似乎都没有我所拥有的语言字符串。请继续阅读。)我找到的最接近的是this one,但不完整。
我正在使用C#编写插件,其中文本从SDL Trados Studio导出到Word,并在Word中相应地设置语言。
我需要编写一个自定义方法,将这些语言名称强制转换为相关的Word.Language
等效语法。这是因为Trados(使用Windows culture和.NET framework 4.5)具有与Word.Language
名称不同的语言(语言环境)名称。
虽然匈牙利相同,但 TraditionalChinese (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 需要中文(繁体,台湾)而不是其他。尽管已经进行了广泛的搜索,但我还是找不到这样的清单。
修改
为了澄清,我的问题是,如何检索我的代码中的确切列表?我相信它应该在Windows文化中的某个地方,例如CultureInfo.DisplayName
或类似的。有什么想法吗?
将它们转换为Word.LanguageID
的最有效方法是什么?
更新 请参阅下面的答案,了解我对这些问题的解决方案仍然会欣赏任何其他建议。
答案 0 :(得分:6)
可以从CultureInfo
返回所有语言的完整列表:
using System.Globalization;
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (CultureInfo culture in cultures)
{
Debug.WriteLine(culture.EnglishName);
}
如同帖子:Programmatic way to get all the available languages (in satellite assemblies)
和covered on msdn一样。
经过广泛的搜索和测试,我发现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中发布的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
返回的语言字符串列表,例如中文(繁体,台湾)。
所以我跳过整个布料的枚举。现在,代码运行时间为毫秒,与最初用于遍历Word.Languages
中所有语言的分钟数相比。我使用以下代码在Word文档中设置语言:
try
{
oWord.Selection.LanguageID = (Word.WdLanguageID)intTgtLanguageId;
}
catch (Exception)
{
oWord.Selection.LanguageID = (Word.WdLanguageID)0;
}
这会设置所有匹配的语言,将LCID
转换为正确的Word.WdLanguageID
常量。对于那些不匹配的,它将其设置为&#34;未设置&#34;。
答案 1 :(得分:2)
我认为您正在寻找Microsoft的区域设置ID(LCID)列表:https://msdn.microsoft.com/en-us/goglobal/bb964664.aspx
答案 2 :(得分:0)
这些字符串可能来自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
中。也许这可以作为访问这些列表的起点。或许不是,但值得一试。