Moment.js-时区语言(本地化) [英] Moment.js - timezone language (localization)
问题描述
我在支持多种语言(英语,德语,法语等)的Web应用程序中使用"Moment.js"及其附加的"moment-timezone".
I use "Moment.js" and it's addition "moment-timezone" in a Web application that supports several languages (english, german, french etc.).
因此,为了改善用户体验,我想知道是否已经存在一个本地化文件(例如Moment.js的本地化文件),该文件可以将时区名称从英语更改为所需的语言,或者我需要自己编写?
So to improve the user experience I'd like to know if there already exists a localization file (like the one for Moment.js) that can change timezone names from english to the desired language or do I need to write it myself?
例如:在这种情况下,字符串"Europe/Vienna"将更改为"Europe/Wien"
For instance: String "Europe/Vienna" would be in that case changed to "Europe/Wien"
推荐答案
几件事:
- 您要查找的内容在时区或时区中不存在.
- 您实际上不应更改为欧洲/维恩".时区字符串为 IANA时区标识符,并且始终为英文.
- 通常,IANA时区标识符并不是为人类可读性而设计的. CLDR的职责是翻译成可读的名称,例如英语的欧洲中部时间"或德语的MitteleuropäischeZeit".项目.
-
您可以使用 Globalize库来访问JavaScript中的CLDR数据,但是AFAIK他们目前不支持时区名称. 我已经在这里请求了.
- What you're looking for doesn't exist in moment or moment-time zone.
- You shouldn't actually change to "Europe/Wien". The time zone strings are IANA time zone identifiers, and are always in English.
- In general, IANA time zone identifiers aren't designed for human readability. Translation to human readable names like "Central European Time" in English, or "Mitteleuropäische Zeit" in German, is the responsibility of the CLDR project.
You can use the Globalize library to get access to CLDR data in JavaScript, however AFAIK they don't currently have support for time zone names. I've requested this here.
即使将IANA时区ID适当转换为本地化的时区名称,也可能很难使用此数据来构建时区选择器控件.我已经在.NET中使用我的TimeZoneNames库(演示
Even with an adequate translation of IANA time zone ID to localized time zone names, it can be difficult to use this data to build time zone picker controls. I've done this in .NET with my TimeZoneNames library (demo here), but not in pure JS. I've yet to see a simple solution to this in JavaScript yet. If I ever find one (or create one), I'll come back here and update this answer.
您可能考虑的其他替代方法是使用基于地图的时区选择器,例如此一个,或这一个和其他.
Other alternatives you might consider are to use a map-based time zone picker, such as this one, or this one, and others.
这篇关于Moment.js-时区语言(本地化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!