Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Locale] IntlDateFormatter #63

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 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8051e9a
[Locale] refactored Locale class
eriksencosta Jan 25, 2011
2850851
[Locale] renamed and simplified Locale::isIntlExtensionAvailable()
Jan 25, 2011
4c1ce75
[Locale] added intl's \Locale constants to the Locale class
Jan 25, 2011
2333ee3
[Locale] added NumberFormatterInterface
eriksencosta Jan 25, 2011
8f17d18
[Locale] added NumberFormatter class
Jan 25, 2011
5a51450
[Locale] changed NumberFormatInterface::getLocale() to use Locale::AC…
Jan 25, 2011
6672c39
[Locale] added SimpleNumberFormatter class (not finished)
Jan 26, 2011
d245fb8
[Locale] partialy implemented \NumberFormatter's format() and formatC…
Jan 29, 2011
af499ee
[Locale] partial impl of \NumberFormatter::parse()
eriksencosta Jan 30, 2011
8b99817
[Locale] extracted method
Feb 2, 2011
75b55ca
[Locale] extract method refactoring
Feb 2, 2011
1b0c671
[Locale] method throws exception for unsupported argument value
Feb 2, 2011
b198a9e
[Locale] refactored test code
Feb 2, 2011
ff6083f
[Locale] removed support for ceil and floor rounding modes as them do…
Feb 2, 2011
353418e
[Locale] updated docblock
Feb 2, 2011
1559557
[Locale] added implementation to getErrorCode and getErrorMessage met…
Feb 2, 2011
33bb0c0
[Locale] not implemented methods throws RuntimeException
Feb 2, 2011
cceeefd
[Locale] Removed NumberFormatterInterface and NumberFormatter wrapper…
Feb 5, 2011
4f024e3
[Locale] moved and renamed SimpleNumberFormatter to StubNumberFormatter
Feb 5, 2011
0aaf7b6
[Locale] added learning tests for the \NumberFormatter class
Feb 5, 2011
59a0f72
[Locale] first implementation of StubIntlDateFormatter
igorw Feb 5, 2011
3da4307
[Locale] add support for escaping, give specifics on implementation u…
igorw Feb 6, 2011
09b24fa
[Locale] move intl bugs to skipped tests
igorw Feb 6, 2011
43794ba
[Locale] support for G and Q placeholders in StubIntlDateFormatter::f…
igorw Feb 6, 2011
af6fae6
[Locale] add support for L, which is the same as M
igorw Feb 6, 2011
a91c970
[Locale] use assertSame instead of assertEquals
igorw Feb 6, 2011
c1aa274
[Locale] add support for h
igorw Feb 6, 2011
fec50dc
[Locale] support for D (day of year)
igorw Feb 6, 2011
b7f42f0
[Locale] support for E (day of week)
igorw Feb 6, 2011
d3e24d6
[Locale] support for a (AM/PM)
igorw Feb 6, 2011
85d05c8
[Locale] support for H (24 hour)
igorw Feb 6, 2011
0396dab
[Locale] refactor IntlDateFormatter::format to build regExp dynamically
igorw Feb 6, 2011
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
276 changes: 274 additions & 2 deletions src/Symfony/Component/Locale/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,23 @@

namespace Symfony\Component\Locale;

class Locale extends \Locale
class Locale
{
const DEFAULT_LOCALE = null;

/** Locale method constants */
const ACTUAL_LOCALE = 0;
const VALID_LOCALE = 1;

/** Language tags constants */
const LANG_TAG = 'language';
const EXTLANG_TAG = 'extlang';
const SCRIPT_TAG = 'script';
const REGION_TAG = 'region';
const VARIANT_TAG = 'variant';
const GRANDFATHERED_LANG_TAG = 'grandfathered';
const PRIVATE_TAG = 'private';

/**
* Caches the countries in different locales
* @var array
Expand Down Expand Up @@ -164,4 +179,261 @@ public static function getLocales()
{
return array_keys(self::getDisplayLocales(self::getDefault()));
}
}

/**
* Returns the best available locale based on HTTP "Accept-Language" header according to RFC 2616
*
* @param string $header The string containing the "Accept-Language" header value
* @return string The corresponding locale code
* @see http://www.php.net/manual/en/locale.acceptfromhttp.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function acceptFromHttp($header)
{
self::assertIntlExtensionAvailability();
return \Locale::acceptFromHttp($header);
}

/**
* Returns a correctly ordered and delimited locale code
*
* @param array $subtags A keyed array where the keys identify the particular locale code subtag
* @return string The corresponding locale code
* @see http://www.php.net/manual/en/locale.composelocale.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function composeLocale(array $subtags)
{
self::assertIntlExtensionAvailability();
return \Locale::composeLocale($subtags);
}

/**
* Checks if a language tag filter matches with locale
*
* @param string $langtag The language tag to check
* @param string $locale The language range to check against
* @return string The corresponding locale code
* @see http://www.php.net/manual/en/locale.filtermatches.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function filterMatches($langtag, $locale, $canonicalize = false)
{
self::assertIntlExtensionAvailability();
return \Locale::filterMatches($langtag, $locale, $canonicalize);
}

/**
* Returns the variants for the input locale
*
* @param string $locale The locale to extract the variants from
* @return array The locale variants
* @see http://www.php.net/manual/en/locale.getallvariants.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function getAllVariants($locale)
{
self::assertIntlExtensionAvailability();
return \Locale::getAllVariants($locale);
}

/**
* Returns the default locale
*
* @return string The default locale code
* @see http://www.php.net/manual/en/locale.getdefault.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function getDefault()
{
self::assertIntlExtensionAvailability();
return \Locale::getDefault();
}

/**
* Returns the localized display name for the locale language
*
* @param string $locale The locale code to return the display language from
* @param string $inLocale Optional format locale code to use to display the language name
* @return string The localized language display name
* @see http://www.php.net/manual/en/locale.getdisplaylanguage.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function getDisplayLanguage($locale, $inLocale = null)
{
self::assertIntlExtensionAvailability();
return \Locale::getDisplayLanguage($locale, $inLocale);
}

/**
* Returns the localized display name for the locale
*
* @param string $locale The locale code to return the display locale name from
* @param string $inLocale Optional format locale code to use to display the locale name
* @return string The localized locale display name
* @see http://www.php.net/manual/en/locale.getdisplayname.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function getDisplayName($locale, $inLocale = null)
{
self::assertIntlExtensionAvailability();
return \Locale::getDisplayName($locale, $inLocale);
}

/**
* Returns the localized display name for the locale region
*
* @param string $locale The locale code to return the display region from
* @param string $inLocale Optional format locale code to use to display the region name
* @return string The localized region display name
* @see http://www.php.net/manual/en/locale.getdisplayregion.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function getDisplayRegion($locale, $inLocale = null)
{
self::assertIntlExtensionAvailability();
return \Locale::getDisplayRegion($locale, $inLocale);
}

/**
* Returns the localized display name for the locale script
*
* @param string $locale The locale code to return the display scrit from
* @param string $inLocale Optional format locale code to use to display the script name
* @return string The localized script display name
* @see http://www.php.net/manual/en/locale.getdisplayscript.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function getDisplayScript($locale, $inLocale = null)
{
self::assertIntlExtensionAvailability();
return \Locale::getDisplayScript($locale, $inLocale);
}

/**
* Returns the localized display name for the locale variant
*
* @param string $locale The locale code to return the display variant from
* @param string $inLocale Optional format locale code to use to display the variant name
* @return string The localized variant display name
* @see http://www.php.net/manual/en/locale.getdisplayvariant.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function getDisplayVariant($locale, $inLocale = null)
{
self::assertIntlExtensionAvailability();
return \Locale::getDisplayVariant($locale, $inLocale);
}

/**
* Returns the keywords for the locale
*
* @param string $locale The locale code to extract the keywords from
* @return array Associative array with the extracted variants
* @see http://www.php.net/manual/en/locale.getkeywords.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function getKeywords($locale)
{
self::assertIntlExtensionAvailability();
return \Locale::getKeywords($locale);
}

/**
* Returns the primary language for the locale
*
* @param string $locale The locale code to extract the language code from
* @return string|null The extracted language code or null in case of error
* @see http://www.php.net/manual/en/locale.getprimarylanguage.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function getPrimaryLanguage($locale)
{
self::assertIntlExtensionAvailability();
return \Locale::getPrimaryLanguage($locale);
}

/**
* Returns the region for the locale
*
* @param string $locale The locale code to extract the region code from
* @return string|null The extracted region code or null if not present
* @see http://www.php.net/manual/en/locale.getregion.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function getRegion($locale)
{
self::assertIntlExtensionAvailability();
return \Locale::getRegion($locale);
}

/**
* Returns the script for the locale
*
* @param string $locale The locale code to extract the script code from
* @return string|null The extracted script code or null if not present
* @see http://www.php.net/manual/en/locale.getscript.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function getScript($locale)
{
self::assertIntlExtensionAvailability();
return \Locale::getScript($locale);
}

/**
* Returns the closest language tag for the locale
*
* @param array $langtag A list of the language tags to compare to locale
* @param string $locale The locale to use as the language range when matching
* @param bool $canonicalize If true, the arguments will be converted to canonical form before matching
* @param string $default The locale to use if no match is found
* @see http://www.php.net/manual/en/locale.lookup.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function lookup(array $langtag, $locale, $canonicalize = false, $default = null)
{
self::assertIntlExtensionAvailability();
return \Locale::lookup($langtag, $locale, $canonicalize, $default);
}

/**
* Returns an associative array of locale identifier subtags
*
* @param string $locale The locale code to extract the subtag array from
* @return array Associative arrat with the extracted subtags
* @see http://www.php.net/manual/en/locale.parselocale.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function parseLocale($locale)
{
self::assertIntlExtensionAvailability();
return \Locale::parseLocale($locale);
}

/**
* Sets the default runtime locale
*
* @param string $locale The locale code
* @return bool true on success or false on failure
* @see http://www.php.net/manual/en/locale.parselocale.php
* @throws RuntimeException When the intl extension is not loaded
*/
public static function setDefault($locale)
{
self::assertIntlExtensionAvailability();
return \Locale::setDefault($locale);
}

/**
* Check if the intl extension is loaded.
*
* @throws RuntimeException When the intl extension is not loaded
*/
private static function assertIntlExtensionAvailability()
{
if (!extension_loaded('intl')) {
throw new \RuntimeException('The intl extension is not available.');
}
}
}
Loading