4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Intl\Locale
;
14 use Symfony\Component\Intl\Exception\MethodNotImplementedException
;
17 * Replacement for PHP's native {@link \Locale} class.
19 * The only method supported in this class is {@link getDefault}. This method
20 * will always return "en". All other methods will throw an exception when used.
22 * @author Eriksen Costa <eriksen.costa@infranology.com.br>
23 * @author Bernhard Schussek <bschussek@gmail.com>
27 const DEFAULT_LOCALE
= null;
29 /* Locale method constants */
30 const ACTUAL_LOCALE
= 0;
31 const VALID_LOCALE
= 1;
33 /* Language tags constants */
34 const LANG_TAG
= 'language';
35 const EXTLANG_TAG
= 'extlang';
36 const SCRIPT_TAG
= 'script';
37 const REGION_TAG
= 'region';
38 const VARIANT_TAG
= 'variant';
39 const GRANDFATHERED_LANG_TAG
= 'grandfathered';
40 const PRIVATE_TAG
= 'private';
43 * Not supported. Returns the best available locale based on HTTP "Accept-Language" header according to RFC 2616
45 * @param string $header The string containing the "Accept-Language" header value
47 * @return string The corresponding locale code
49 * @see http://www.php.net/manual/en/locale.acceptfromhttp.php
51 * @throws MethodNotImplementedException
53 public static function acceptFromHttp($header)
55 throw new MethodNotImplementedException(__METHOD__
);
59 * Not supported. Returns a correctly ordered and delimited locale code
61 * @param array $subtags A keyed array where the keys identify the particular locale code subtag
63 * @return string The corresponding locale code
65 * @see http://www.php.net/manual/en/locale.composelocale.php
67 * @throws MethodNotImplementedException
69 public static function composeLocale(array $subtags)
71 throw new MethodNotImplementedException(__METHOD__
);
75 * Not supported. Checks if a language tag filter matches with locale
77 * @param string $langtag The language tag to check
78 * @param string $locale The language range to check against
79 * @param Boolean $canonicalize
81 * @return string The corresponding locale code
83 * @see http://www.php.net/manual/en/locale.filtermatches.php
85 * @throws MethodNotImplementedException
87 public static function filterMatches($langtag, $locale, $canonicalize = false)
89 throw new MethodNotImplementedException(__METHOD__
);
93 * Not supported. Returns the variants for the input locale
95 * @param string $locale The locale to extract the variants from
97 * @return array The locale variants
99 * @see http://www.php.net/manual/en/locale.getallvariants.php
101 * @throws MethodNotImplementedException
103 public static function getAllVariants($locale)
105 throw new MethodNotImplementedException(__METHOD__
);
109 * Returns the default locale
111 * @return string The default locale code. Always returns 'en'
113 * @see http://www.php.net/manual/en/locale.getdefault.php
115 public static function getDefault()
121 * Not supported. Returns the localized display name for the locale language
123 * @param string $locale The locale code to return the display language from
124 * @param string $inLocale Optional format locale code to use to display the language name
126 * @return string The localized language display name
128 * @see http://www.php.net/manual/en/locale.getdisplaylanguage.php
130 * @throws MethodNotImplementedException
132 public static function getDisplayLanguage($locale, $inLocale = null)
134 throw new MethodNotImplementedException(__METHOD__
);
138 * Not supported. Returns the localized display name for the locale
140 * @param string $locale The locale code to return the display locale name from
141 * @param string $inLocale Optional format locale code to use to display the locale name
143 * @return string The localized locale display name
145 * @see http://www.php.net/manual/en/locale.getdisplayname.php
147 * @throws MethodNotImplementedException
149 public static function getDisplayName($locale, $inLocale = null)
151 throw new MethodNotImplementedException(__METHOD__
);
155 * Not supported. Returns the localized display name for the locale region
157 * @param string $locale The locale code to return the display region from
158 * @param string $inLocale Optional format locale code to use to display the region name
160 * @return string The localized region display name
162 * @see http://www.php.net/manual/en/locale.getdisplayregion.php
164 * @throws MethodNotImplementedException
166 public static function getDisplayRegion($locale, $inLocale = null)
168 throw new MethodNotImplementedException(__METHOD__
);
172 * Not supported. Returns the localized display name for the locale script
174 * @param string $locale The locale code to return the display script from
175 * @param string $inLocale Optional format locale code to use to display the script name
177 * @return string The localized script display name
179 * @see http://www.php.net/manual/en/locale.getdisplayscript.php
181 * @throws MethodNotImplementedException
183 public static function getDisplayScript($locale, $inLocale = null)
185 throw new MethodNotImplementedException(__METHOD__
);
189 * Not supported. Returns the localized display name for the locale variant
191 * @param string $locale The locale code to return the display variant from
192 * @param string $inLocale Optional format locale code to use to display the variant name
194 * @return string The localized variant display name
196 * @see http://www.php.net/manual/en/locale.getdisplayvariant.php
198 * @throws MethodNotImplementedException
200 public static function getDisplayVariant($locale, $inLocale = null)
202 throw new MethodNotImplementedException(__METHOD__
);
206 * Not supported. Returns the keywords for the locale
208 * @param string $locale The locale code to extract the keywords from
210 * @return array Associative array with the extracted variants
212 * @see http://www.php.net/manual/en/locale.getkeywords.php
214 * @throws MethodNotImplementedException
216 public static function getKeywords($locale)
218 throw new MethodNotImplementedException(__METHOD__
);
222 * Not supported. Returns the primary language for the locale
224 * @param string $locale The locale code to extract the language code from
226 * @return string|null The extracted language code or null in case of error
228 * @see http://www.php.net/manual/en/locale.getprimarylanguage.php
230 * @throws MethodNotImplementedException
232 public static function getPrimaryLanguage($locale)
234 throw new MethodNotImplementedException(__METHOD__
);
238 * Not supported. Returns the region for the locale
240 * @param string $locale The locale code to extract the region code from
242 * @return string|null The extracted region code or null if not present
244 * @see http://www.php.net/manual/en/locale.getregion.php
246 * @throws MethodNotImplementedException
248 public static function getRegion($locale)
250 throw new MethodNotImplementedException(__METHOD__
);
254 * Not supported. Returns the script for the locale
256 * @param string $locale The locale code to extract the script code from
258 * @return string|null The extracted script code or null if not present
260 * @see http://www.php.net/manual/en/locale.getscript.php
262 * @throws MethodNotImplementedException
264 public static function getScript($locale)
266 throw new MethodNotImplementedException(__METHOD__
);
270 * Not supported. Returns the closest language tag for the locale
272 * @param array $langtag A list of the language tags to compare to locale
273 * @param string $locale The locale to use as the language range when matching
274 * @param Boolean $canonicalize If true, the arguments will be converted to canonical form before matching
275 * @param string $default The locale to use if no match is found
277 * @see http://www.php.net/manual/en/locale.lookup.php
279 * @throws MethodNotImplementedException
281 public static function lookup(array $langtag, $locale, $canonicalize = false, $default = null)
283 throw new MethodNotImplementedException(__METHOD__
);
287 * Not supported. Returns an associative array of locale identifier subtags
289 * @param string $locale The locale code to extract the subtag array from
291 * @return array Associative array with the extracted subtags
293 * @see http://www.php.net/manual/en/locale.parselocale.php
295 * @throws MethodNotImplementedException
297 public static function parseLocale($locale)
299 throw new MethodNotImplementedException(__METHOD__
);
303 * Not supported. Sets the default runtime locale
305 * @param string $locale The locale code
307 * @return Boolean true on success or false on failure
309 * @see http://www.php.net/manual/en/locale.parselocale.php
311 * @throws MethodNotImplementedException
313 public static function setDefault($locale)
315 throw new MethodNotImplementedException(__METHOD__
);