List of all available languages for Windows .NET framework

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 through the API as:

string strTgtLocaleId = EditorController.ActiveDocument.ActiveFile.Language.ToString();
string strTgtLanguage = EditorController.ActiveDocument.ActiveFile.Language.DisplayName.ToString();
int intTgtLanguageId = 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)intTgtLanguageId;
}
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".


I think you are looking for Microsoft's Locale ID (LCID) list: https://msdn.microsoft.com/en-us/goglobal/bb964664.aspx