Moment.js-时区语言(本地化) [英] Moment.js - timezone language (localization)

查看:538
本文介绍了Moment.js-时区语言(本地化)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在支持多种语言(英语,德语,法语等)的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"

推荐答案

几件事:

  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆