Moment.js - timezone language (localization)
Asked Answered
H

2

8

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"

Heckelphone answered 11/1, 2017 at 12:47 Comment(0)
V
13

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.

Variable answered 11/1, 2017 at 18:53 Comment(1)
The Globalize library has updated. Will you update this answer?Tebet
W
-2
import moment from 'moment';  
import 'moment/locale/fr';  
moment.locale('fr')

Visit Here

Whitson answered 23/3, 2021 at 7:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.