-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
[Intl] New Intl API #9206
Conversation
*/ | ||
public function __construct($genrb = 'genrb', $envVars = '') | ||
{ | ||
exec('which ' . $genrb, $output, $status); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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).
…never an invalid locale is given
…-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
…king for fallback locales
…continues at fallback locale (unless disabled)
…file to enable proper locale fallback
…ss through numeric strings without converting them to integers
…y::forNumericCode()
What is the status of this overhaul ? |
@bschussek can you comment about the status ? And it will need to be rebased |
@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 |
There was a problem hiding this comment.
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.
@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. |
@webmozart If we want this PR to be included in 2.5, we should finish it asap. |
@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). |
…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) 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
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
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
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
@webmozart Is it still relevant? |
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:
I changed the
Intl::get*Bundle()->get*()
methods to throw exceptions instead of just returningnull
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.I added a new method
getLocaleAliases()
toLocaleBundleInterface
.I also did two BC breaks in our internal code, which shouldn't affect our users:
I changed the default value of
$fallback
in the protectedAbstractBundle::readEntry()
method fromfalse
totrue
. The method is just a proxy toStructuredBundleReader::readEntry()
, which also has the defaulttrue
for this parameter. We had numerous bugs in the past that were caused by this parameter beingfalse
by default. This BC break obviously only affects people who extendedAbstractBundle
(I'd be surprised if anyone did).I removed the internal interfaces
CompilationContextInterface
andStubbingContextInterface
.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 theLocaleBundle
, 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 pregeneratedmisc.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 groupicu-consistency
for them, which is excluded by default.TODO: