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] Implemented Locale::exists()
  • Loading branch information
webmozart committed Oct 14, 2013
commit a7e8e683759ef5cdba2a72d3563dcfc84b589864
6 changes: 3 additions & 3 deletions 6 src/Symfony/Component/Intl/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function getSymbol($currency, $displayLocale = null)
throw new InvalidArgumentException('The currency "' . $currency . '" does not exist.');
}

if (null !== $displayLocale && !in_array($displayLocale, Locale::getLocales(), true)) {
if (null !== $displayLocale && !Locale::exists($displayLocale)) {
throw new InvalidArgumentException('The locale "' . $displayLocale . '" does not exist.');
}

Expand Down Expand Up @@ -111,7 +111,7 @@ public static function getName($currency, $displayLocale = null)
throw new InvalidArgumentException('The currency "' . $currency . '" does not exist.');
}

if (null !== $displayLocale && !in_array($displayLocale, Locale::getLocales(), true)) {
if (null !== $displayLocale && !Locale::exists($displayLocale)) {
throw new InvalidArgumentException('The locale "' . $displayLocale . '" does not exist.');
}

Expand Down Expand Up @@ -141,7 +141,7 @@ public static function getName($currency, $displayLocale = null)
*/
public static function getNames($displayLocale = null)
{
if (null !== $displayLocale && !in_array($displayLocale, Locale::getLocales(), true)) {
if (null !== $displayLocale && !Locale::exists($displayLocale)) {
throw new InvalidArgumentException('The locale "' . $displayLocale . '" does not exist.');
}

Expand Down
6 changes: 3 additions & 3 deletions 6 src/Symfony/Component/Intl/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function getLanguages()
* provided where an equivalent ISO 639-1 two-letter code exists.
*
* If you want to support the above cases, you should manually canonicalize
* the language code in prior to calling this method.
* the language code prior to calling this method.
*
* @param string $language A canonicalized ISO 639 language code (e.g. "en")
*
Expand Down Expand Up @@ -184,7 +184,7 @@ public static function getName($language, $displayLocale = null)
throw new InvalidArgumentException('The language "' . $language . '" does not exist.');
}

if (null !== $displayLocale && !in_array($displayLocale, Locale::getLocales(), true)) {
if (null !== $displayLocale && !Locale::exists($displayLocale)) {
throw new InvalidArgumentException('The locale "' . $displayLocale . '" does not exist.');
}

Expand Down Expand Up @@ -215,7 +215,7 @@ public static function getName($language, $displayLocale = null)
*/
public static function getNames($displayLocale = null)
{
if (null !== $displayLocale && !in_array($displayLocale, Locale::getLocales(), true)) {
if (null !== $displayLocale && !Locale::exists($displayLocale)) {
throw new InvalidArgumentException('The locale "' . $displayLocale . '" does not exist.');
}

Expand Down
38 changes: 36 additions & 2 deletions 38 src/Symfony/Component/Intl/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class Locale extends \Locale
*/
private static $locales;

/**
* @var integer[]|null
*/
private static $lookupTable;

/**
* Returns all available locales.
*
Expand All @@ -50,6 +55,35 @@ public static function getLocales()
return self::$locales;
}

/**
* Returns whether the given ICU locale exists.
*
* This method does not canonicalize the given locale. Specifically, it will
* return false if the locale is not correctly cased or uses hyphens ("-")
* as separators between the subtags instead of underscores ("_"). For
* example, this method returns false for "en-Latn-GB", but true for
* "en_Latn_GB".
*
* If you want to support the above cases, you should manually canonicalize
* the locale prior to calling this method.
*
* @param string $locale A canonicalized ICU locale (e.g. "en_Latn_GB")
*
* @return Boolean Whether the locale exists
*
* @see canonicalize
*
* @api
*/
public static function exists($locale)
{
if (null === self::$lookupTable) {
self::$lookupTable = array_flip(static::getLocales());
}

return isset(self::$lookupTable[$locale]);
}

/**
* Returns the name of a locale in the given display locale.
*
Expand All @@ -74,7 +108,7 @@ public static function getLocales()
*/
public static function getName($locale, $displayLocale = null)
{
if (!in_array($locale, self::getLocales(), true)) {
if (!static::exists($locale)) {
throw new InvalidArgumentException('The locale "' . $locale . '" does not exist.');
}

Expand Down Expand Up @@ -108,7 +142,7 @@ public static function getName($locale, $displayLocale = null)
*/
public static function getNames($displayLocale = null)
{
if (null !== $displayLocale && !in_array($displayLocale, Locale::getLocales(), true)) {
if (null !== $displayLocale && !Locale::exists($displayLocale)) {
throw new InvalidArgumentException('The locale "' . $displayLocale . '" does not exist.');
}

Expand Down
6 changes: 6 additions & 0 deletions 6 src/Symfony/Component/Intl/Tests/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
namespace Symfony\Component\Intl\Tests;

use Symfony\Component\Intl\Language;
use Symfony\Component\Intl\Locale;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class LanguageTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
Locale::setDefault('en');
}

public function existsProvider()
{
return array(
Expand Down
31 changes: 31 additions & 0 deletions 31 src/Symfony/Component/Intl/Tests/LocaleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@ protected function setUp()
Locale::setDefault('en');
}

public function existsProvider()
{
return array(
array(true, 'de'),
array(true, 'de_AT'),
// scripts are supported in some cases
array(true, 'zh_Hant_TW'),
// but not in others
array(false, 'de_Latn_AT'),
// different casing is not supported
array(false, 'De_AT'),
// hyphens are not supported
array(false, 'de-AT'),
// aliases with individual translations are supported
array(true, 'mo'),
// ISO 936-2 is not supported if an equivalent exists in ISO 936-1
array(false, 'deu'),
array(false, 'deu_AT'),
// country aliases are not supported
array(false, 'de_AUT'),
);
}

/**
* @dataProvider existsProvider
*/
public function testExists($exists, $language)
{
$this->assertSame($exists, Locale::exists($language));
}

public function testGetName()
{
$this->assertSame('English', Locale::getName('en', 'en'));
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.