Is there a facility to translate the Long timezone names to another language? #258
Replies: 20 comments 12 replies
-
If the data is there I see no issue in added a function that takes a timezone and replaces the region and the subdivision based on the from and to locale. You might want to consider putting in ex_cldr_territories as there are other functions there that deals we translating region and subdivision. Although I leave the decision to @kipcole9 as he has a better knowledge of the data available and the rest of the libraries. |
Beta Was this translation helpful? Give feedback.
-
I've been actively avoiding this topic for years now. And I should have known that @tjchambers would eventually come asking very good questions that don't have easy answers :-) Random thoughtsMy normal default response to UIs that ask users to pick timezones is to say "don't do that" because most users don't understand timezones. Prefer instead to ask for a city name, resolve that to lat/lng and use something like tz_world to resolve the timezone. However this does require a geocoding library as well. and one that includes localised place names. So not that easy. CLDR does localise timezone names for metazones so being able to translate a zone will often be possible and I will add this to ex_cldr_dates_times because by the spec, I should already be using this data for certain date formats. From a UX point of view, I'm not sure how to handle the case where multiple zone names apply to the same zone. There are a lot of them: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones And then there's daylight savings time ..... Proposed workI will add functions to return localised display names for a timezone. These are typically of three types: generic, standard and daylight. In this first implementation the developer will need to decided which one they want. Its going to take a little time to wrap my head around CLDR resolves timezone names to metazones with fallbacks. I will also aim to map a DateTime.t to a localised timezone name. @tjchambers, would that be enough to get started with? Comments and suggestions most welcome. |
Beta Was this translation helpful? Give feedback.
-
I think I've got a path forward but there is quite a bit of work to do - the hardest part is decoding the spec but the best way I've found it just to do work and puzzle it out as we go.
|
Beta Was this translation helpful? Give feedback.
-
I want to be clear about what I in particular am trying to achieve and that is to let a user pick their timezone, but do so in their language. SO my app is using the locale What I do not need (or do not believe I need) is to "guess" from the locale their current timezone - I am already leveraging other code to do so. From that you might surmise "Why do you need them to pick it if you already know it?" and that would be an excellent question. However they may need to override it for various reasons, like putting themselves into another persons timezone for the purposes of determining a date for a scheduled event from the other person's perspective. In any case I want to be clear that I am looking for an "official" way to present that timezone list in the language of their locale. Thanks for your attention on this. |
Beta Was this translation helpful? Give feedback.
-
Understood @tjchambers, I was just rambling a bit in my response. Based upon what I see in the CLDR data there is a localised timezone display name that could be displayed. Thats not strictly the same as a translated timezone. But it would present in a UI a localized name than is then mapped to the actual timezone name. Does that seem workable for you? |
Beta Was this translation helpful? Give feedback.
-
If you could direct me to what I think you are describing I could certainly examine that. You know that large dataset much better than I. I am fine with self servicing it but want to contribute back if it is something valuable to others. |
Beta Was this translation helpful? Give feedback.
-
You could do the following in the
You'll see a map in which a typical entry would look like:
|
Beta Was this translation helpful? Give feedback.
-
In case I wasn't clear earlier, I will most definitely make the overall timezone data available as part of the API of This still requires mapping through metazone data that is not currently in |
Beta Was this translation helpful? Give feedback.
-
I've created a new repo that encapsulates the metazone data. There are two new relevant functions:
These functions are required to make further progress in If for some reason you're interested in what the data looks like, then feel free to configure |
Beta Was this translation helpful? Give feedback.
-
Added:
Which I believe concludes encapsulating the necessary data - now on to work on |
Beta Was this translation helpful? Give feedback.
-
And ... now I've added the functions in The next step is to decode the standard and implement it. The first function I'll aim for is |
Beta Was this translation helpful? Give feedback.
-
Good progress this week and its now ready for your early review. Configuration
Usage
ExamplesNon-location formatiex> Cldr.DateTime.Timezone.non_location_format("Australia/Sydney")
{:ok, "Australian Eastern Time"}
iex> Cldr.DateTime.Timezone.non_location_format("Asia/Shanghai")
{:ok, "China Time"}
iex> Cldr.DateTime.Timezone.non_location_format("Europe/Rome", locale: :ja)
{:ok, "中央ヨーロッパ時間"} Location formatiex> Cldr.DateTime.Timezone.location_format("America/Phoenix", format: :short)
{:ok, "Phoenix Time"}
iex> Cldr.DateTime.Timezone.location_format("Europe/Rome", locale: :ja)
{:ok, "イタリア時間"}
iex> Cldr.DateTime.Timezone.location_format("America/New_York", locale: :fr, type: :daylight)
{:ok, "New York (heure d’été)"} Exemplar Cityiex> Cldr.DateTime.Timezone.exemplar_city("Australia/Sydney")
{:ok, "Sydney"}
iex> Cldr.DateTime.Timezone.exemplar_city("Europe/Kiev")
{:ok, "Kyiv"}
iex> Cldr.DateTime.Timezone.exemplar_city("America/Indiana/Knox")
{:ok, "Knox, Indiana"}
iex> Cldr.DateTime.Timezone.exemplar_city("Europe/Kiev", locale: :ja)
{:ok, "キーウ"} Work still to do
|
Beta Was this translation helpful? Give feedback.
-
I've added a lot of tests, and added
|
Beta Was this translation helpful? Give feedback.
-
Some thoughts on selecting timezones in an UI. Comments and suggestions very welcome.
|
Beta Was this translation helpful? Give feedback.
-
Am not sure that this is a correct statement as the summer time s/b GMT-7 I believe. |
Beta Was this translation helpful? Give feedback.
-
https://github.com/elixir-cldr/cldr_dates_times/blame/5be08255f2c0022964755e38b392e2f1f42b2645/lib/cldr/format/date_time_timezone.ex#L136 small typo "THe" |
Beta Was this translation helpful? Give feedback.
-
It might be useful to indicate somewhere in the doc that no attempt is made to support or process NATO military times zones. I am aware the the "Z" format overlaps with UTC but the other alphabet is not supported or part of this afaict. I am referring to https://en.wikipedia.org/wiki/Military_time_zone |
Beta Was this translation helpful? Give feedback.
-
https://github.com/elixir-cldr/cldr_dates_times/blame/5be08255f2c0022964755e38b392e2f1f42b2645/lib/cldr/format/date_time_timezone.ex#L485 type "daatabase" |
Beta Was this translation helpful? Give feedback.
-
https://github.com/elixir-cldr/cldr_dates_times/blame/5be08255f2c0022964755e38b392e2f1f42b2645/lib/cldr/format/date_time_timezone.ex#L503 typo "datababase" |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an app where I wish to allow the user to pick a timezone i.e. "America/Louisville" from a dropdown list on a form. I can easily get all those timezone names IN ENGLISH. I realize that in cldr/common/main/*.xml there are exemplar cities translated into other languages in the .XML source.
I am doing this in a Phoenix app and would like to translate the dropdown for instance for Japanese users so they can see the Kanji equivalent of "American/Louisville" for example in the dropdown. I believe at least the cities are translated in the .xml files, and I presume also in the .json content in ex_cldr.
Please advise.
Beta Was this translation helpful? Give feedback.
All reactions