Skip to content

[Intl] Provide translated timezone names #17636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

c960657
Copy link
Contributor

@c960657 c960657 commented Feb 1, 2016

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR symfony/symfony-docs#6209

This PR adds support for translating timezone names. This is useful e.g. in the TimezoneType form type.

The patch only adds support for identifier (Europe/London) to location/city name mapping (London) and vice versa. I assume this is the most common use-case.

The timezone database contains other elements, including meta-zones, alternative names etc. Support for these may be added in the future.

@c960657 c960657 force-pushed the intl-timezones branch 2 times, most recently from ce37c78 to 3b3fac3 Compare February 1, 2016 07:01
@c960657 c960657 force-pushed the intl-timezones branch 4 times, most recently from 0e7bc01 to b4946ec Compare February 1, 2016 12:00
/**
* Returns the location name (usually a city) for a timezone.
*
* @param string $locale The locale to return the name of (e.g. "de_AT").
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not correspond to signature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@c960657 c960657 force-pushed the intl-timezones branch 3 times, most recently from b9aa2cc to 16bdf3e Compare March 1, 2016 17:41
*
* @return string
*/
protected function getFallbackName($timezone)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be private

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@c960657 c960657 force-pushed the intl-timezones branch 2 times, most recently from e66f0db to a2c1257 Compare March 23, 2016 18:19
@webmozart
Copy link
Contributor

Thanks for creating this great PR @c960657! 🎆 I think both the PR and the rest of the Intl component should be improved, API-wise (see #18368). Do you want to work on that?

@c960657
Copy link
Contributor Author

c960657 commented Apr 2, 2016

@webmozart I agree that the Intl component could be improved or perhaps superseded by one or more new components.

It's a bit unclear to me what the purpose of that package is – it provides a copy of a subset of the CLDR datasets (with some opinionated blacklists of pseudo-currencies, pseudo-countries etc.), a partial reimplementation of PHP's ICU DateFormatter for English only, as well as code for parsing ICU data files and converting them to various Symfony-specific file formats.

CLDR contains a lot of useful data that I would like to see exposed. Symfony will probably never get support for all the different data, but it should make it easy to fetch the relevant bits from the CLDR data files.

I would be interested in working on this, provided that we can agree on a clear direction. I'll add some comments and suggestions to #18368.

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@stof
Copy link
Member

stof commented Mar 31, 2017

Is the data contained in this PR build based on the same ICU version than the other data already in the component ?

If yes, this gets a 👍 from me. If no, we need to recompile the data first.

@curry684
Copy link
Contributor

curry684 commented Apr 1, 2017

Same goes here what I commented in the other PR: the translation quality appears to be sub par and inconsistent, and in that case, no matter the usefulness of the PR itself, we should not want to do it imho.

There are several databases that are kept up to date independently that can provide this data. Why burden Symfony with it?

@nicolas-grekas
Copy link
Member

@jakzal could you have a look at this one please? you're the one doing most of the updates :)

@nicolas-grekas nicolas-grekas changed the base branch from master to 3.4 July 6, 2017 10:17
@c960657
Copy link
Contributor Author

c960657 commented Jul 9, 2017

I don't think it is fair to say that the CLDR translations are poor. CLDR is backed by Microsoft, Google and Apple (among others) who use the data in their software. They all spend considerable ressources on providing high-quality data for a large number of locales.

The blame is on me for using the data the wrong way. Since I submitted this PR last year, I have learned a lot more about the CLDR data and the CLDR spec while contributing to the Punic library.

The Olson database contains timezone definitions but does not specify how they should be displayed to end users. Symfony simply shows the raw timezone identifier with / and _ replaced with dash and space, respectively. This strategy works most of time for English, but it does not handle apostrophes, periods and accents, e.g. Antarctica/DumontDUrville is displayed as “DumontDUrville” rather than “Dumont d’Urville” (search for examplarCity in root.xml for more examples). So even for English, CLDR may help improve matters.

The Olson database does not designate a name for each timezone apart from the timezone identifier (e.g. Europe/Berlin). There are several naming schemes for timezones; for instance, “Berlin time”, “German time” and (to some extent) “CET” are different names for the same timezone. The CLDR spec defines several naming schemes, such as generic non-location format and generic partial location format, that describes how to combine the CLDR strings into end-user facing strings.

A sidenote, not really related to this issue: If you are creating UI that allows users to select a timezone, showing all 400 Olson timezones is probably not the most user-friendly approach. Many of the Olson timezones are duplicates, in the sense that they (in recent years) have identical offsets and DST rules, e.g. Europe/Berlin and Europe/Paris. It makes sense to group the zones in the UI, e.g. like in the Microsoft Windows timezone selector. CLDR includes two such groupings; the one used in Windows, and another called metazones.

So, how does all this apply to Symfony?

In order to build a multi-locale appliation that handles dates and timezones, you would usually use a l10n library such as PHPs Intl extension, the Punic library or similar (Symfonys Intl component is not a l10n library in this respect). These packages often provide translated timezone names. E.g. the Intl extension allows you to get the localized city name like this IntlDateFormatter::formatObject(new DateTime('now', new DateTimeZone('Europe/Rome')), 'VVV', 'it') // returns "Roma".

So it seems there is little benefit in adding the timezone names to the Intl package.

(I guess the same applies to the other data currently provided by Symfonys Intl component, but
as mentioned above, it is unclear to me what the purpose of the Intl package is)

The reason I created this PR in the first place was to allow the timezone form component to be localized (PR #17628). Perhaps a better approach is to use PHPs Intl extension directly at run-time when generating the dropdown (with fallback to English if the Intl extension is not installed). What do you think of this?

@curry684
Copy link
Contributor

@c960657 my apologies if I inferred the quality of your work as a whole was poor, I merely reviewed the proposed changes and concluded that the work being submitted here was not generically usable in its current form. And therefore should not (yet) be a core part of Symfony as it would cause technical debt and BC issues if it were corrected later.

@c960657
Copy link
Contributor Author

c960657 commented Jul 10, 2017

@curry684 No offense taken :-) It seems we agree that this data is available through other libraries and thus does not belong in Symfony.

@nicolas-grekas
Copy link
Member

shall we close then?

@c960657 c960657 closed this Jul 11, 2017
fabpot added a commit that referenced this pull request Apr 21, 2019
This PR was squashed before being merged into the 4.3-dev branch (closes #28831).

Discussion
----------

[Intl] Add Timezones

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | replaces #26851, #17628, #17636
| License       | MIT
| Doc PR        | symfony/symfony-docs#11447

This PR compiles a new `TimezoneBundle` from ICU data, based on the following resources:

- https://github.com/unicode-org/icu/tree/master/icu4c/source/data/zone
- https://github.com/unicode-org/icu/blob/master/icu4c/source/data/misc/timezoneTypes.txt
- https://github.com/unicode-org/icu/blob/master/icu4c/source/data/misc/metaZones.txt

The goal is to provide a fixed set of timezones, with a localized human readable name.

For inspiration and to double check some data i used the timezone widget from google, e.g. when using Google Calendar.

I've only pushed some common compiled locales for review, the rest will follow once finished.

cc @jakzal

Commits
-------

4bea198 [Intl] Add Timezones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants