简体   繁体   English

Asp.Net MVC:以当前语言显示本地化吗?

[英]Asp.Net MVC: Display a localization in the current language?

I've a website and I need to display some language name in the current culture, based of the two character language name. 我有一个网站,我需要根据两种字符的语言名称显示当前文化中的一些语言名称。

Eg I need to display when the culture is FRench: 例如,当文化是FRench时,我需要显示:

  • fr -> Français fr->法国
  • en -> Anglais zh-> Anglais
  • de -> Allemand de-> Allemand

In German(de) culture 在德国文化中

  • fr -> Français fr->法国
  • en -> Anglais zh-> Anglais
  • de -> Allemand de-> Allemand

... ...

The currentThread culture is already correct(meaning that I'm in "FR" localization). currentThread文化已经是正确的(这意味着我处于“ FR”本地化状态)。

The problem is that if I'm in the french culture and I do: 问题是,如果我属于法国文化并且愿意:

System.Globalization.CultureInfo.GetCultureInfo("de")

I receive this object: 我收到此对象:

Calendar: {System.Globalization.GregorianCalendar}
CompareInfo: {CompareInfo - de}
CultureTypes: NeutralCultures | InstalledWin32Cultures | FrameworkCultures
DateTimeFormat: {System.Globalization.DateTimeFormatInfo}
DisplayName: "German"
EnglishName: "German"
IetfLanguageTag: "de"
IsNeutralCulture: true
IsReadOnly: true
KeyboardLayoutId: 7
LCID: 7
Name: "de"
NativeName: "Deutsch"
NumberFormat: {System.Globalization.NumberFormatInfo}
OptionalCalendars: {System.Globalization.Calendar[1]}
Parent: {}
TextInfo: {TextInfo - de}
ThreeLetterISOLanguageName: "deu"
ThreeLetterWindowsLanguageName: "DEU"
TwoLetterISOLanguageName: "de"
UseUserOverride: false

And I wished that the display name is in the current locale(So "Allemand"). 我希望显示名称位于当前语言环境中(因此为“ Allemand”)。

I'm sure it's possible, am I missing a language pack? 我确定有可能,我是否缺少语言包? At which level? 在哪个级别? Windows? 视窗? ASP? ASP? MVC? MVC? Or should I use a different code? 还是应该使用其他代码?

The .NET Framework does not provide what you are asking for (ie the name of a culture in an arbitrary language). .NET Framework没有提供您所要求的内容(即,一种任意语言的文化名称)。 The properties EnglishName and NativeName are self-explanatory. 属性EnglishNameNativeName是不言自明的。 As for DisplayName , this gives you the name of the culture in the language of your system (so if you're running the .NET Framework in French, you'll get "Allemand"--if you're running it in English, you'll get "German"). 至于DisplayName ,这将为您提供系统语言的区域性名称(因此,如果您以法语运行.NET Framework,则将获得“ Allemand”,如果您以英语运行,您将获得“德语”)。

To clarify this last point, the .NET Framework itself has been localized into a number of languages, and you can get localized versions of the .NET Framework by downloading language packs (eg http://www.microsoft.com/en-us/download/details.aspx?id=3324 for .NET 4.0). 为了澄清最后一点,.NET Framework本身已本地化为多种语言,您可以通过下载语言包来获取.NET Framework的本地化版本(例如, http//www.microsoft.com/zh-cn /download/details.aspx?id=3324(适用于.NET 4.0)。 If you do this then what DisplayName gives you will depend both on your system's locale and on whether or not a language pack for the corresponding language is installed. 如果执行此操作,那么DisplayName提供的内容将取决于系统的语言环境以及是否安装了对应语言的语言包。 In any case, I don't believe that you can rely on this for your scenario as you can't dynamically switch the system locale. 在任何情况下,我都不认为您可以依赖此方案,因为您不能动态切换系统区域设置。

Update: I forgot to mention the solution in case it's not obvious: You can add your list of languages to your localizable resources alongside all your other user interface strings, ie include strings "French", "English" and "German" which for example your French translator will localize as "Français", "Anglais", "Allemand". 更新:如果解决方案不是很明显,我会忘记提及该解决方案:您可以将语言列表与所有其他用户界面字符串一起添加到可本地化的资源中,例如,包括字符串“ French”,“ English”和“ German”您的法语翻译将本地化为“Français”,“ Anglais”,“ Allemand”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM