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] Renamed NoSuchEntryException to MissingResourceException
  • Loading branch information
webmozart committed Oct 14, 2013
commit 42f123821c742949223a7a02c3f3d1f0dd8731b1
6 changes: 3 additions & 3 deletions 6 UPGRADE-2.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Intl

* The methods in the various resource bundles of the `Intl` class used to
return `null` when invalid arguments were given. These methods throw a
`NoSuchEntryException` now.
`MissingResourceException` now.

Before:

Expand All @@ -39,7 +39,7 @@ Intl

```
use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\Exception\NoSuchEntryException;
use Symfony\Component\Intl\Exception\MissingResourceException;
use Symfony\Component\Intl\Exception\NoSuchLocaleException;

try {
Expand All @@ -48,7 +48,7 @@ Intl

// invalid locale
$language = Intl::getLanguageBundle()->getLanguageName('de', null, 'foo');
} catch (NoSuchEntryException $e) {
} catch (MissingResourceException $e) {
if ($e->getPrevious() instanceof NoSuchLocaleException) {
// locale was invalid...
} else {
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Intl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CHANGELOG
2.4.0
-----

* [BC BREAK] the various Intl methods now throw a `NoSuchEntryException`
* [BC BREAK] the various Intl methods now throw a `MissingResourceException`
whenever a non-existing locale, 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
Expand Down
26 changes: 8 additions & 18 deletions 26 src/Symfony/Component/Intl/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public static function getCurrencies()
*
* @return string The currency symbol for the specified locale
*
* @throws Exception\InvalidArgumentException If the currency or the locale
* is invalid
* @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.

*/
Expand All @@ -84,11 +83,7 @@ public static function getSymbol($currency, $displayLocale = null)
$displayLocale = \Locale::getDefault();
}

try {
return self::getDataProvider()->getSymbol($currency, $displayLocale);
} catch (NoSuchEntryException $e) {
return $currency;
}
return self::getDataProvider()->getSymbol($currency, $displayLocale);
}

/**
Expand All @@ -106,8 +101,7 @@ public static function getSymbol($currency, $displayLocale = null)
*
* @return string The name of the currency
*
* @throws Exception\InvalidArgumentException If the currency or the locale
* is invalid
* @throws InvalidArgumentException If the currency or the locale is invalid
*
* @api
*/
Expand All @@ -125,11 +119,7 @@ public static function getName($currency, $displayLocale = null)
$displayLocale = \Locale::getDefault();
}

try {
return self::getDataProvider()->getName($currency, $displayLocale);
} catch (NoSuchEntryException $e) {
return $currency;
}
return self::getDataProvider()->getName($currency, $displayLocale);
}

/**
Expand All @@ -145,7 +135,7 @@ public static function getName($currency, $displayLocale = null)
*
* @return string[] An array of currency names indexed by currency codes
*
* @throws Exception\InvalidArgumentException If the locale is invalid
* @throws InvalidArgumentException If the locale is invalid
*
* @api
*/
Expand All @@ -172,7 +162,7 @@ public static function getNames($displayLocale = null)
*
* @return integer The number of digits after the comma
*
* @throws Exception\InvalidArgumentException If the currency is invalid
* @throws InvalidArgumentException If the currency is invalid
*
* @api
*/
Expand All @@ -196,7 +186,7 @@ public static function getFractionDigits($currency)
*
* @return integer The rounding increment
*
* @throws Exception\InvalidArgumentException If the currency is invalid
* @throws InvalidArgumentException If the currency is invalid
*
* @api
*/
Expand All @@ -219,7 +209,7 @@ public static function getRoundingIncrement($currency)
*
* @return integer The numeric code
*
* @throws Exception\InvalidArgumentException If the currency is invalid
* @throws InvalidArgumentException If the currency is invalid
*
* @api
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class NoSuchEntryException extends RuntimeException
class MissingResourceException extends RuntimeException
{
}
13 changes: 5 additions & 8 deletions 13 src/Symfony/Component/Intl/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\Icu\LanguageDataProvider;
use Symfony\Component\Intl\Exception\InvalidArgumentException;
use Symfony\Component\Intl\Exception\NoSuchEntryException;

/**
* Provides access to language-related data.
Expand Down Expand Up @@ -193,11 +192,7 @@ public static function getName($language, $displayLocale = null)
$displayLocale = \Locale::getDefault();
}

try {
return self::getDataProvider()->getName($language, $displayLocale);
} catch (NoSuchEntryException $e) {
return $language;
}
return self::getDataProvider()->getName($language, $displayLocale);
}

/**
Expand Down Expand Up @@ -238,7 +233,9 @@ public static function getNames($displayLocale = null)
*
* @return string The ISO 639-2 three-letter code of the language
*
* @throws InvalidArgumentException If the language is invalid
* @throws Exception\InvalidArgumentException If the language is invalid
* @throws Exception\MissingResourceException If the language has no
* corresponding three-letter code
*
* @api
*/
Expand All @@ -248,7 +245,7 @@ public static function getAlpha3Code($language)
throw new InvalidArgumentException('The language "' . $language . '" does not exist.');
}

return self::getDataProvider->getAlpha3Code($language);
return self::getDataProvider()->getAlpha3Code($language);
}

/**
Expand Down
1 change: 0 additions & 1 deletion 1 src/Symfony/Component/Intl/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\Icu\LocaleDataProvider;
use Symfony\Component\Intl\Exception\InvalidArgumentException;
use Symfony\Component\Intl\Exception\NoSuchEntryException;

/**
* Provides access to locale-related data.
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\Intl\ResourceBundle;

use Symfony\Component\Icu\LanguageDataProvider;
use Symfony\Component\Intl\Exception\NoSuchEntryException;
use Symfony\Component\Intl\Exception\MissingResourceException;
use Symfony\Component\Intl\Locale;
use Symfony\Component\Intl\ResourceBundle\Reader\BundleEntryReaderInterface;

Expand Down Expand Up @@ -67,7 +67,7 @@ public function getLanguageName($lang, $region = null, $locale = null)
if (null !== $region) {
try {
return $this->languageDataProvider->getName($lang.'_'.$region, $locale);
} catch (NoSuchEntryException $e) {
} catch (MissingResourceException $e) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\Intl\ResourceBundle\Reader;

use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\Exception\NoSuchEntryException;
use Symfony\Component\Intl\Exception\MissingResourceException;
use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException;
use Symfony\Component\Intl\Exception\OutOfBoundsException;
use Symfony\Component\Intl\ResourceBundle\Util\RecursiveArrayAccess;
Expand Down Expand Up @@ -177,6 +177,6 @@ public function readEntry($path, $locale, array $indices, $fallback = true)
);
}

throw new NoSuchEntryException($errorMessage, 0, $exception);
throw new MissingResourceException($errorMessage, 0, $exception);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ interface BundleEntryReaderInterface extends BundleReaderInterface
* in the requested locale.
*
* @return mixed Returns an array or {@link \ArrayAccess} instance for
* complex data, a scalar value for simple data and NULL
* if the given path could not be accessed.
* complex data and a scalar value for simple data.
*
* @throws \Symfony\Component\Intl\Exception\MissingResourceException If the indices cannot be accessed
*/
public function readEntry($path, $locale, array $indices, $fallback = true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Intl\ResourceBundle\Transformer\Rule;

use Symfony\Component\Intl\Exception\NoSuchEntryException;
use Symfony\Component\Intl\Exception\MissingResourceException;
use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException;
use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\ResourceBundle\LanguageBundleInterface;
Expand Down Expand Up @@ -148,7 +148,7 @@ private function generateTextFiles(TextBundleWriter $writer, $targetDirectory, a
if (null !== ($name = $this->generateLocaleName($locale, $displayLocale))) {
$localeNames[$displayLocale][$locale] = $name;
}
} catch (NoSuchEntryException $e) {
} catch (MissingResourceException $e) {
} catch (ResourceBundleNotFoundException $e) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Intl\Test;

use Symfony\Component\Intl\Exception\NoSuchEntryException;
use Symfony\Component\Intl\Exception\MissingResourceException;
use Symfony\Component\Intl\Intl;

/**
Expand Down Expand Up @@ -84,7 +84,7 @@ public function testGetLanguageNames()
try {
Intl::getLanguageBundle()->getLanguageNames($displayLocale);
$translatedLocales[] = $displayLocale;
} catch (NoSuchEntryException $e) {
} catch (MissingResourceException $e) {
}
}

Expand Down Expand Up @@ -115,7 +115,7 @@ public function testGetLanguageName($language)
try {
Intl::getLanguageBundle()->getLanguageName($language ?: $displayLocale, null, $displayLocale);
$translatedLocales[] = $displayLocale;
} catch (NoSuchEntryException $e) {
} catch (MissingResourceException $e) {
}
}

Expand All @@ -135,7 +135,7 @@ public function testGetScriptNames()
try {
Intl::getLanguageBundle()->getScriptNames($displayLocale);
$translatedLocales[] = $displayLocale;
} catch (NoSuchEntryException $e) {
} catch (MissingResourceException $e) {
}
}

Expand Down Expand Up @@ -166,7 +166,7 @@ public function testGetScriptName($script)
try {
Intl::getLanguageBundle()->getScriptName($script, null, $displayLocale);
$translatedLocales[] = $displayLocale;
} catch (NoSuchEntryException $e) {
} catch (MissingResourceException $e) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Intl\Test;

use Symfony\Component\Intl\Exception\NoSuchEntryException;
use Symfony\Component\Intl\Exception\MissingResourceException;
use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\Test\ConsistencyTestCase;

Expand Down Expand Up @@ -81,7 +81,7 @@ public function testGetCountryNames()
try {
Intl::getRegionBundle()->getCountryNames($displayLocale);
$translatedLocales[] = $displayLocale;
} catch (NoSuchEntryException $e) {
} catch (MissingResourceException $e) {
}
}

Expand Down Expand Up @@ -112,7 +112,7 @@ public function testGetCountryName($country)
try {
Intl::getRegionBundle()->getCountryName($country, $displayLocale);
$translatedLocales[] = $displayLocale;
} catch (NoSuchEntryException $e) {
} catch (MissingResourceException $e) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function ($value) { return array($value); },

/**
* @dataProvider provideLanguagesWithoutAlpha3Equivalent
* @expectedException \Symfony\Component\Intl\Exception\NoSuchEntryException
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
*/
public function testGetAlpha3CodeFailsIfNoAlpha3Equivalent($currency)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Intl\Tests\ResourceBundle;

use Symfony\Component\Intl\Exception\NoSuchEntryException;
use Symfony\Component\Intl\Exception\MissingResourceException;
use Symfony\Component\Intl\ResourceBundle\LanguageBundle;

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ public function testGetLanguageNameWithUntranslatedRegion()
$this->reader->expects($this->at(0))
->method('readEntry')
->with(self::RES_DIR, 'en', array('Languages', 'en_US'))
->will($this->throwException(new NoSuchEntryException()));
->will($this->throwException(new MissingResourceException()));

$this->reader->expects($this->at(1))
->method('readEntry')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testReadExistingEntry()
}

/**
* @expectedException \Symfony\Component\Intl\Exception\NoSuchEntryException
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
*/
public function testReadNonExistingEntry()
{
Expand Down Expand Up @@ -130,7 +130,7 @@ public function testFallbackIfEntryDoesNotExist()
}

/**
* @expectedException \Symfony\Component\Intl\Exception\NoSuchEntryException
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
*/
public function testDontFallbackIfEntryDoesNotExistAndFallbackDisabled()
{
Expand Down Expand Up @@ -158,7 +158,7 @@ public function testFallbackIfLocaleDoesNotExist()
}

/**
* @expectedException \Symfony\Component\Intl\Exception\NoSuchEntryException
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
*/
public function testDontFallbackIfLocaleDoesNotExistAndFallbackDisabled()
{
Expand Down Expand Up @@ -290,7 +290,7 @@ public function testMergeExistingEntryWithNonExistingFallbackEntry($childData, $
}

/**
* @expectedException \Symfony\Component\Intl\Exception\NoSuchEntryException
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
*/
public function testFailIfEntryFoundNeitherInParentNorChild()
{
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.