MediaWiki  master
MediaWiki\Languages\LanguageNameUtils Class Reference

A service that provides utilities to do with language names and codes. More...

Collaboration diagram for MediaWiki\Languages\LanguageNameUtils:

Public Member Functions

 __construct (ServiceOptions $options, HookContainer $hookContainer)
 
 getFileName ( $prefix, $code, $suffix='.php')
 Get the name of a file for a certain language code. More...
 
 getJsonMessagesFileName ( $code)
 
 getLanguageName ( $code, $inLanguage=self::AUTONYMS, $include=self::ALL)
 
 getLanguageNames ( $inLanguage=self::AUTONYMS, $include=self::DEFINED)
 Get an array of language names, indexed by code. More...
 
 getMessagesFileName ( $code)
 
 isKnownLanguageTag (string $tag)
 Returns true if a language code is an IETF tag known to MediaWiki. More...
 
 isSupportedLanguage (string $code)
 Checks whether any localisation is available for that language tag in MediaWiki (MessagesXx.php or xx.json exists). More...
 
 isValidBuiltInCode (string $code)
 Returns true if a language code is of a valid form for the purposes of internal customisation of MediaWiki, via Messages*.php or *.json. More...
 
 isValidCode (string $code)
 Returns true if a language code string is of a valid form, whether or not it exists. More...
 

Public Attributes

const ALL = 'all'
 Return all known languages in getLanguageName(s). More...
 
const AUTONYMS = null
 Return autonyms in getLanguageName(s). More...
 
const CONSTRUCTOR_OPTIONS
 
const DEFINED = 'mw'
 Return in getLanguageName(s) only the languages that are defined by MediaWiki. More...
 
const SUPPORTED = 'mwfile'
 Return in getLanguageName(s) only the languages for which we have at least some localisation. More...
 

Private Member Functions

 getLanguageNamesUncached ( $inLanguage, $include)
 Uncached helper for getLanguageNames. More...
 

Private Attributes

HookRunner $hookRunner
 
HashBagOStuff null $languageNameCache
 Cache for language names. More...
 
ServiceOptions $options
 
array $validCodeCache = []
 Cache for validity of language codes. More...
 

Detailed Description

A service that provides utilities to do with language names and codes.

See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more information.

Since
1.34

Definition at line 42 of file LanguageNameUtils.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Languages\LanguageNameUtils::__construct ( ServiceOptions  $options,
HookContainer  $hookContainer 
)
Parameters
ServiceOptions$options
HookContainer$hookContainer

Definition at line 93 of file LanguageNameUtils.php.

References MediaWiki\Languages\LanguageNameUtils\$options, and MediaWiki\Config\ServiceOptions\assertRequiredOptions().

Member Function Documentation

◆ getFileName()

MediaWiki\Languages\LanguageNameUtils::getFileName (   $prefix,
  $code,
  $suffix = '.php' 
)

Get the name of a file for a certain language code.

Parameters
string$prefixPrepend this to the filename
string$codeLanguage code
string$suffixAppend this to the filename
Exceptions
MWException
Returns
string $prefix . $mangledCode . $suffix

Definition at line 289 of file LanguageNameUtils.php.

References MediaWiki\Languages\LanguageNameUtils\isValidBuiltInCode().

Referenced by MediaWiki\Languages\LanguageNameUtils\getMessagesFileName().

◆ getJsonMessagesFileName()

MediaWiki\Languages\LanguageNameUtils::getJsonMessagesFileName (   $code)

◆ getLanguageName()

MediaWiki\Languages\LanguageNameUtils::getLanguageName (   $code,
  $inLanguage = self::AUTONYMS,
  $include = self::ALL 
)
Parameters
string$codeThe code of the language for which to get the name
null | string$inLanguageCode of language in which to return the name (self::AUTONYMS for autonyms)
string$includeSee getLanguageNames(), except this defaults to self::ALL instead of self::DEFINED
Returns
string Language name or empty
Since
1.20

Definition at line 275 of file LanguageNameUtils.php.

References MediaWiki\Languages\LanguageNameUtils\getLanguageNames().

Referenced by MediaWiki\Languages\LanguageNameUtils\isKnownLanguageTag().

◆ getLanguageNames()

MediaWiki\Languages\LanguageNameUtils::getLanguageNames (   $inLanguage = self::AUTONYMS,
  $include = self::DEFINED 
)

Get an array of language names, indexed by code.

Parameters
null | string$inLanguageCode of language in which to return the names Use self::AUTONYMS for autonyms (native names)
string$includeOne of: self::ALL all available languages self::DEFINED only if the language is defined in MediaWiki or wgExtraLanguageNames (default) self::SUPPORTED only if the language is in self::DEFINED and has a message file
Returns
array Language code => language name (sorted by key)

Definition at line 185 of file LanguageNameUtils.php.

References MediaWiki\Languages\LanguageNameUtils\getLanguageNamesUncached().

Referenced by MediaWiki\Languages\LanguageNameUtils\getLanguageName().

◆ getLanguageNamesUncached()

MediaWiki\Languages\LanguageNameUtils::getLanguageNamesUncached (   $inLanguage,
  $include 
)
private

Uncached helper for getLanguageNames.

Parameters
null | string$inLanguageAs getLanguageNames
string$includeAs getLanguageNames
Returns
array Language code => language name (sorted by key)

Definition at line 206 of file LanguageNameUtils.php.

References MediaWiki\Languages\Data\Names\$names, MediaWiki\Languages\LanguageNameUtils\getJsonMessagesFileName(), MediaWiki\Languages\LanguageNameUtils\getMessagesFileName(), and MediaWiki\Languages\LanguageNameUtils\isValidCode().

Referenced by MediaWiki\Languages\LanguageNameUtils\getLanguageNames().

◆ getMessagesFileName()

MediaWiki\Languages\LanguageNameUtils::getMessagesFileName (   $code)

◆ isKnownLanguageTag()

MediaWiki\Languages\LanguageNameUtils::isKnownLanguageTag ( string  $tag)

Returns true if a language code is an IETF tag known to MediaWiki.

Parameters
string$tag
Returns
bool

Definition at line 160 of file LanguageNameUtils.php.

References MediaWiki\Languages\LanguageNameUtils\getLanguageName(), and MediaWiki\Languages\LanguageNameUtils\isValidBuiltInCode().

◆ isSupportedLanguage()

MediaWiki\Languages\LanguageNameUtils::isSupportedLanguage ( string  $code)

Checks whether any localisation is available for that language tag in MediaWiki (MessagesXx.php or xx.json exists).

Parameters
string$codeLanguage tag (in lower case)
Returns
bool Whether language is supported

Definition at line 106 of file LanguageNameUtils.php.

References MediaWiki\Languages\LanguageNameUtils\getJsonMessagesFileName(), MediaWiki\Languages\LanguageNameUtils\getMessagesFileName(), and MediaWiki\Languages\LanguageNameUtils\isValidBuiltInCode().

◆ isValidBuiltInCode()

MediaWiki\Languages\LanguageNameUtils::isValidBuiltInCode ( string  $code)

Returns true if a language code is of a valid form for the purposes of internal customisation of MediaWiki, via Messages*.php or *.json.

Parameters
string$code
Returns
bool

Definition at line 149 of file LanguageNameUtils.php.

Referenced by MediaWiki\Languages\LanguageNameUtils\getFileName(), MediaWiki\Languages\LanguageNameUtils\getJsonMessagesFileName(), MediaWiki\Languages\LanguageNameUtils\isKnownLanguageTag(), and MediaWiki\Languages\LanguageNameUtils\isSupportedLanguage().

◆ isValidCode()

MediaWiki\Languages\LanguageNameUtils::isValidCode ( string  $code)

Returns true if a language code string is of a valid form, whether or not it exists.

This includes codes which are used solely for customisation via the MediaWiki namespace.

Parameters
string$code
Returns
bool False if the language code contains dangerous characters, e.g. HTML special characters or characters illegal in MediaWiki titles.

Definition at line 129 of file LanguageNameUtils.php.

References MediaWikiTitleCodec\getTitleInvalidRegex().

Referenced by MediaWiki\Languages\LanguageNameUtils\getLanguageNamesUncached().

Member Data Documentation

◆ $hookRunner

HookRunner MediaWiki\Languages\LanguageNameUtils::$hookRunner
private

Definition at line 87 of file LanguageNameUtils.php.

◆ $languageNameCache

HashBagOStuff null MediaWiki\Languages\LanguageNameUtils::$languageNameCache
private

Cache for language names.

Definition at line 70 of file LanguageNameUtils.php.

◆ $options

ServiceOptions MediaWiki\Languages\LanguageNameUtils::$options
private

◆ $validCodeCache

array MediaWiki\Languages\LanguageNameUtils::$validCodeCache = []
private

Cache for validity of language codes.

Definition at line 76 of file LanguageNameUtils.php.

◆ ALL

const MediaWiki\Languages\LanguageNameUtils::ALL = 'all'

Return all known languages in getLanguageName(s).

Definition at line 51 of file LanguageNameUtils.php.

◆ AUTONYMS

const MediaWiki\Languages\LanguageNameUtils::AUTONYMS = null

Return autonyms in getLanguageName(s).

Definition at line 46 of file LanguageNameUtils.php.

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\Languages\LanguageNameUtils::CONSTRUCTOR_OPTIONS
Initial value:
= [
'ExtraLanguageNames',
'UsePigLatinVariant',
]

Definition at line 81 of file LanguageNameUtils.php.

◆ DEFINED

const MediaWiki\Languages\LanguageNameUtils::DEFINED = 'mw'

Return in getLanguageName(s) only the languages that are defined by MediaWiki.

Definition at line 56 of file LanguageNameUtils.php.

◆ SUPPORTED

const MediaWiki\Languages\LanguageNameUtils::SUPPORTED = 'mwfile'

Return in getLanguageName(s) only the languages for which we have at least some localisation.

Definition at line 61 of file LanguageNameUtils.php.


The documentation for this class was generated from the following file: