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?
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?
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'))
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.
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'
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.