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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
77cbd73
[Intl] Made TextBundleWriter able to write "nofallback" resource bundles
webmozart Oct 2, 2013
ba12cd4
[Intl] Made TextBundleWriter able to write traversables
webmozart Oct 2, 2013
e14dd3a
[Intl] The various Intl methods now throw a NoSuchLocaleException whe…
webmozart Oct 2, 2013
953a29c
[Intl] Changed Intl methods to throw NoSuchEntriesExceptions when non…
webmozart Oct 2, 2013
0b5408b
[Intl] The available locales of each resource bundle are now stored i…
webmozart Oct 2, 2013
2ad4d32
[Intl] Fixed LocaleScanner to actually remove blacklisted locales
webmozart Oct 2, 2013
d6805b4
[Intl] Improved LocaleBundleTransformationRule to not generate duplic…
webmozart Oct 2, 2013
958a4dc
[Intl] Added LocaleScannerTest
webmozart Oct 2, 2013
b3bd0aa
[Intl] Removed unneeded method BundleReaderInterface::getLocales()
webmozart Oct 2, 2013
15419bb
[Intl] Fixed CS
webmozart Oct 3, 2013
fbe2853
[Intl] Fixed currency transformation rule to clean up after the trans…
webmozart Oct 3, 2013
95de438
[Intl] Fixed StructuredBundleReader to follow locale aliases when loo…
webmozart Oct 3, 2013
5d14465
[Intl] Added exception handler to data generation scripts
webmozart Oct 3, 2013
72398a3
[Intl] Decoupled transformation rules from Intl class
webmozart Oct 3, 2013
2bb2508
[Intl] Improved test coverage of BinaryBundleReader
webmozart Oct 3, 2013
9d202dc
[Intl] Improved exception formatting in transformation scripts
webmozart Oct 3, 2013
fec3933
[Intl] StructuredBundleReader now catches NoSuchLocaleExceptions and …
webmozart Oct 3, 2013
945cfef
[Intl] Changed LocaleBundleTransformationRule to generate a root.res …
webmozart Oct 3, 2013
d19e20a
[Intl] Improved error messages in BinaryBundleReader
webmozart Oct 3, 2013
127d9c0
[Intl] Changed AbstractEntry::readEntry() to fallback by default
webmozart Oct 3, 2013
921f9fb
[Intl] Added period to exception message in RecursiveArrayAccess
webmozart Oct 3, 2013
6251c7e
[Intl] Renamed BundleCompiler to GenrbBundleCompiler
webmozart Oct 3, 2013
1b3d920
[Intl] Added missing entries to the UPGRADE file
webmozart Oct 3, 2013
e002eba
[Intl] Renamed StructuredBundleReader[Interface] to BundleEntryReader…
webmozart Oct 3, 2013
c1252ef
[Intl] Added integration tests to check the resource bundles
webmozart Oct 3, 2013
a014f7d
[Intl] Fixed TextBundleWriter to escape keys that contain colons (":")
webmozart Oct 4, 2013
7e36a29
[Intl] Fixed transformation rules not to generate files in the source…
webmozart Oct 4, 2013
a2b31f6
[Intl] Fixed TextBundleWriter to escape keys with spaces (" ")
webmozart Oct 4, 2013
9b34d51
[Intl] Removed the interfaces CompilationContextInterface and Stubbin…
webmozart Oct 4, 2013
8f983ed
[Intl] Moved consistency tests to Icu component
webmozart Oct 7, 2013
52820da
[Intl] Simplified consistency tests
webmozart Oct 7, 2013
9935cb8
[Intl] Changed transformation rules to include more information in th…
webmozart Oct 9, 2013
3ca4108
[Intl] Tested Intl::getFallbackLocale() and let it return "root" for …
webmozart Oct 10, 2013
f4c82dd
[Intl] Changed BinaryBundleReader to never set the fallback flag in \…
webmozart Oct 10, 2013
241e704
[Intl] Implemented new Locale class
webmozart Oct 9, 2013
43076d6
[Intl] Fixed TextWriter to output integer arrays indexed by strings a…
webmozart Oct 10, 2013
e271491
[Intl] Implemented Currency class
webmozart Oct 14, 2013
350f864
[Intl] Renamed getDisplayName()/getDisplayNames() to getName()/getNam…
webmozart Oct 14, 2013
be2ce30
[Intl] Changed "@since" version numbers of new code to 2.5
webmozart Oct 14, 2013
c27325b
[Intl] Fixed "@var" declarations in data provider properties
webmozart Oct 14, 2013
ad3d1f4
[Intl] Updated doc comments
webmozart Oct 14, 2013
76e4930
[Intl] Implemented Language class
webmozart Oct 14, 2013
42f1238
[Intl] Renamed NoSuchEntryException to MissingResourceException
webmozart Oct 14, 2013
1b6aab0
[Intl] Moved Intl::getFallbackLocale() to Locale::getFallback()
webmozart Oct 14, 2013
a7e8e68
[Intl] Implemented Locale::exists()
webmozart Oct 14, 2013
50b516a
[Intl] Fixed TextBundleWriter to write tables with numeric keys
webmozart Oct 14, 2013
05e4761
[Intl] Fixed RecursiveArrayAccess/ArrayAccessibleResourceBundle to pa…
webmozart Oct 15, 2013
1cc7c7a
[Intl] Added Currency::exists(), Currency::canonicalize() and Currenc…
webmozart Oct 15, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Intl] Improved LocaleBundleTransformationRule to not generate duplic…
…ate locale names when fallback (en_GB->en) is possible
  • Loading branch information
webmozart committed Oct 4, 2013
commit d6805b48c99046c8ea5521e06b600da92e0b02f7
4 changes: 4 additions & 0 deletions 4 src/Symfony/Component/Intl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ CHANGELOG
whenever a non-existing language, currency, etc. is accessed
* the available locales of each resource bundle are now stored in a generic
"misc.res" file in order to improve reading performance
* improved `LocaleBundleTransformationRule` to not generate duplicate locale
names when fallback (e.g. "en_GB"->"en") is possible anyway. This reduced
the Resources/ directory file size of the Icu 1.2.x branch from 14M to 12M at
the time of this writing
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,22 @@ public function beforeCompile(CompilationContextInterface $context)
$context->getFilesystem()->mkdir($tempDir);

$locales = $context->getLocaleScanner()->scanLocales($context->getSourceDir().'/locales');
$aliases = $context->getLocaleScanner()->scanAliases($context->getSourceDir().'/locales');

$this->generateTextFiles($tempDir, $locales);
$writer = new TextBundleWriter();

$this->generateTextFiles($writer, $tempDir, $locales, $aliases);

// Generate aliases, needed to enable proper fallback from alias to its
// target
foreach ($aliases as $alias => $aliasOf) {
$writer->write($tempDir, $alias, array('%%ALIAS' => $aliasOf));
}

// Create misc file with all available locales
$writer = new TextBundleWriter();
$writer->write($tempDir, 'misc', array(
'Locales' => $locales,
'Aliases' => $aliases,
), false);

return $tempDir;
Expand Down Expand Up @@ -97,47 +106,86 @@ public function afterCreateStub(StubbingContextInterface $context)
{
}

private function generateTextFiles($targetDirectory, array $locales)
private function generateTextFiles(TextBundleWriter $writer, $targetDirectory, array $locales, array $aliases)
{
// Collect locales for which translations exist
$displayLocales = array_unique(array_merge(
$this->languageBundle->getLocales(),
$this->regionBundle->getLocales()
));

$txtWriter = new TextBundleWriter();
// Flip to facilitate lookup
$displayLocales = array_flip($displayLocales);
$locales = array_flip($locales);

// Generate a list of locale names in the language of each display locale
// Each locale name has the form: "Language (Script, Region, Variant1, ...)
// Script, Region and Variants are optional. If none of them is available,
// the braces are not printed.
foreach ($displayLocales as $displayLocale) {
// Don't include ICU's root resource bundle
if ('root' === $displayLocale) {
continue;
}
// Don't generate names for aliases (names will be generated for the
// locale they are duplicating)
$displayLocales = array_diff_key($displayLocales, $aliases);

// Generate a list of (existing) locale fallbacks
$fallbacks = array();

foreach ($displayLocales as $displayLocale => $_) {
$fallbacks[$displayLocale] = null;
$fallback = $displayLocale;

$names = array();
// Recursively search for a fallback locale until one is found
while (null !== ($fallback = Intl::getFallbackLocale($fallback))) {
// Currently, no locale has an alias as fallback locale.
// If this starts to be the case, we need to add code here.
assert(!isset($aliases[$fallback]));

foreach ($locales as $locale) {
// Don't include ICU's root resource bundle
if ($locale === 'root') {
continue;
// Check whether the fallback exists
if (isset($displayLocales[$fallback])) {
$fallbacks[$displayLocale] = $fallback;
break;
}
}
}

// Since fallbacks are always shorter than their source, we can sort
// the display locales so that fallbacks are always processed before
// their variants
ksort($displayLocales);

$localeNames = array();

// Generate locale names for all locales that have translations in
// at least the language or the region bundle
foreach ($displayLocales as $displayLocale => $_) {
$localeNames[$displayLocale] = array();

foreach ($locales as $locale => $__) {
try {
// Generate a locale name in the language of each display locale
// Each locale name has the form: "Language (Script, Region, Variant1, ...)
// Script, Region and Variants are optional. If none of them is
// available, the braces are not printed.
if (null !== ($name = $this->generateLocaleName($locale, $displayLocale))) {
$names[$locale] = $name;
$localeNames[$displayLocale][$locale] = $name;
}
} catch (NoSuchEntryException $e) {
}
}

// If no names could be generated for the current locale, skip it
if (0 === count($names)) {
// Compare names with the names of the fallback locales and only
// keep the differences
$fallback = $displayLocale;

while (isset($fallbacks[$fallback])) {
$fallback = $fallbacks[$fallback];
$localeNames[$displayLocale] = array_diff(
$localeNames[$displayLocale],
$localeNames[$fallback]
);
}

// If no names remain to be saved for the current locale, skip it
if (0 === count($localeNames[$displayLocale])) {
continue;
}

$txtWriter->write($targetDirectory, $displayLocale, array('Locales' => $names));
$writer->write($targetDirectory, $displayLocale, array('Locales' => $localeNames[$displayLocale]));
}
}

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