* @see $wgShellLocale
*/
function wfInitShellLocale() {
+ wfDeprecated( __FUNCTION__, '1.30' );
}
/**
* See unit test for examples.
* See mediawiki.language.bcp47 for the JavaScript implementation.
*
+ * @deprecated since 1.31, use LanguageCode::bcp47() directly.
+ *
* @param string $code The language code.
* @return string The language code which complying with BCP 47 standards.
*/
function wfBCP47( $code ) {
- $codeSegment = explode( '-', $code );
- $codeBCP = [];
- foreach ( $codeSegment as $segNo => $seg ) {
- // when previous segment is x, it is a private segment and should be lc
- if ( $segNo > 0 && strtolower( $codeSegment[( $segNo - 1 )] ) == 'x' ) {
- $codeBCP[$segNo] = strtolower( $seg );
- // ISO 3166 country code
- } elseif ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) {
- $codeBCP[$segNo] = strtoupper( $seg );
- // ISO 15924 script code
- } elseif ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) {
- $codeBCP[$segNo] = ucfirst( strtolower( $seg ) );
- // Use lowercase for other cases
- } else {
- $codeBCP[$segNo] = strtolower( $seg );
- }
- }
- $langCode = implode( '-', $codeBCP );
- return $langCode;
+ return LanguageCode::bcp47( $code );
}
/**
if ( !$this->mParserOptions ) {
if ( !$this->getContext()->getUser()->isSafeToLoad() ) {
- // $wgUser isn't loaded yet, so don't try to get a
+ // $wgUser isn't unstubbable yet, so don't try to get a
// ParserOptions for it. And don't cache this ParserOptions
// either.
$po = ParserOptions::newFromAnon();
// IE and some other browsers use BCP 47 standards in
// their Accept-Language header, like "zh-CN" or "zh-Hant".
// We should handle these too.
- $variantBCP47 = wfBCP47( $variant );
+ $variantBCP47 = LanguageCode::bcp47( $variant );
if ( $variantBCP47 !== $variant ) {
$aloption[] = 'substr=' . $variantBCP47;
}
foreach ( $variants as $variant ) {
$tags["variant-$variant"] = Html::element( 'link', [
'rel' => 'alternate',
- 'hreflang' => wfBCP47( $variant ),
+ 'hreflang' => LanguageCode::bcp47( $variant ),
'href' => $this->getTitle()->getLocalURL(
[ 'variant' => $variant ] )
]
*
* @param int|float $num
* @param string $raw
- * @param Language $language
+ * @param Language|StubUserLang $language
* @return string
*/
public static function formatRaw( $num, $raw, $language ) {
$code = strtolower( $code );
$inLanguage = strtolower( $inLanguage );
$lang = Language::fetchLanguageName( $code, $inLanguage );
- return $lang !== '' ? $lang : wfBCP47( $code );
+ return $lang !== '' ? $lang : LanguageCode::bcp47( $code );
}
/**