8

Is there a method to retrieve time zone names in another language?

In Python, if I do something like this:

for tz in pytz.common_timezones_set :
 print tz

The result is in English, but what if I would like to have it in Spanish or Arabic?

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
Trollbane
  • 327
  • 1
  • 5

4 Answers4

6

You can use babel package

import pytz
from babel.dates import get_timezone_location

for tz in pytz.common_timezones_set:
    print(get_timezone_location(tz, locale='es'))
alexey_efimov
  • 1,541
  • 2
  • 12
  • 16
1

No, unfortunately there are no translations for the timezone names. The names are part of the Olson timezone database (not part of Python or pytz). New ones are added from time to time, so any potential translation project would have to stay in sync with that database.

Celada
  • 21,627
  • 4
  • 64
  • 78
1

pytz.common_timezones_set returns a set of timezone ids in the tz database. They are designed to be human readable but they are not translatable.

PyICU provides access to the localized timezone names:

>>> from datetime import datetime
>>> import icu
>>> df = icu.DateFormat.createDateTimeInstance(icu.DateFormat.SHORT, icu.DateFormat.FULL, icu.Locale.getFrance())
>>> df.format(datetime.now(icu.ICUtzinfo.getDefault()))
'27/01/2015 21:01:01 heure normale d’Europe centrale'
jfs
  • 399,953
  • 195
  • 994
  • 1,670
0

Coming quite late but I ran into a similar issue lately, and ended up creating my own package l18n for that purpose. It is available here : https://pypi.org/project/l18n/

It provides translations files for human-readable places and timezones used in pytz. Most of the translations are automatically fetched from the CLDR database, but there are always a few of them missing. For the moment only translation files for English and French are available. Feel free to contact me (create an issue on the packages's repo https://github.com/tkhyn/l18n) or follow the step-by-step procedure here if you want to add translations for your language.

ouk
  • 395
  • 5
  • 7
  • Thanks for putting this together! But a suggestion: 'l' looks like it could be a capital 'i' (and if you squint, a lowercase 'i'), so l18n can be easily confused with i18n. It was a creative name, but perhaps less likely to catch on this way? Also, it's nice to translate the place names, but another useful piece would be to give the actual timezone names (e.g. which seems pretty complicated, unfortunately). – Neal Gokli Aug 03 '17 at 19:10
  • @NealGokli you can get the actual timezone name with `l18n.tz_fullnames`, can't you? – ouk Aug 04 '17 at 21:48