开发者

Get language name from locale string using .NET? ex: en_us => english

How can i find the language for a given locale?

Example: input: en_US output: English

Using the .NET libraries? I tried the CultureInfo class, but i can't find someth开发者_Python百科ing usefull.

Thanks!


Do not use the constructor of CultureInfo. It is faster to use the static GetCultureInfo method since this method is cached and returns an immutable (readonly) CultureInfo object.

According to the Facebook SDK documentation concerning localization, it is safe to assume that you can replace the underscore by a dash in order to allow .NET to understand the locale.

Facebook locales follow ISO language and country codes respectively, concatenated by an underscore.

The basic format is ''ll_CC'', where ''ll'' is a two-letter language code, and ''CC'' is a two-letter country code. For instance, 'en_US' represents US English.

Depending if you need the name to appear in english regardless of the language of the OS, use

CultureInfo.GetCultureInfo("en-US").EnglishName

If you need the name in the language of the OS, use:

CultureInfo.GetCultureInfo("en-US").DisplayName


You need to use en-US not en_US with code like:

System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
string name = culture.DisplayName;

output: English (United States)


System.Globalization.CultureInfo.GetCultureInfo("en-US").EnglishName;


You can use following code

Dim culture1 As CultureInfo = New CultureInfo("en-US")
Dim t As Thread = Thread.CurrentThread
Dim currentCulture As CultureInfo = t.CurrentCulture
Dim currentUICulture As CultureInfo = t.CurrentUICulture

'*** display cultures in console
Console.WriteLine("Current Culture: " & currentCulture.Name)
Console.WriteLine("Current UI Culture: " & currentUICulture.Name)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜