Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moment.js - timezone language (localization)

I use "Moment.js" and it's addition "moment-timezone" in a Web application that supports several languages (english, german, french etc.).

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?

For instance: String "Europe/Vienna" would be in that case changed to "Europe/Wien"

like image 571
LostInTheEcho Avatar asked Jan 11 '17 12:01

LostInTheEcho


1 Answers

A few things:

  • 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.

  • 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.

like image 131
Matt Johnson-Pint Avatar answered Nov 13 '22 04:11

Matt Johnson-Pint