Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Intl] New Intl API #9206

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 48 commits into from
Closed

[Intl] New Intl API #9206

wants to merge 48 commits into from

Conversation

webmozart
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? yes
Deprecations? yes
Tests pass? yes
Fixed tickets #5802
License MIT
Doc PR TODO

The following description is outdated. This PR has turned into an overhaul of the Intl API to basically rebuild ICU4J/ICU4C (the official ICU APIs) under PHP. Once I'm done, I'll update the text below.

This PR contains a new, extensive integration test suite for the Intl component that check whether the methods of the resource bundles work correctly and consistently in practice. When I wrote this test suite, I discovered numerous bugs that have been fixed in this PR.

I had to do two major BC breaks:

  1. I changed the Intl::get*Bundle()->get*() methods to throw exceptions instead of just returning null on errors. Otherwise it would have been impossible to fix the existing bugs. Consequently, anybody using these methods directly with invalid languages, locales etc. will now experience an uncaught exception. People using the Form layer only should not be affected.

  2. I added a new method getLocaleAliases() to LocaleBundleInterface.

I also did two BC breaks in our internal code, which shouldn't affect our users:

  1. I changed the default value of $fallback in the protected AbstractBundle::readEntry() method from false to true. The method is just a proxy to StructuredBundleReader::readEntry(), which also has the default true for this parameter. We had numerous bugs in the past that were caused by this parameter being false by default. This BC break obviously only affects people who extended AbstractBundle (I'd be surprised if anyone did).

  2. I removed the internal interfaces CompilationContextInterface and StubbingContextInterface.

The fixed bugs had mainly to do with locale aliases. When locales get renamed in ICU, the old locale remains as an alias for (think: pointer to) the new locale. For example, the locale "mo" is an alias for "ro_MD". That locale falls back to "ro" if entries can't be found. Previously, the fallback from "mo" to "ro" did not work since aliases were ignored.

Additionally, the .res files for aliases (i.e. pointers to the new actual locales) were not generated for the LocaleBundle, so locale aliases there could not be accessed at all (e.g. Intl::getLocaleBundle()->getLocaleName('en', 'mo') -> bang).

The PR also contains improvements in efficiency. When accessing the Intl::get*Bundle()->getLocales(), the bundles won't scan the filesystem for available locales anymore (slow), but read a cached entry from a pregenerated misc.res file (speedy gonzales).

The new test suite (see the *ConsistencyTest) is a very nice documentation of the current state of the ICU data, so go and check it out. Some tests are very slow, so I created a new group icu-consistency for them, which is excluded by default.

TODO:

  • Test and upgrade symfony/Icu 1.2.x
  • Test and upgrade symfony/Icu 1.1.x
  • Test and upgrade symfony/Icu 1.0.x
  • Make sure no BC breaks leak through to the Form component
  • Update Intl component documentation

*/
public function __construct($genrb = 'genrb', $envVars = '')
{
exec('which ' . $genrb, $output, $status);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not using symfony/process?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question :) but out of scope of this PR (this class was just renamed, the above code remained the same).

…-existing languages, currencies, etc. are accessed
…n a generic misc.res file to improve reading performance
…ate locale names when fallback (en_GB->en) is possible
…continues at fallback locale (unless disabled)
@pvgnd
Copy link
Contributor

pvgnd commented Dec 16, 2013

What is the status of this overhaul ?
Is there a workaround on Symfony 2.3 or Symfony 2.4 to be able to use Intl ?

@stof
Copy link
Member

stof commented Jan 24, 2014

@bschussek can you comment about the status ?

And it will need to be rebased

@webmozart
Copy link
Contributor Author

@stof Currently on hold due to other, more important, issues. I'd however be interested in feedback about the new API. I designed the API to reflect ICU4Js API (more or less), i.e. classes with static methods, such as:

$currencies = Currency::getCurrencies();
$names = Currency::getNames();

if (Language::exists('de_DE')) // etc.

Now we all know that static methods are boo. However, these methods are used to access "global system information", so I'm not sure whether it makes sense to always pass objects around for accessing this global information.

Opinions?

/cc @pierrejoye

*
* @throws InvalidArgumentException If the currency or the locale is invalid
*
* @api
Copy link
Member

Choose a reason for hiding this comment

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

All the @api tags should be removed IMO. We should not decide to enforce full BC on them before they are even final.

@stof
Copy link
Member

stof commented Jan 24, 2014

@bschussek Teh issue I see with using a static API is that it means that code using it cannot be tested in isolation anymore, because you cannot mock the static calls being done in the middle.

@fabpot
Copy link
Member

fabpot commented Mar 3, 2014

@webmozart If we want this PR to be included in 2.5, we should finish it asap.

@pierrejoye
Copy link

@stof what is the problem actually? I do not see much point to create an instance for only checking the existence of a locale (or other ICU related data).

webmozart added a commit that referenced this pull request Sep 12, 2014
…cessibleResourceBundle (webmozart)

This PR was merged into the 2.3 branch.

Discussion
----------

[Intl] Removed non-working $fallback argument from ArrayAccessibleResourceBundle

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

The code in question didn't actually work. This was extracted from #9206.

Commits
-------

5feda5e [Intl] Removed non-working $fallback argument from ArrayAccessibleResourceBundle
webmozart added a commit that referenced this pull request Sep 12, 2014
…webmozart)

This PR was merged into the 2.3 branch.

Discussion
----------

[Intl] Added exception handler to command line scripts

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Extracted from #9206.

Commits
-------

9052efc [Intl] Added exception handler to command line scripts
webmozart added a commit that referenced this pull request Sep 12, 2014
This PR was merged into the 2.3 branch.

Discussion
----------

[Intl] Updated icu.ini up to ICU 53

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Extracted from #9206.

Commits
-------

260e2fe [Intl] Updated icu.ini up to ICU 53
webmozart added a commit that referenced this pull request Sep 15, 2014
This PR was merged into the 2.3 branch.

Discussion
----------

[Intl] Fixed a few bugs in TextBundleWriter

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

See the included test cases for more information. This code was extracted from #9206.

Commits
-------

7b4a35a [Intl] Fixed a few bugs in TextBundleWriter
webmozart added a commit that referenced this pull request Sep 15, 2014
This PR was merged into the 2.3 branch.

Discussion
----------

[Intl] Improved bundle reader implementations

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This PR extracts bundle reader improvements from #9206.

The code is internal and used for resource bundle generation only, so I did not care about BC too much.

Commits
-------

c3cce5c [Intl] Improved bundle reader implementations
@fabpot
Copy link
Member

fabpot commented Dec 24, 2014

@webmozart Is it still relevant?

@fabpot fabpot closed this Feb 5, 2015
@webmozart webmozart mentioned this pull request Mar 30, 2016
7 tasks
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.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.