How to translate CultureInfo language names

北战南征 提交于 2019-11-26 09:12:54

问题


I know of three ways to get a full language name of a CultureInfo object.

CultureInfo.DisplayName   
CultureInfo.NativeName  
CultureInfo.EnglishName

DisplayName gives the name in the installed .net language.
NativeName gives the name in \'CultureInfos\' language.
EnglishName gives the name in English (surprisingly...)

So for CultureInfo de-DE this gives (on an English .net installation)
German
Deutsch
German

Now my question: Is there a way to ask for the language name of de-DE in another language? E.g. I want the language name of de-DE in Dutch (which would be \'Duits\').


回答1:


This functionality isn't built into the .NET Framework

Maybe look at Google Translate API




回答2:


Example for CultureInfo.EnglishName:

    public CultureInfo GetCultureInfo(string EnglishName)
    {
        foreach (CultureInfo info in CultureInfo.GetCultures(CultureTypes.AllCultures))
        {
            if (info.EnglishName == EnglishName)
                return new CultureInfo(info.Name);
        }

        return null;
    }



回答3:


In principle the following code works:

private static ResourceManager resourceManager = new ResourceManager("mscorlib", typeof(int).Assembly);

public static string CultureName(CultureInfo culture, CultureInfo displayCulture)
{
    return resourceManager.GetString("Globalization.ci_" + culture.Name, displayCulture);
}

However there are important limitations:

  • It relies on undocumented behaviour, so it can break with updates of Windows or .NET
  • The display language needs to be installed on the Computer you run it on. You can install additional languages, depending on the edition of Windows you're using.

    On most computers there is only one installed language, making this a pointless exercise in most cases.



来源:https://stackoverflow.com/questions/2432813/how-to-translate-cultureinfo-language-names

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!