MediaWiki master
MediaWiki\Language\Language Class Reference

Base class for language-specific code. More...

Inherits Bcp47Code.

Inherited by LanguageAr, LanguageAz, LanguageBe_tarask, LanguageBs, LanguageCu, LanguageDsb, LanguageEn, LanguageFi, LanguageGa, LanguageHsb, LanguageHu, LanguageHy, LanguageJa, LanguageKaa, LanguageKk_cyrl, LanguageKm, LanguageKsh, LanguageLa, LanguageMl, LanguageMy, LanguageOs, LanguageQqx, LanguageSl, LanguageTr, LanguageTyv, LanguageWa, LanguageYue, and LanguageZh_hans.

Collaboration diagram for MediaWiki\Language\Language:

Public Member Functions

 __construct ( $code=null, ?NamespaceInfo $namespaceInfo=null, ?LocalisationCache $localisationCache=null, ?LanguageNameUtils $langNameUtils=null, ?LanguageFallback $langFallback=null, ?LanguageConverterFactory $converterFactory=null, ?HookContainer $hookContainer=null, ?Config $config=null)
 
 alignEnd ()
 Return 'right' or 'left' as appropriate alignment for line-end for this language's text direction.
 
 alignStart ()
 Return 'left' or 'right' as appropriate alignment for line-start for this language's text direction.
 
 caseFold ( $s)
 Return a case-folded representation of $s.
 
 checkTitleEncoding (string $s)
 
 commaList (array $list)
 Take a list of strings and build a locale-friendly comma-separated list, using the local comma-separator message.
 
 convertForSearchResult ( $termsArray)
 
 convertGrammar ( $word, $case)
 Grammatical transformations, needed for inflected languages Invoked by putting {{grammar:case|word}} in a message.
 
 convertPlural ( $count, $forms)
 Plural form transformations, needed for some languages.
 
 date ( $ts, $adj=false, $format=true, $timecorrection=false)
 
 dateFormat ( $usePrefs=true)
 This is meant to be used by time(), date(), and timeanddate() to get the date preference they're supposed to use.
 
 digitGroupingPattern ()
 
 digitTransformTable ()
 
 embedBidi ( $text='')
 Wraps argument with unicode control characters for directionality safety.
 
 emphasize ( $text)
 Italic is unsuitable for some languages.
 
 equals (Language $lang)
 Compare with another language object.
 
 fallback8bitEncoding ()
 
 firstChar ( $s)
 Get the first character of a string.
 
 formatBitrate ( $bps)
 Format a bitrate for output, using an appropriate unit (bps, kbps, Mbps, Gbps, Tbps, Pbps, Ebps, Zbps, Ybps, Rbps or Qbps) according to the magnitude in question.
 
 formatComputingNumbers ( $size, $boundary, $messageKey)
 
 formatDuration ( $seconds, array $chosenIntervals=[])
 Takes a number of seconds and turns it into a text using values such as hours and minutes.
 
 formatDurationBetweenTimestamps (int $timestamp1, int $timestamp2, ?int $precision=null)
 Takes two timestamps and turns the difference between them into a text using values such as hours and minutes.
 
 formatExpiry ( $expiry, $format=true, $infinity='infinity', $user=null)
 Decode an expiry (block, protection, etc.) which has come from the DB.
 
 formatNum ( $number)
 Normally we output all numbers in plain en_US style, that is 293,291.235 for two hundred ninety-three thousand two hundred ninety-one point two hundred thirty-five.
 
 formatNumNoSeparators ( $number)
 Front-end for non-commafied formatNum.
 
 formatSize ( $size)
 Format a size in bytes for output, using an appropriate unit (B, KB, MB, GB, TB, PB, EB, ZB, YB, RB or QB) according to the magnitude in question.
 
 formatTimePeriod ( $seconds, $format=[])
 Formats a time given in seconds into a string representation of that time.
 
 gender ( $gender, $forms)
 Provides an alternative text depending on specified gender.
 
 getAllMessages ()
 
 getArrow ( $direction='forwards')
 An arrow, depending on the language direction.
 
 getBlockDurations ( $includeOther=true)
 Get an array of suggested block durations from MediaWiki:Ipboptions.
 
 getBookstoreList ()
 Exports $wgBookstoreListEn.
 
 getCode ()
 Get the internal language code for this language object.
 
 getCompiledPluralRules ()
 Get the compiled plural rules for the language.
 
 getDateFormats ()
 
 getDateFormatString ( $type, $pref)
 Get a format string for a given type and preference.
 
 getDatePreferenceMigrationMap ()
 
 getDatePreferences ()
 
 getDefaultDateFormat ()
 
 getDir ()
 Return the correct HTML 'dir' attribute value for this language.
 
 getDirMark ( $opposite=false)
 A hidden direction mark (LRM or RLM), depending on the language direction.
 
 getDirMarkEntity ( $opposite=false)
 A hidden direction mark (LRM or RLM), depending on the language direction.
 
 getDurationIntervals ( $seconds, array $chosenIntervals=[])
 Takes a number of seconds and returns an array with a set of corresponding intervals.
 
 getFallbackLanguages ()
 
 getFormalityIndex ()
 Some languages provide translations in different levels of formality (or manner of address), for example using the T-V distinction.
 
 getFormattedNamespaces ()
 A convenience function that returns getNamespaces() with spaces instead of underscores in values.
 
 getFormattedNsText ( $index)
 A convenience function that returns the same thing as getNsText() except with '_' changed to ' ', useful for producing output.
 
 getGenderNsText ( $index, $gender)
 Returns gender-dependent namespace alias if available.
 
 getGrammarForms ()
 Get the grammar forms for the content language.
 
 getGrammarTransformations ()
 Get the grammar transformations data for the language.
 
 getGroupMemberName (string $group, $member)
 Gets the localized name for a member of a user group if it exists.
 
 getGroupName ( $group)
 Gets the localized friendly name for a group, if it exists.
 
 getHtmlCode ()
 Get the code in BCP 47 format which we can use inside html lang="" tags.
 
 getHumanTimestamp (MWTimestamp $time, ?MWTimestamp $relativeTo=null, ?UserIdentity $user=null)
 Get the timestamp in a human-friendly relative format, e.g., "3 days ago".
 
 getJsData ()
 
 getLocalNsIndex ( $text)
 Get a namespace key by case-insensitive value.
 
 getMagic ( $mw)
 Fill a MagicWord object with data from this instance.
 
 getMagicWords ()
 Get all the magic words from the localisation cache.
 
 getMessage ( $key)
 
 getMessageFromDB ( $msg)
 Get a message from the MediaWiki namespace.
 
 getMonthAbbreviation ( $key)
 
 getMonthAbbreviationsArray ()
 
 getMonthName ( $key)
 
 getMonthNameGen ( $key)
 
 getMonthNamesArray ()
 
 getNamespaceAliases ()
 
 getNamespaceIds ()
 
 getNamespaces ()
 Returns an array of localised namespaces indexed by their numbers.
 
 getNsIndex ( $text)
 Get a namespace key by case-insensitive value.
 
 getNsText ( $index)
 Get a namespace value by key.
 
 getPluralRuleIndexNumber ( $number)
 Find the index number of the plural rule appropriate for the given number.
 
 getPluralRules ()
 Get the plural rules for the language.
 
 getPluralRuleType ( $number)
 Find the plural rule type appropriate for the given number.
 
 getPluralRuleTypes ()
 Get the plural rule types for the language.
 
 getSpecialPageAliases ()
 Get special page names, as an associative array canonical name => array of valid names, including aliases.
 
 getVariantname ( $code, $usemsg=true)
 Short names for language variants used for language conversion links.
 
 getWeekdayAbbreviation ( $key)
 
 getWeekdayName ( $key)
 
 hasWordBreaks ()
 Most writing systems use whitespace to break up words.
 
 iconv ( $in, $out, $string)
 
 isRTL ()
 For right-to-left language support.
 
 isSameCodeAs (Bcp47Code $other)
 Compare this Language object to a Bcp47Code.
 
 lc ( $str, $first=false)
 
 lcfirst ( $str)
 
 linkPrefixCharset ()
 A regular expression character set to match legal word-prefixing characters which should be merged onto a link of the form foo[[bar]].
 
 linkPrefixExtension ()
 To allow "foo[[bar]]" to extend the link over the whole word "foobar".
 
 linkTrail ()
 A regular expression to match legal word-trailing characters which should be merged onto a link of the form [[foo]]bar.
 
 listToText (array $list)
 Take a list of strings and build a locale-friendly comma-separated list, using the local comma-separator message.
 
 minimumGroupingDigits ()
 The minimum number of digits a number must have, in addition to the grouping size, before grouping separators are added.
 
 needsGenderDistinction ()
 Whether this language uses gender-dependent namespace aliases.
 
 normalize ( $s)
 Convert a UTF-8 string to normal form C.
 
 normalizeForSearch ( $text)
 Some languages have special punctuation need to be normalized.
 
 parseFormattedNumber ( $number)
 
 pipeList (array $list)
 Same as commaList, but separate it with the pipe instead.
 
 resetNamespaces ()
 Resets all the namespace caches.
 
 segmentByWord ( $string)
 Some languages such as Chinese require word segmentation, Specify such segmentation when overridden in derived class.
 
 segmentForDiff ( $text)
 Languages like Chinese need to be segmented in order for the diff to be of any use.
 
 semicolonList (array $list)
 Take a list of strings and build a locale-friendly semicolon-separated list, using the local semicolon-separator message.
 
 separatorTransformTable ()
 
 setNamespaces (array $namespaces)
 Arbitrarily set all the namespace names at once.
 
 specialList ( $page, $details)
 Make a list item, used by various special pages.
 
 sprintfDate ( $format, $ts, ?DateTimeZone $zone=null, &$ttl='unused')
 This is a workalike of PHP's date() function, but with better internationalisation, a reduced set of format characters, and a better escaping format.
 
 time ( $ts, $adj=false, $format=true, $timecorrection=false)
 
 timeanddate ( $ts, $adj=false, $format=true, $timecorrection=false)
 
 toBcp47Code ()
 Implement the Bcp47Code interface.
 
 translateBlockExpiry ( $str, ?UserIdentity $user=null, $now=0)
 
 truncateForDatabase ( $string, $length, $ellipsis='...', $adjustLength=true)
 Truncate a string to a specified length in bytes, appending an optional string (e.g., for ellipsis) When an ellipsis isn't needed, using mb_strcut() directly is recommended.
 
 truncateForVisual ( $string, $length, $ellipsis='...', $adjustLength=true)
 Truncate a string to a specified number of characters, appending an optional string (e.g., for ellipsis).
 
 truncateHtml ( $text, $length, $ellipsis='...')
 Truncate a string of valid HTML to a specified length in bytes, appending an optional string (e.g., for ellipses), and return valid HTML.
 
 uc ( $str, $first=false)
 
 ucfirst ( $str)
 
 ucwordbreaks ( $str)
 capitalize words at word breaks
 
 ucwords ( $str)
 
 unsegmentForDiff ( $text)
 And unsegment to show the result.
 
 userAdjust ( $ts, $tz=false)
 Used by date() and time() to adjust the time output.
 
 userDate ( $ts, UserIdentity $user, array $options=[])
 Get the formatted date for the given timestamp and formatted for the given user.
 
 userTime ( $ts, UserIdentity $user, array $options=[])
 Get the formatted time for the given timestamp and formatted for the given user.
 
 userTimeAndDate ( $ts, UserIdentity $user, array $options=[])
 Get the formatted date and time for the given timestamp and formatted for the given user.
 

Static Public Member Functions

static getCodeFromFileName ( $filename, $prefix='Language', $suffix='.php')
 Get the language code from a file name.
 
static hebrewNumeral ( $num)
 Hebrew Gematria number formatting up to 9999.
 
static romanNumeral ( $num)
 Roman number formatting up to 10000.
 

Public Attributes

string[][] $dateFormatStrings = []
 memoize
 
string $mCode
 
string[][] null $mExtendedSpecialPageAliases
 memoize
 
 $mMagicExtensions = []
 
const HEBREW_CALENDAR_MONTH_GENITIVE_MESSAGES
 
const HEBREW_CALENDAR_MONTHS_MESSAGES
 
const HIJRI_CALENDAR_MONTH_MESSAGES
 
const IRANIAN_CALENDAR_MONTHS_MESSAGES
 
const MONTH_ABBREVIATED_MESSAGES
 
const MONTH_GENITIVE_MESSAGES
 
const MONTH_MESSAGES
 
const WEEKDAY_ABBREVIATED_MESSAGES
 
const WEEKDAY_MESSAGES
 

Static Public Attributes

static int[] $durationIntervals = self::DURATION_INTERVALS
 
static $mMonthAbbrevMsgs = self::MONTH_ABBREVIATED_MESSAGES
 
static $mMonthMsgs = self::MONTH_MESSAGES
 

Protected Member Functions

 getConverterInternal ()
 Return the LanguageConverter for this language, convenience function for use in the language classes only.
 
 getHookContainer ()
 Get a HookContainer, for hook metadata and running extension hooks.
 
 getHookRunner ()
 Get a HookRunner, for running core hooks.
 
 getSearchIndexVariant ()
 Specify the language variant that should be used for search indexing.
 
 handleExplicitPluralForms ( $count, array $forms)
 Handles explicit plural forms for Language::convertPlural()
 
 msg ( $msg,... $params)
 Gets the Message object from this language.
 
 preConvertPlural ($forms, $count)
 Checks that convertPlural was given an array and pads it to requested number of forms by copying the last one.
 
 removeBadCharLast ( $string)
 Remove bytes that represent an incomplete Unicode character at the end of string (e.g.
 
 transformUsingPairFile (string $dataClass, string $input)
 Transform a string using serialized data stored in the given file (which must be in the serialized subdirectory of $IP).
 

Static Protected Member Functions

static convertDoubleWidth ( $string)
 Convert double-width roman characters to single-width.
 
static insertSpace ( $string, $pattern)
 

Protected Attributes

array< string, int > null $mNamespaceIds
 Indexed by localized lower-cased namespace name.
 
array< string, int > null $namespaceAliases
 Map from alias to namespace ID.
 
array< int, string > null $namespaceNames
 Indexed by numeric namespace ID.
 
const DURATION_INTERVALS
 

Detailed Description

Base class for language-specific code.

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

Definition at line 80 of file Language.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Language\Language::__construct ( $code = null,
?NamespaceInfo $namespaceInfo = null,
?LocalisationCache $localisationCache = null,
?LanguageNameUtils $langNameUtils = null,
?LanguageFallback $langFallback = null,
?LanguageConverterFactory $converterFactory = null,
?HookContainer $hookContainer = null,
?Config $config = null )
Access: internal
Calling this directly is deprecated. Use LanguageFactory instead.
Parameters
string | null$codeWhich code to use. Passing null is deprecated in 1.35, hard-deprecated since 1.43.
NamespaceInfo | null$namespaceInfo
LocalisationCache | null$localisationCache
LanguageNameUtils | null$langNameUtils
LanguageFallback | null$langFallback
LanguageConverterFactory | null$converterFactory
HookContainer | null$hookContainer
Config | null$config

Definition at line 337 of file Language.php.

References MediaWiki\MediaWikiServices\getInstance(), and wfDeprecatedMsg().

Member Function Documentation

◆ alignEnd()

MediaWiki\Language\Language::alignEnd ( )

Return 'right' or 'left' as appropriate alignment for line-end for this language's text direction.

Should be equivalent to CSS3 'end' text-align value....

Returns
string

Definition at line 2982 of file Language.php.

◆ alignStart()

MediaWiki\Language\Language::alignStart ( )

Return 'left' or 'right' as appropriate alignment for line-start for this language's text direction.

Should be equivalent to CSS3 'start' text-align value....

Returns
string

Definition at line 2970 of file Language.php.

◆ caseFold()

MediaWiki\Language\Language::caseFold ( $s)

Return a case-folded representation of $s.

This is a representation such that caseFold($s1) == caseFold($s2) if $s1 and $s2 are the same except for the case of their characters. It is not necessary for the value returned to make sense when displayed.

Do not perform any other normalisation in this function. If a caller uses this function when it should be using a more general normalisation function, then fix the caller.

Parameters
string$s
Returns
string

Definition at line 2745 of file Language.php.

◆ checkTitleEncoding()

MediaWiki\Language\Language::checkTitleEncoding ( string $s)
Parameters
string$s
Returns
string

Definition at line 2753 of file Language.php.

◆ commaList()

MediaWiki\Language\Language::commaList ( array $list)

Take a list of strings and build a locale-friendly comma-separated list, using the local comma-separator message.

Parameters
string[]$listArray of strings to put in a comma list
Returns
string

Definition at line 3406 of file Language.php.

Referenced by BlockLogFormatter\formatBlockFlags().

◆ convertDoubleWidth()

static MediaWiki\Language\Language::convertDoubleWidth ( $string)
staticprotected

Convert double-width roman characters to single-width.

range: ff00-ff5f ~= 0020-007f

Parameters
string$string
Returns
string

Definition at line 2826 of file Language.php.

Referenced by LanguageZh\convertForSearchResult().

◆ convertForSearchResult()

MediaWiki\Language\Language::convertForSearchResult ( $termsArray)
Parameters
string[]$termsArray
Returns
string[]

Reimplemented in LanguageZh.

Definition at line 2850 of file Language.php.

◆ convertGrammar()

MediaWiki\Language\Language::convertGrammar ( $word,
$case )

Grammatical transformations, needed for inflected languages Invoked by putting {{grammar:case|word}} in a message.

Parameters
string$word
string$case
Returns
string

Reimplemented in LanguageBs, LanguageCu, LanguageDsb, LanguageFi, LanguageGa, LanguageHsb, LanguageHu, LanguageHy, LanguageKaa, LanguageKk, LanguageKsh, LanguageLa, LanguageOs, LanguageSl, and LanguageTyv.

Definition at line 3764 of file Language.php.

References wfLogWarning().

◆ convertPlural()

MediaWiki\Language\Language::convertPlural ( $count,
$forms )

Plural form transformations, needed for some languages.

For example, there are 3 forms of plural in Russian and Polish, depending on "count mod 10". See [[w:Plural]] For English it is pretty simple.

Invoked by putting {{plural:count|wordform1|wordform2}} or {{plural:count|wordform1|wordform2|wordform3}}

Example: {{plural:{{NUMBEROFARTICLES}}|article|articles}}

Parameters
int$countNon-localized number
array$formsDifferent plural forms
Returns
string Correct form of plural for $count in this language

Reimplemented in LanguageKsh.

Definition at line 3901 of file Language.php.

◆ date()

MediaWiki\Language\Language::date ( $ts,
$adj = false,
$format = true,
$timecorrection = false )
Parameters
string$tsThe time format which needs to be turned into a date('YmdHis') format with wfTimestamp(TS_MW,$ts)
bool$adjWhether to adjust the time output according to the user configured offset ($timecorrection)
mixed$formatTrue to use user's date format preference
string | false$timecorrectionThe time offset as returned by validateTimeZone() in Special:Preferences
Returns
string

Reimplemented in LanguageWa.

Definition at line 2098 of file Language.php.

References wfTimestamp().

Referenced by LanguageFi\translateBlockExpiry().

◆ dateFormat()

MediaWiki\Language\Language::dateFormat ( $usePrefs = true)

This is meant to be used by time(), date(), and timeanddate() to get the date preference they're supposed to use.

It should be used in all children.

function timeanddate([...], $format = true) {
  $datePreference = $this->dateFormat($format);
  [...]
}
Parameters
int | string | bool$usePrefsIf true, the user's preference is used if false, the site/language default is used if int/string, assumed to be a format.
Returns
string

Definition at line 2030 of file Language.php.

References MediaWiki\User\Options\UserOptionsLookup\getDefaultOption().

Referenced by LanguageWa\date(), and LanguageWa\timeanddate().

◆ digitGroupingPattern()

MediaWiki\Language\Language::digitGroupingPattern ( )
Returns
string

Definition at line 3339 of file Language.php.

◆ digitTransformTable()

MediaWiki\Language\Language::digitTransformTable ( )
Returns
string[]

Definition at line 3346 of file Language.php.

◆ embedBidi()

MediaWiki\Language\Language::embedBidi ( $text = '')

Wraps argument with unicode control characters for directionality safety.

This solves the problem where directionality-neutral characters at the edge of the argument string get interpreted with the wrong directionality from the enclosing context, giving renderings that look corrupted like "(Ben_(WMF".

The wrapping is LRE...PDF or RLE...PDF, depending on the detected directionality of the argument string, using the BIDI algorithm's own "First strong directional codepoint" rule. Essentially, this works round the fact that there is no embedding equivalent of U+2068 FSI (isolation with heuristic direction inference). The latter is cleaner but still not widely supported.

Use of hidden control characters when the output allows use of HTML markup is discouraged and the recommendation is to use bdi HTML tag which doesn't have the issue of hidden characters ending up in user clipboard in text copy paste, see T375975.

Deprecated
since 1.43, use bdi HTML tag in HTML context where possible.
Parameters
string$textText to wrap
Returns
string Text, wrapped in LRE...PDF or RLE...PDF or nothing

Definition at line 3992 of file Language.php.

◆ emphasize()

MediaWiki\Language\Language::emphasize ( $text)

Italic is unsuitable for some languages.

Parameters
string$textThe text to be emphasized.
Returns
string

Reimplemented in LanguageJa.

Definition at line 3113 of file Language.php.

◆ equals()

MediaWiki\Language\Language::equals ( Language $lang)

Compare with another language object.

Since
1.28
Parameters
Language$lang
Returns
bool

Definition at line 4129 of file Language.php.

References MediaWiki\Language\Language\getCode().

◆ fallback8bitEncoding()

MediaWiki\Language\Language::fallback8bitEncoding ( )
Returns
string

Definition at line 2764 of file Language.php.

◆ firstChar()

MediaWiki\Language\Language::firstChar ( $s)

Get the first character of a string.

Parameters
string$s
Returns
string

Definition at line 2862 of file Language.php.

◆ formatBitrate()

MediaWiki\Language\Language::formatBitrate ( $bps)

Format a bitrate for output, using an appropriate unit (bps, kbps, Mbps, Gbps, Tbps, Pbps, Ebps, Zbps, Ybps, Rbps or Qbps) according to the magnitude in question.

This use base 1000. For base 1024 use formatSize(), for another base see formatComputingNumbers().

Parameters
int$bps
Returns
string

Definition at line 4383 of file Language.php.

◆ formatComputingNumbers()

MediaWiki\Language\Language::formatComputingNumbers ( $size,
$boundary,
$messageKey )
Parameters
int$sizeSize of the unit
int$boundarySize boundary (1000, or 1024 in most cases)
string$messageKeyMessage key to be used
Returns
string

Definition at line 4396 of file Language.php.

◆ formatDuration()

MediaWiki\Language\Language::formatDuration ( $seconds,
array $chosenIntervals = [] )

Takes a number of seconds and turns it into a text using values such as hours and minutes.

Since
1.20
Parameters
int$secondsThe number of seconds.
array$chosenIntervalsThe intervals to enable.
Returns
string

Reimplemented in LanguageZh_hans.

Definition at line 2156 of file Language.php.

◆ formatDurationBetweenTimestamps()

MediaWiki\Language\Language::formatDurationBetweenTimestamps ( int $timestamp1,
int $timestamp2,
?int $precision = null )

Takes two timestamps and turns the difference between them into a text using values such as hours and minutes.

Parameters
int$timestamp1The first timestamp.
int$timestamp2The second timestamp.
?int$precisionThe number of intervals to show.
Returns
string

Definition at line 2180 of file Language.php.

◆ formatExpiry()

MediaWiki\Language\Language::formatExpiry ( $expiry,
$format = true,
$infinity = 'infinity',
$user = null )

Decode an expiry (block, protection, etc.) which has come from the DB.

Parameters
string$expiryDatabase expiry String
true | int$formatTrue to process using language functions, or TS_ constant to return the expiry in a given timestamp
string$infinityIf $format is not true, use this string for infinite expiry
UserIdentity | null$userIf $format is true, use this user for date format
Returns
string
Since
1.18
1.36 $user was added

Definition at line 4246 of file Language.php.

References wfTimestamp().

◆ formatNum()

MediaWiki\Language\Language::formatNum ( $number)

Normally we output all numbers in plain en_US style, that is 293,291.235 for two hundred ninety-three thousand two hundred ninety-one point two hundred thirty-five.

However, this is not suitable for all languages, some such as Bengali (bn) want ২,৯৩,২৯১.২৩৫ and others such as Icelandic just want to use commas instead of dots, and dots instead of commas like "293.291,235".

An example of this function being called: wfMessage( 'message' )->numParams( $num )->text()

See $separatorTransformTable on MessageIs.php for the , => . and . => , implementation.

Parameters
string | int | float$numberExpected to be a pre-formatted (e.g. leading zeros, number of decimal places) numeric string. Any non-string will be cast to string.
Returns
string

Reimplemented in LanguageKm, and LanguageMy.

Definition at line 3137 of file Language.php.

◆ formatNumNoSeparators()

MediaWiki\Language\Language::formatNumNoSeparators ( $number)

Front-end for non-commafied formatNum.

Parameters
string | int | float$numberThe string to be formatted, should be an integer or a floating point number.
Since
1.21
Returns
string

Definition at line 3298 of file Language.php.

Referenced by LanguageKm\formatNum(), and LanguageMy\formatNum().

◆ formatSize()

MediaWiki\Language\Language::formatSize ( $size)

Format a size in bytes for output, using an appropriate unit (B, KB, MB, GB, TB, PB, EB, ZB, YB, RB or QB) according to the magnitude in question.

This method use base 1024. For base 1000 use formatBitrate(), for another base see formatComputingNumbers()

Parameters
int$sizeSize to format
Returns
string Plain text (not HTML)

Definition at line 4434 of file Language.php.

◆ formatTimePeriod()

MediaWiki\Language\Language::formatTimePeriod ( $seconds,
$format = [] )

Formats a time given in seconds into a string representation of that time.

Parameters
int | float$seconds
array$formatAn optional argument that formats the returned string in different ways: If $format['avoid'] === 'avoidhours': don't show hours, just show days If $format['avoid'] === 'avoidseconds': don't show seconds if $seconds >= 1 hour, If $format['avoid'] === 'avoidminutes': don't show seconds/minutes if $seconds > 48 hours, If $format['noabbrevs'] is true: use 'seconds' and friends instead of 'seconds-abbrev' and friends.
Note
For backwards compatibility, $format may also be one of the strings 'avoidseconds' or 'avoidminutes'.
Returns
string

Definition at line 4280 of file Language.php.

◆ gender()

MediaWiki\Language\Language::gender ( $gender,
$forms )

Provides an alternative text depending on specified gender.

Usage {{gender:username|masculine|feminine|unknown}}. username is optional, in which case the gender of the current user is used, but only in (some) interface messages; otherwise the default gender is used.

If no forms are given, an empty string is returned. If only one form is given, it will be returned unconditionally. These details are implied by the caller and cannot be overridden in subclasses.

If three forms are given, the default is to use the third (unknown) form. If fewer than three forms are given, the default is to use the first (masculine) form. These details can be overridden in subclasses.

Parameters
string$gender
array$forms
Returns
string

Definition at line 3872 of file Language.php.

◆ getAllMessages()

MediaWiki\Language\Language::getAllMessages ( )
Deprecated
since 1.41, use LocalisationCache directly.
Returns
string[]

Definition at line 2561 of file Language.php.

◆ getArrow()

MediaWiki\Language\Language::getArrow ( $direction = 'forwards')

An arrow, depending on the language direction.

Parameters
string$directionThe direction of the arrow: forwards (default), backwards, left, right, up, down.
Returns
string

Definition at line 3042 of file Language.php.

◆ getBlockDurations()

MediaWiki\Language\Language::getBlockDurations ( $includeOther = true)

Get an array of suggested block durations from MediaWiki:Ipboptions.

Todo
FIXME: This uses a rather odd syntax for the options, should it be converted to the standard "**<duration>|<displayname>" format?
Since
1.42
Parameters
bool$includeOtherWhether to include the 'other' option in the list of suggestions
Returns
string[]

Definition at line 4015 of file Language.php.

◆ getBookstoreList()

MediaWiki\Language\Language::getBookstoreList ( )

Exports $wgBookstoreListEn.

Returns
array

Definition at line 411 of file Language.php.

◆ getCode()

MediaWiki\Language\Language::getCode ( )

Get the internal language code for this language object.

NOTE: The return value of this function is NOT HTML-safe and must be escaped with htmlspecialchars() or similar

Returns
string

Definition at line 4141 of file Language.php.

Referenced by MediaWiki\Skin\SkinComponentLogo\__construct(), MessageCache\__construct(), LanguageHu\convertGrammar(), MediaWiki\Language\Language\equals(), and ChangeTags\getChangeTagListSummary().

◆ getCodeFromFileName()

static MediaWiki\Language\Language::getCodeFromFileName ( $filename,
$prefix = 'Language',
$suffix = '.php' )
static

Get the language code from a file name.

Inverse of getFileName()

Parameters
string$filename$prefix . $languageCode . $suffix
string$prefixPrefix before the language code
string$suffixSuffix after the language code
Returns
string|false Language code, or false if $prefix or $suffix isn't found

Definition at line 4199 of file Language.php.

◆ getCompiledPluralRules()

MediaWiki\Language\Language::getCompiledPluralRules ( )

Get the compiled plural rules for the language.

Since
1.20
Returns
array<int,string> Associative array with plural form, and plural rule as key-value pairs

Definition at line 4463 of file Language.php.

◆ getConverterInternal()

MediaWiki\Language\Language::getConverterInternal ( )
protected

Return the LanguageConverter for this language, convenience function for use in the language classes only.

Returns
ILanguageConverter

Definition at line 4555 of file Language.php.

Referenced by LanguageZh\convertForSearchResult(), and MediaWiki\Language\Language\getNamespaceAliases().

◆ getDateFormats()

MediaWiki\Language\Language::getDateFormats ( )
Returns
string[]

Definition at line 712 of file Language.php.

◆ getDateFormatString()

MediaWiki\Language\Language::getDateFormatString ( $type,
$pref )

Get a format string for a given type and preference.

Parameters
string$typeOne of 'date', 'time', 'both', or 'pretty'.
string$prefThe format name as it appears in Messages*.php under $datePreferences.
Since
1.22 New type 'pretty' that provides a more readable timestamp format
Returns
string

Definition at line 2062 of file Language.php.

◆ getDatePreferenceMigrationMap()

MediaWiki\Language\Language::getDatePreferenceMigrationMap ( )
Returns
string[]

Definition at line 731 of file Language.php.

◆ getDatePreferences()

MediaWiki\Language\Language::getDatePreferences ( )
Returns
string[]|false List of date format preference keys, or false if disabled.

Definition at line 705 of file Language.php.

◆ getDefaultDateFormat()

MediaWiki\Language\Language::getDefaultDateFormat ( )
Returns
string

Definition at line 719 of file Language.php.

◆ getDir()

MediaWiki\Language\Language::getDir ( )

Return the correct HTML 'dir' attribute value for this language.

Returns
string

Definition at line 2958 of file Language.php.

Referenced by ChangesList\revDateLink().

◆ getDirMark()

MediaWiki\Language\Language::getDirMark ( $opposite = false)

A hidden direction mark (LRM or RLM), depending on the language direction.

This function produces them as invisible Unicode characters and the output may be hard to read and debug, so it should only be used when the output is plain text or can be escaped.

Use of hidden control characters when the output allows use of HTML markup is discouraged and the recommendation is to use bdi HTML tag which doesn't have the issue of hidden characters ending up in user clipboard in text copy paste, see T375975.

Deprecated
since 1.43, use bdi HTML tag in HTML context where possible.
Parameters
bool$oppositeGet the direction mark opposite to your language
Returns
string

Definition at line 3028 of file Language.php.

◆ getDirMarkEntity()

MediaWiki\Language\Language::getDirMarkEntity ( $opposite = false)

A hidden direction mark (LRM or RLM), depending on the language direction.

Unlike getDirMark(), this function returns the character as an HTML entity. This function should be used when the output is guaranteed to be HTML, because it makes the output HTML source code more readable. When the output is plain text or can be escaped, getDirMark() should be used.

Use of hidden control characters when the output allows use of HTML markup is discouraged and the recommendation is to use bdi HTML tag which doesn't have the issue of hidden characters ending up in user clipboard in text copy paste, see T375975.

Deprecated
hard deprecated since 1.43, use bdi HTML tag in HTML context where possible.
Parameters
bool$oppositeGet the direction mark opposite to your language
Returns
string
Since
1.20

Definition at line 3004 of file Language.php.

References wfDeprecated().

◆ getDurationIntervals()

MediaWiki\Language\Language::getDurationIntervals ( $seconds,
array $chosenIntervals = [] )

Takes a number of seconds and returns an array with a set of corresponding intervals.

For example, 65 will be turned into [ minutes => 1, seconds => 5 ].

Since
1.20
Parameters
int$secondsThe number of seconds.
array$chosenIntervalsThe intervals to enable.
Returns
int[]

Definition at line 2249 of file Language.php.

Referenced by LanguageZh_hans\formatDuration().

◆ getFallbackLanguages()

MediaWiki\Language\Language::getFallbackLanguages ( )
Returns
array
Since
1.19

Definition at line 403 of file Language.php.

◆ getFormalityIndex()

MediaWiki\Language\Language::getFormalityIndex ( )

Some languages provide translations in different levels of formality (or manner of address), for example using the T-V distinction.

Since most translations do not differ by formality, we provide magic word, e.g. {{#FORMAL:Du|Sie}} that allows translating only once and defining different forms inline. This only works for languages that have a fallback relation. For example es and es-formal. The return value indicates which form of the forms given should be used for this language. Zero-based index.

Since
1.43

Definition at line 3966 of file Language.php.

◆ getFormattedNamespaces()

MediaWiki\Language\Language::getFormattedNamespaces ( )

A convenience function that returns getNamespaces() with spaces instead of underscores in values.

Useful for producing output to be displayed e.g. in <select> forms.

Returns
string[]

Definition at line 485 of file Language.php.

References MediaWiki\Language\Language\getNamespaces().

◆ getFormattedNsText()

MediaWiki\Language\Language::getFormattedNsText ( $index)

A convenience function that returns the same thing as getNsText() except with '_' changed to ' ', useful for producing output.

$mw_ns = $lang->getFormattedNsText( NS_MEDIAWIKI_TALK ); echo $mw_ns; // prints 'MediaWiki talk'

Parameters
int$indexThe array key of the namespace to return
Returns
string Namespace name without underscores (empty string if namespace does not exist)

Definition at line 524 of file Language.php.

References MediaWiki\Language\Language\getNsText().

◆ getGenderNsText()

MediaWiki\Language\Language::getGenderNsText ( $index,
$gender )

Returns gender-dependent namespace alias if available.

See https://www.mediawiki.org/wiki/Manual:$wgExtraGenderNamespaces

Parameters
int$indexNamespace index
string$genderGender key (male, female... )
Returns
string|false
Since
1.18

Definition at line 537 of file Language.php.

References MediaWiki\MainConfigNames\ExtraGenderNamespaces, and MediaWiki\Language\Language\getNsText().

◆ getGrammarForms()

MediaWiki\Language\Language::getGrammarForms ( )

Get the grammar forms for the content language.

Returns
array Array of grammar forms
Since
1.20

Definition at line 3816 of file Language.php.

◆ getGrammarTransformations()

MediaWiki\Language\Language::getGrammarTransformations ( )

Get the grammar transformations data for the language.

Used like grammar forms, with {{GRAMMAR}} and cases, but uses pairs of regexes and replacements instead of code.

Returns
array[] Array of grammar transformations.
Since
1.28

Definition at line 3835 of file Language.php.

References $IP.

◆ getGroupMemberName()

MediaWiki\Language\Language::getGroupMemberName ( string $group,
$member )

Gets the localized name for a member of a user group if it exists.

For example, "administrator" or "bureaucrat"

Since
1.38
Parameters
string$groupInternal group name
string | UserIdentity$member
Returns
string Localized name for group member

Definition at line 2540 of file Language.php.

◆ getGroupName()

MediaWiki\Language\Language::getGroupName ( $group)

Gets the localized friendly name for a group, if it exists.

For example, "Administrators" or "Bureaucrats"

Since
1.38
Parameters
string$groupInternal group name
Returns
string Localized friendly group name

Definition at line 2526 of file Language.php.

◆ getHookContainer()

MediaWiki\Language\Language::getHookContainer ( )
protected

Get a HookContainer, for hook metadata and running extension hooks.

Since
1.35
Returns
HookContainer

Definition at line 4565 of file Language.php.

◆ getHookRunner()

MediaWiki\Language\Language::getHookRunner ( )
protected

Get a HookRunner, for running core hooks.

Access: internal
This is for use by core only. Hook interfaces may be removed without notice.
Since
1.35
Returns
HookRunner

Definition at line 4577 of file Language.php.

Referenced by MediaWiki\Language\Language\getNamespaces().

◆ getHtmlCode()

MediaWiki\Language\Language::getHtmlCode ( )

Get the code in BCP 47 format which we can use inside html lang="" tags.

NOTE: The return value of this function is NOT HTML-safe and must be escaped with htmlspecialchars() or similar.

Since
1.19
Returns
string

Definition at line 4155 of file Language.php.

◆ getHumanTimestamp()

MediaWiki\Language\Language::getHumanTimestamp ( MWTimestamp $time,
?MWTimestamp $relativeTo = null,
?UserIdentity $user = null )

Get the timestamp in a human-friendly relative format, e.g., "3 days ago".

Determine the difference between the timestamp and the current time, and generate a readable timestamp by returning "<N> <units> ago", where the largest possible unit is used.

Since
1.26 (Prior to 1.26, the method existed but was not meant to be used directly)
Parameters
MWTimestamp$time
MWTimestamp | null$relativeToThe base timestamp to compare to (defaults to now)
UserIdentity | null$userUser the timestamp is being generated for (or null to use main context's user)
Returns
string Formatted timestamp

Definition at line 2411 of file Language.php.

References MediaWiki\Utils\MWTimestamp\offsetForUser().

◆ getJsData()

MediaWiki\Language\Language::getJsData ( )
Access: internal
Only for use by the 'mediawiki.language' ResourceLoader module and generateJqueryMsgData.php
Returns
array

Definition at line 4586 of file Language.php.

◆ getLocalNsIndex()

MediaWiki\Language\Language::getLocalNsIndex ( $text)

Get a namespace key by case-insensitive value.

Only matches namespace names for the current language, not the canonical ones defined in Namespace.php.

Parameters
string$text
Returns
int|false An integer if $text is a valid value otherwise false

Definition at line 577 of file Language.php.

References MediaWiki\Language\Language\getNamespaceIds(), and MediaWiki\Language\Language\lc().

◆ getMagic()

MediaWiki\Language\Language::getMagic ( $mw)

Fill a MagicWord object with data from this instance.

Parameters
MagicWord$mw

Definition at line 3082 of file Language.php.

References wfWarn().

◆ getMagicWords()

MediaWiki\Language\Language::getMagicWords ( )

Get all the magic words from the localisation cache.

Returns
array<string,array> $magicWord => [ int $caseSensitive, string ...$alias ]

Definition at line 3073 of file Language.php.

◆ getMessage()

MediaWiki\Language\Language::getMessage ( $key)
Deprecated
since 1.41, use LocalisationCache or MessageCache as appropriate.
Parameters
string$key
Returns
string|null

Reimplemented in LanguageQqx.

Definition at line 2553 of file Language.php.

◆ getMessageFromDB()

MediaWiki\Language\Language::getMessageFromDB ( $msg)

Get a message from the MediaWiki namespace.

Parameters
string$msgMessage name
Returns
string

Definition at line 741 of file Language.php.

◆ getMonthAbbreviation()

MediaWiki\Language\Language::getMonthAbbreviation ( $key)
Parameters
int$keyNumber from 1 to 12
Returns
string

Definition at line 789 of file Language.php.

Referenced by MediaWiki\Parser\DateFormatter\__construct().

◆ getMonthAbbreviationsArray()

MediaWiki\Language\Language::getMonthAbbreviationsArray ( )
Returns
string[] Indexed from 0 to 11

Definition at line 796 of file Language.php.

◆ getMonthName()

MediaWiki\Language\Language::getMonthName ( $key)
Parameters
int$keyNumber from 1 to 12
Returns
string

Definition at line 762 of file Language.php.

Referenced by MediaWiki\Parser\DateFormatter\__construct(), and LanguageWa\date().

◆ getMonthNameGen()

MediaWiki\Language\Language::getMonthNameGen ( $key)
Parameters
int$keyNumber from 1 to 12
Returns
string

Definition at line 781 of file Language.php.

◆ getMonthNamesArray()

MediaWiki\Language\Language::getMonthNamesArray ( )
Returns
string[] Indexed from 0 to 11

Definition at line 769 of file Language.php.

◆ getNamespaceAliases()

MediaWiki\Language\Language::getNamespaceAliases ( )

◆ getNamespaceIds()

MediaWiki\Language\Language::getNamespaceIds ( )

◆ getNamespaces()

MediaWiki\Language\Language::getNamespaces ( )

Returns an array of localised namespaces indexed by their numbers.

If the namespace is not available in localised form, it will be included in English.

Returns
array<int,string> List of localized namespace names, indexed by numeric namespace ID.

Definition at line 421 of file Language.php.

References MediaWiki\Language\Language\$namespaceNames, MediaWiki\MainConfigNames\ExtraNamespaces, MediaWiki\Language\Language\getHookRunner(), MediaWiki\MainConfigNames\MetaNamespace, MediaWiki\MainConfigNames\MetaNamespaceTalk, NS_PROJECT, and NS_PROJECT_TALK.

Referenced by MediaWiki\Language\Language\getFormattedNamespaces(), MediaWiki\Language\Language\getNamespaceAliases(), MediaWiki\Language\Language\getNamespaceIds(), and MediaWiki\Language\Language\getNsText().

◆ getNsIndex()

MediaWiki\Language\Language::getNsIndex ( $text)

Get a namespace key by case-insensitive value.

Canonical namespace names override custom ones defined for the current language.

Parameters
string$text
Returns
int|false An integer if $text is a valid value otherwise false

Definition at line 669 of file Language.php.

References MediaWiki\Language\Language\getNamespaceIds(), and MediaWiki\Language\Language\lc().

◆ getNsText()

MediaWiki\Language\Language::getNsText ( $index)

Get a namespace value by key.

Namespace name uses underscores (not spaces), e.g. 'MediaWiki_talk'.

$mw_ns = $lang->getNsText( NS_MEDIAWIKI_TALK ); echo $mw_ns; // prints 'MediaWiki_talk'

Parameters
int$indexThe array key of the namespace to return
Returns
string|false String if the namespace value exists, otherwise false

Definition at line 506 of file Language.php.

References MediaWiki\Language\Language\getNamespaces().

Referenced by MediaWiki\Language\Language\getFormattedNsText(), and MediaWiki\Language\Language\getGenderNsText().

◆ getPluralRuleIndexNumber()

MediaWiki\Language\Language::getPluralRuleIndexNumber ( $number)

Find the index number of the plural rule appropriate for the given number.

Parameters
int$number
Returns
int The index number of the plural rule

Definition at line 4529 of file Language.php.

◆ getPluralRules()

MediaWiki\Language\Language::getPluralRules ( )

Get the plural rules for the language.

Since
1.20
Returns
array<int,string> Associative array with plural form number and plural rule as key-value pairs

Definition at line 4485 of file Language.php.

◆ getPluralRuleType()

MediaWiki\Language\Language::getPluralRuleType ( $number)

Find the plural rule type appropriate for the given number.

For example, if the language is set to Arabic, getPluralType(5) should return 'few'.

Since
1.22
Parameters
int$number
Returns
string The name of the plural rule type, e.g., one, two, few, many

Definition at line 4543 of file Language.php.

◆ getPluralRuleTypes()

MediaWiki\Language\Language::getPluralRuleTypes ( )

Get the plural rule types for the language.

Since
1.22
Returns
array<int,string> Associative array with plural form number and plural rule type as key-value pairs

Definition at line 4507 of file Language.php.

◆ getSearchIndexVariant()

MediaWiki\Language\Language::getSearchIndexVariant ( )
protected

Specify the language variant that should be used for search indexing.

Returns
string|null

Reimplemented in LanguageGan, LanguageWuu, and LanguageZh.

Definition at line 2796 of file Language.php.

◆ getSpecialPageAliases()

MediaWiki\Language\Language::getSpecialPageAliases ( )

Get special page names, as an associative array canonical name => array of valid names, including aliases.

Returns
string[][]

Definition at line 3099 of file Language.php.

◆ getVariantname()

MediaWiki\Language\Language::getVariantname ( $code,
$usemsg = true )

Short names for language variants used for language conversion links.

Parameters
string$code
bool$usemsgUse the "variantname-xyz" message if it exists
Returns
string

Definition at line 686 of file Language.php.

References MediaWiki\Language\Language\msg().

◆ getWeekdayAbbreviation()

MediaWiki\Language\Language::getWeekdayAbbreviation ( $key)
Parameters
int$keyNumber from 1 to 7
Returns
string

Definition at line 816 of file Language.php.

◆ getWeekdayName()

MediaWiki\Language\Language::getWeekdayName ( $key)
Parameters
int$keyNumber from 1 to 7
Returns
string

Definition at line 808 of file Language.php.

◆ handleExplicitPluralForms()

MediaWiki\Language\Language::handleExplicitPluralForms ( $count,
array $forms )
protected

Handles explicit plural forms for Language::convertPlural()

In {{PLURAL:$1|0=nothing|one|many}}, 0=nothing will be returned if $1 equals zero. If an explicitly defined plural form matches the $count, then the string value is returned. Otherwise the array is returned for further consideration by CLDR rules or overridden convertPlural().

Since
1.23
Parameters
int$countNon-localized number
string[]$formsDifferent plural forms
Returns
string[]|string

Definition at line 3931 of file Language.php.

Referenced by LanguageKsh\convertPlural().

◆ hasWordBreaks()

MediaWiki\Language\Language::hasWordBreaks ( )

Most writing systems use whitespace to break up words.

Some languages such as Chinese don't conventionally do this, which requires special handling when breaking up words for searching, etc.

Returns
bool

Reimplemented in LanguageYue, and LanguageZh_hans.

Definition at line 2776 of file Language.php.

◆ hebrewNumeral()

static MediaWiki\Language\Language::hebrewNumeral ( $num)
static

Hebrew Gematria number formatting up to 9999.

Parameters
int$num
Returns
string

Definition at line 1885 of file Language.php.

◆ iconv()

MediaWiki\Language\Language::iconv ( $in,
$out,
$string )
Parameters
string$in
string$out
string$string
Returns
string

Definition at line 2571 of file Language.php.

◆ insertSpace()

static MediaWiki\Language\Language::insertSpace ( $string,
$pattern )
staticprotected
Parameters
string$string
string$pattern
Returns
string

Definition at line 2841 of file Language.php.

Referenced by LanguageJa\segmentByWord(), LanguageYue\segmentByWord(), and LanguageZh_hans\segmentByWord().

◆ isRTL()

MediaWiki\Language\Language::isRTL ( )

For right-to-left language support.

Returns
bool

Definition at line 2950 of file Language.php.

◆ isSameCodeAs()

MediaWiki\Language\Language::isSameCodeAs ( Bcp47Code $other)

Compare this Language object to a Bcp47Code.

This is part of the Bcp47Code interface.

Parameters
Bcp47Code$other
Returns
bool
Since
1.41

Definition at line 4178 of file Language.php.

◆ lc()

MediaWiki\Language\Language::lc ( $str,
$first = false )
Parameters
string$str
bool$firstWhether to lowercase only the first character
Returns
string The string with lowercase conversion applied

Definition at line 2655 of file Language.php.

Referenced by MediaWiki\Language\Language\getLocalNsIndex(), MediaWiki\Language\Language\getNamespaceIds(), and MediaWiki\Language\Language\getNsIndex().

◆ lcfirst()

MediaWiki\Language\Language::lcfirst ( $str)
Parameters
string$str
Returns
string The string with lowercase conversion applied to the first character

Reimplemented in LanguageKaa, and LanguageTr.

Definition at line 2632 of file Language.php.

◆ linkPrefixCharset()

MediaWiki\Language\Language::linkPrefixCharset ( )

A regular expression character set to match legal word-prefixing characters which should be merged onto a link of the form foo[[bar]].

Returns
string

Definition at line 4118 of file Language.php.

◆ linkPrefixExtension()

MediaWiki\Language\Language::linkPrefixExtension ( )

To allow "foo[[bar]]" to extend the link over the whole word "foobar".

Returns
bool

Definition at line 3064 of file Language.php.

◆ linkTrail()

MediaWiki\Language\Language::linkTrail ( )

A regular expression to match legal word-trailing characters which should be merged onto a link of the form [[foo]]bar.

Returns
string

Definition at line 4108 of file Language.php.

◆ listToText()

MediaWiki\Language\Language::listToText ( array $list)

Take a list of strings and build a locale-friendly comma-separated list, using the local comma-separator message.

The last two strings are chained with an "and".

Parameters
string[]$list
Returns
string

Definition at line 3380 of file Language.php.

◆ minimumGroupingDigits()

MediaWiki\Language\Language::minimumGroupingDigits ( )

The minimum number of digits a number must have, in addition to the grouping size, before grouping separators are added.

For example, Polish has minimumGroupingDigits = 2, which with a grouping size of 3 causes 4-digit numbers to be written like 9999, but 5-digit numbers are written like "10 000".

Returns
int

Definition at line 3367 of file Language.php.

◆ msg()

MediaWiki\Language\Language::msg ( $msg,
$params )
protected

Gets the Message object from this language.

Only for use inside this class.

Parameters
string$msgMessage name @phpcs:ignore Generic.Files.LineLength
MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float>...$params See Message::params()
Returns
Message

Definition at line 754 of file Language.php.

Referenced by MediaWiki\Language\Language\getVariantname().

◆ needsGenderDistinction()

MediaWiki\Language\Language::needsGenderDistinction ( )

Whether this language uses gender-dependent namespace aliases.

See https://www.mediawiki.org/wiki/Manual:$wgExtraGenderNamespaces

Returns
bool
Since
1.18

Definition at line 552 of file Language.php.

References MediaWiki\MainConfigNames\ExtraGenderNamespaces, MediaWiki\MainConfigNames\ExtraNamespaces, NS_USER, and NS_USER_TALK.

◆ normalize()

MediaWiki\Language\Language::normalize ( $s)

Convert a UTF-8 string to normal form C.

In Malayalam and Arabic, this also cleans up certain backwards-compatible sequences, converting them to the modern Unicode equivalent.

Access: internal
Parameters
string$s
Returns
string

Reimplemented in LanguageAr, and LanguageMl.

Definition at line 2913 of file Language.php.

◆ normalizeForSearch()

MediaWiki\Language\Language::normalizeForSearch ( $text)

Some languages have special punctuation need to be normalized.

Make such changes here.

Some languages such as Chinese have many-to-one conversions, e.g., it should be better to use zh-hans for search, since conversion from zh-hant to zh-hans is less ambiguous than the other way around.

Parameters
string$text
Returns
string

Reimplemented in LanguageZh_hans, and LanguageBe_tarask.

Definition at line 2811 of file Language.php.

◆ parseFormattedNumber()

MediaWiki\Language\Language::parseFormattedNumber ( $number)
Parameters
string$number
Returns
string

Definition at line 3306 of file Language.php.

◆ pipeList()

MediaWiki\Language\Language::pipeList ( array $list)

Same as commaList, but separate it with the pipe instead.

Parameters
string[]$listArray of strings to put in a pipe list
Returns
string

Definition at line 3433 of file Language.php.

◆ preConvertPlural()

MediaWiki\Language\Language::preConvertPlural ( $forms,
$count )
protected

Checks that convertPlural was given an array and pads it to requested number of forms by copying the last one.

Parameters
array$forms
int$countMinimum number of forms
Returns
array Padded array of forms

Definition at line 3952 of file Language.php.

Referenced by LanguageKsh\convertPlural().

◆ removeBadCharLast()

MediaWiki\Language\Language::removeBadCharLast ( $string)
protected

Remove bytes that represent an incomplete Unicode character at the end of string (e.g.

bytes of the char are missing)

Parameters
string$string
Returns
string

Definition at line 3564 of file Language.php.

◆ resetNamespaces()

MediaWiki\Language\Language::resetNamespaces ( )

Resets all the namespace caches.

Mainly used for testing

Deprecated
since 1.39 Use MediaWikiServices::resetServiceForTesting() instead.

Definition at line 473 of file Language.php.

◆ romanNumeral()

static MediaWiki\Language\Language::romanNumeral ( $num)
static

Roman number formatting up to 10000.

Parameters
int$num
Returns
string

Definition at line 1854 of file Language.php.

◆ segmentByWord()

MediaWiki\Language\Language::segmentByWord ( $string)

Some languages such as Chinese require word segmentation, Specify such segmentation when overridden in derived class.

Parameters
string$string
Returns
string

Reimplemented in LanguageJa, LanguageYue, and LanguageZh_hans.

Definition at line 2787 of file Language.php.

◆ segmentForDiff()

MediaWiki\Language\Language::segmentForDiff ( $text)

Languages like Chinese need to be segmented in order for the diff to be of any use.

Parameters
string$text
Returns
string

Reimplemented in LanguageZh.

Definition at line 4088 of file Language.php.

◆ semicolonList()

MediaWiki\Language\Language::semicolonList ( array $list)

Take a list of strings and build a locale-friendly semicolon-separated list, using the local semicolon-separator message.

Parameters
string[]$listArray of strings to put in a semicolon list
Returns
string

Definition at line 3420 of file Language.php.

◆ separatorTransformTable()

MediaWiki\Language\Language::separatorTransformTable ( )
Returns
string[]

Definition at line 3353 of file Language.php.

◆ setNamespaces()

MediaWiki\Language\Language::setNamespaces ( array $namespaces)

Arbitrarily set all the namespace names at once.

Mainly used for testing

Parameters
string[]$namespacesArray of namespaces (id => name)

Definition at line 464 of file Language.php.

◆ specialList()

MediaWiki\Language\Language::specialList ( $page,
$details )

Make a list item, used by various special pages.

Parameters
string$pagePage link
string$detailsHTML safe text between brackets
Returns
string HTML escaped

Definition at line 4447 of file Language.php.

◆ sprintfDate()

MediaWiki\Language\Language::sprintfDate ( $format,
$ts,
?DateTimeZone $zone = null,
& $ttl = 'unused' )

This is a workalike of PHP's date() function, but with better internationalisation, a reduced set of format characters, and a better escaping format.

Supported format characters are dDjlNwzWFmMntLoYyaAgGhHiscrUeIOPTZ. See the PHP manual for definitions. There are a number of extensions, which start with "x":

xn Do not translate digits of the next numeric format character xN Toggle raw digit (xn) flag, stays set until explicitly unset xr Use roman numerals for the next numeric format character xh Use hebrew numerals for the next numeric format character xx Literal x xg Genitive month name

xij j (day number) in Iranian calendar xiF F (month name) in Iranian calendar xin n (month number) in Iranian calendar xiy y (two digit year) in Iranian calendar xiY Y (full year) in Iranian calendar xit t (days in month) in Iranian calendar xiz z (day of the year) in Iranian calendar

xjj j (day number) in Hebrew calendar xjF F (month name) in Hebrew calendar xjt t (days in month) in Hebrew calendar xjx xg (genitive month name) in Hebrew calendar xjn n (month number) in Hebrew calendar xjY Y (full year) in Hebrew calendar

xmj j (day number) in Hijri calendar xmF F (month name) in Hijri calendar xmn n (month number) in Hijri calendar xmY Y (full year) in Hijri calendar

xkY Y (full year) in Thai solar calendar. Months and days are identical to the Gregorian calendar xoY Y (full year) in Minguo calendar or Juche year. Months and days are identical to the Gregorian calendar xtY Y (full year) in Japanese nengo. Months and days are identical to the Gregorian calendar

Characters enclosed in double quotes will be considered literal (with the quotes themselves removed). Unmatched quotes will be considered literal quotes. Example:

"The month is" F => The month is January i's" => 20'11"

Backslash escaping is also supported.

Input timestamp is assumed to be pre-normalized to the desired local time zone, if any. Note that the format characters crUeIOPTZ will assume $ts is UTC if $zone is not given.

Parameters
string$format
string$ts14-character timestamp YYYYMMDDHHMMSS 01234567890123
DateTimeZone | null$zoneTimezone of $ts
int | null&$ttlThe amount of time (in seconds) the output may be cached for. Only makes sense if $ts is the current time.
Todo
handling of "o" format character for Iranian, Hebrew, Hijri & Thai?
Returns
string

Definition at line 907 of file Language.php.

◆ time()

MediaWiki\Language\Language::time ( $ts,
$adj = false,
$format = true,
$timecorrection = false )
Parameters
string$tsThe time format which needs to be turned into a date('YmdHis') format with wfTimestamp(TS_MW,$ts)
bool$adjWhether to adjust the time output according to the user configured offset ($timecorrection)
mixed$formatTrue to use user's date format preference
string | false$timecorrectionThe time offset as returned by validateTimeZone() in Special:Preferences
Returns
string

Definition at line 2117 of file Language.php.

References wfTimestamp().

Referenced by LanguageWa\timeanddate().

◆ timeanddate()

MediaWiki\Language\Language::timeanddate ( $ts,
$adj = false,
$format = true,
$timecorrection = false )
Parameters
string$tsThe time format which needs to be turned into a date('YmdHis') format with wfTimestamp(TS_MW,$ts)
bool$adjWhether to adjust the time output according to the user configured offset ($timecorrection)
mixed$formatWhat date format to return the result in; if it's false output the default one (default true)
string | false$timecorrectionThe time offset as returned by validateTimeZone() in Special:Preferences
Returns
string

Reimplemented in LanguageWa.

Definition at line 2137 of file Language.php.

References wfTimestamp().

◆ toBcp47Code()

MediaWiki\Language\Language::toBcp47Code ( )

Implement the Bcp47Code interface.

This is an alias for ::getHtmlCode().

Since
1.40
Returns
string

Definition at line 4167 of file Language.php.

◆ transformUsingPairFile()

MediaWiki\Language\Language::transformUsingPairFile ( string $dataClass,
string $input )
protected

Transform a string using serialized data stored in the given file (which must be in the serialized subdirectory of $IP).

The file contains pairs mapping source characters to destination characters.

The data is cached in process memory.

Parameters
string$dataClassName of a normalized pairs' data class
string$input
Returns
string

Definition at line 2937 of file Language.php.

Referenced by LanguageAr\normalize(), and LanguageMl\normalize().

◆ translateBlockExpiry()

MediaWiki\Language\Language::translateBlockExpiry ( $str,
?UserIdentity $user = null,
$now = 0 )
Todo
Maybe translate block durations. Note that this function is somewhat misnamed: it deals with translating the duration ("1 week", "4 days", etc.), not the expiry time (which is an absolute timestamp). Please note: do NOT add this blindly, as it is used on old expiry lengths recorded in log entries. You'd need to provide the start date to match up with it.
Parameters
string$strThe validated block duration in English
UserIdentity | null$userUser to use timezone from or null for the context user
int$nowCurrent timestamp, for formatting relative block durations
Returns
string Somehow translated block duration
See also
LanguageFi.php file for an implementation example

Reimplemented in LanguageFi.

Definition at line 4046 of file Language.php.

References wfIsInfinity().

◆ truncateForDatabase()

MediaWiki\Language\Language::truncateForDatabase ( $string,
$length,
$ellipsis = '...',
$adjustLength = true )

Truncate a string to a specified length in bytes, appending an optional string (e.g., for ellipsis) When an ellipsis isn't needed, using mb_strcut() directly is recommended.

If $length is negative, the string will be truncated from the beginning

Since
1.31
Parameters
string$stringString to truncate
int$lengthMaximum length in bytes
string$ellipsisString to append to the end of truncated text
bool$adjustLengthSubtract length of ellipsis from $length
Returns
string

Definition at line 3456 of file Language.php.

◆ truncateForVisual()

MediaWiki\Language\Language::truncateForVisual ( $string,
$length,
$ellipsis = '...',
$adjustLength = true )

Truncate a string to a specified number of characters, appending an optional string (e.g., for ellipsis).

This provides the multibyte version of truncateForDatabase() method of this class, suitable for truncation based on number of characters, instead of number of bytes.

The input should be a raw UTF-8 string, and NOT be HTML escaped. It is not safe to truncate HTML-escaped strings, because the entity can be truncated! Use ::truncateHtml() if you need a specific number of HTML-encoded bytes, or ::truncateForDatabase() if you need a specific number of PHP bytes.

If $length is negative, the string will be truncated from the beginning.

Since
1.31
Parameters
string$stringString to truncate
int$lengthMaximum number of characters
string$ellipsisString to append to the end of truncated text
bool$adjustLengthSubtract length of ellipsis from $length
Returns
string

Definition at line 3487 of file Language.php.

Referenced by TraditionalImageGallery\getCaptionHtml(), and ChangeTags\getChangeTagList().

◆ truncateHtml()

MediaWiki\Language\Language::truncateHtml ( $text,
$length,
$ellipsis = '...' )

Truncate a string of valid HTML to a specified length in bytes, appending an optional string (e.g., for ellipses), and return valid HTML.

This is only intended for styled/linked text, such as HTML with tags like and , where the tags are self-contained (valid HTML). Also, this will not detect things like "display:none" CSS.

Note: since 1.18 you do not need to leave extra room in $length for ellipses.

Parameters
string$textHTML string to truncate
int$length(zero/positive) Maximum HTML length (including ellipses)
string$ellipsisString to append to the truncated text
Returns
string

Definition at line 3598 of file Language.php.

◆ uc()

MediaWiki\Language\Language::uc ( $str,
$first = false )
Parameters
string$str
bool$firstWhether to uppercase only the first character
Returns
string The string with uppercase conversion applied

Definition at line 2620 of file Language.php.

◆ ucfirst()

MediaWiki\Language\Language::ucfirst ( $str)
Parameters
string$str
Returns
string The string with uppercase conversion applied to the first character

Reimplemented in LanguageAz, LanguageKaa, and LanguageTr.

Definition at line 2586 of file Language.php.

◆ ucwordbreaks()

MediaWiki\Language\Language::ucwordbreaks ( $str)

capitalize words at word breaks

Parameters
string$str
Returns
mixed

Definition at line 2701 of file Language.php.

References $matches.

◆ ucwords()

MediaWiki\Language\Language::ucwords ( $str)
Parameters
string$str
Returns
mixed|string

Definition at line 2675 of file Language.php.

References $matches.

◆ unsegmentForDiff()

MediaWiki\Language\Language::unsegmentForDiff ( $text)

And unsegment to show the result.

Parameters
string$text
Returns
string

Reimplemented in LanguageZh.

Definition at line 4098 of file Language.php.

◆ userAdjust()

MediaWiki\Language\Language::userAdjust ( $ts,
$tz = false )

Used by date() and time() to adjust the time output.

Parameters
string$tsThe time in date('YmdHis') format
string | false$tzAdjust the time by this amount (default false, mean we get user timecorrection setting)
Returns
string

Definition at line 1971 of file Language.php.

Referenced by LanguageWa\date().

◆ userDate()

MediaWiki\Language\Language::userDate ( $ts,
UserIdentity $user,
array $options = [] )

Get the formatted date for the given timestamp and formatted for the given user.

Parameters
mixed$tsMixed: the time format which needs to be turned into a date('YmdHis') format with wfTimestamp(TS_MW,$ts)
UserIdentity$userUser used to get preferences for timezone and format
array$optionsArray, can contain the following keys:
  • 'timecorrection': time correction, can have the following values:
    • true: use user's preference
    • false: don't use time correction
    • int: value of time correction in minutes
  • 'format': format to use, can have the following values:
    • true: use user's preference
    • false: use default preference
    • string: format to use
Since
1.19
Returns
string

Definition at line 2346 of file Language.php.

Referenced by MediaWiki\Skin\SkinComponentLastModified\getTemplateData().

◆ userTime()

MediaWiki\Language\Language::userTime ( $ts,
UserIdentity $user,
array $options = [] )

Get the formatted time for the given timestamp and formatted for the given user.

Parameters
mixed$tsThe time format which needs to be turned into a date('YmdHis') format with wfTimestamp(TS_MW,$ts)
UserIdentity$userUser used to get preferences for timezone and format
array$optionsArray, can contain the following keys:
  • 'timecorrection': time correction, can have the following values:
    • true: use user's preference
    • false: don't use time correction
    • int: value of time correction in minutes
  • 'format': format to use, can have the following values:
    • true: use user's preference
    • false: use default preference
    • string: format to use
Since
1.19
Returns
string

Definition at line 2369 of file Language.php.

Referenced by MediaWiki\Skin\SkinComponentLastModified\getTemplateData(), and ChangesList\revDateLink().

◆ userTimeAndDate()

MediaWiki\Language\Language::userTimeAndDate ( $ts,
UserIdentity $user,
array $options = [] )

Get the formatted date and time for the given timestamp and formatted for the given user.

Parameters
mixed$tsThe time format which needs to be turned into a date('YmdHis') format with wfTimestamp(TS_MW,$ts)
UserIdentity$userUser used to get preferences for timezone and format
array$optionsArray, can contain the following keys:
  • 'timecorrection': time correction, can have the following values:
    • true: use user's preference
    • false: don't use time correction
    • int: value of time correction in minutes
  • 'format': format to use, can have the following values:
    • true: use user's preference
    • false: use default preference
    • string: format to use
Since
1.19
Returns
string

Definition at line 2392 of file Language.php.

Referenced by ChangesList\revDateLink().

Member Data Documentation

◆ $dateFormatStrings

string [][] MediaWiki\Language\Language::$dateFormatStrings = []

memoize

Deprecated
since 1.35, must be private

Definition at line 99 of file Language.php.

◆ $durationIntervals

int [] MediaWiki\Language\Language::$durationIntervals = self::DURATION_INTERVALS
static
Deprecated
since 1.35, use the DURATION_INTERVALS constant
Since
1.20

Definition at line 295 of file Language.php.

◆ $mCode

string MediaWiki\Language\Language::$mCode

Definition at line 84 of file Language.php.

◆ $mExtendedSpecialPageAliases

string [][] null MediaWiki\Language\Language::$mExtendedSpecialPageAliases

memoize

Deprecated
since 1.35, must be protected

Definition at line 106 of file Language.php.

◆ $mMagicExtensions

MediaWiki\Language\Language::$mMagicExtensions = []
Deprecated
since 1.35, use LocalisationCache with custom language config

Definition at line 89 of file Language.php.

◆ $mMonthAbbrevMsgs

MediaWiki\Language\Language::$mMonthAbbrevMsgs = self::MONTH_ABBREVIATED_MESSAGES
static
Deprecated
since 1.35, use the MONTH_ABBREVIATED_MESSAGES constant

Definition at line 229 of file Language.php.

◆ $mMonthMsgs

MediaWiki\Language\Language::$mMonthMsgs = self::MONTH_MESSAGES
static
Deprecated
since 1.35, use the MONTH_MESSAGES constant

Definition at line 207 of file Language.php.

◆ $mNamespaceIds

array<string,int> null MediaWiki\Language\Language::$mNamespaceIds
protected

Indexed by localized lower-cased namespace name.

Definition at line 111 of file Language.php.

Referenced by MediaWiki\Language\Language\getNamespaceIds().

◆ $namespaceAliases

array<string,int> null MediaWiki\Language\Language::$namespaceAliases
protected

Map from alias to namespace ID.

Definition at line 113 of file Language.php.

Referenced by MediaWiki\Language\Language\getNamespaceAliases().

◆ $namespaceNames

array<int,string> null MediaWiki\Language\Language::$namespaceNames
protected

Indexed by numeric namespace ID.

Definition at line 109 of file Language.php.

Referenced by MediaWiki\Language\Language\getNamespaces().

◆ DURATION_INTERVALS

const MediaWiki\Language\Language::DURATION_INTERVALS
protected
Initial value:
= [
'millennia' => 1000 * 31_556_952,
'centuries' => 100 * 31_556_952,
'decades' => 10 * 31_556_952,
'years' => 31_556_952,
'months' => 365.2425 * 24 * 3600 / 12,
'days' => 24 * 3600,
'hours' => 3600,
'minutes' => 60,
'seconds' => 1,
]
Since
1.35

Definition at line 276 of file Language.php.

◆ HEBREW_CALENDAR_MONTH_GENITIVE_MESSAGES

const MediaWiki\Language\Language::HEBREW_CALENDAR_MONTH_GENITIVE_MESSAGES
Initial value:
= [
'hebrew-calendar-m1-gen', 'hebrew-calendar-m2-gen', 'hebrew-calendar-m3-gen',
'hebrew-calendar-m4-gen', 'hebrew-calendar-m5-gen', 'hebrew-calendar-m6-gen',
'hebrew-calendar-m7-gen', 'hebrew-calendar-m8-gen', 'hebrew-calendar-m9-gen',
'hebrew-calendar-m10-gen', 'hebrew-calendar-m11-gen', 'hebrew-calendar-m12-gen',
'hebrew-calendar-m6a-gen', 'hebrew-calendar-m6b-gen'
]
Since
1.35

Definition at line 255 of file Language.php.

◆ HEBREW_CALENDAR_MONTHS_MESSAGES

const MediaWiki\Language\Language::HEBREW_CALENDAR_MONTHS_MESSAGES
Initial value:
= [
'hebrew-calendar-m1', 'hebrew-calendar-m2', 'hebrew-calendar-m3',
'hebrew-calendar-m4', 'hebrew-calendar-m5', 'hebrew-calendar-m6',
'hebrew-calendar-m7', 'hebrew-calendar-m8', 'hebrew-calendar-m9',
'hebrew-calendar-m10', 'hebrew-calendar-m11', 'hebrew-calendar-m12',
'hebrew-calendar-m6a', 'hebrew-calendar-m6b'
]
Since
1.35

Definition at line 244 of file Language.php.

◆ HIJRI_CALENDAR_MONTH_MESSAGES

const MediaWiki\Language\Language::HIJRI_CALENDAR_MONTH_MESSAGES
Initial value:
= [
'hijri-calendar-m1', 'hijri-calendar-m2', 'hijri-calendar-m3',
'hijri-calendar-m4', 'hijri-calendar-m5', 'hijri-calendar-m6',
'hijri-calendar-m7', 'hijri-calendar-m8', 'hijri-calendar-m9',
'hijri-calendar-m10', 'hijri-calendar-m11', 'hijri-calendar-m12'
]
Since
1.35

Definition at line 266 of file Language.php.

◆ IRANIAN_CALENDAR_MONTHS_MESSAGES

const MediaWiki\Language\Language::IRANIAN_CALENDAR_MONTHS_MESSAGES
Initial value:
= [
'iranian-calendar-m1', 'iranian-calendar-m2', 'iranian-calendar-m3',
'iranian-calendar-m4', 'iranian-calendar-m5', 'iranian-calendar-m6',
'iranian-calendar-m7', 'iranian-calendar-m8', 'iranian-calendar-m9',
'iranian-calendar-m10', 'iranian-calendar-m11', 'iranian-calendar-m12'
]
Since
1.35

Definition at line 234 of file Language.php.

◆ MONTH_ABBREVIATED_MESSAGES

const MediaWiki\Language\Language::MONTH_ABBREVIATED_MESSAGES
Initial value:
= [
'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug',
'sep', 'oct', 'nov', 'dec'
]
Since
1.35

Definition at line 221 of file Language.php.

◆ MONTH_GENITIVE_MESSAGES

const MediaWiki\Language\Language::MONTH_GENITIVE_MESSAGES
Initial value:
= [
'january-gen', 'february-gen', 'march-gen', 'april-gen', 'may-gen', 'june-gen',
'july-gen', 'august-gen', 'september-gen', 'october-gen', 'november-gen',
'december-gen'
]
Since
1.35

Definition at line 212 of file Language.php.

◆ MONTH_MESSAGES

const MediaWiki\Language\Language::MONTH_MESSAGES
Initial value:
= [
'january', 'february', 'march', 'april', 'may_long', 'june',
'july', 'august', 'september', 'october', 'november',
'december'
]
Since
1.35

Definition at line 198 of file Language.php.

◆ WEEKDAY_ABBREVIATED_MESSAGES

const MediaWiki\Language\Language::WEEKDAY_ABBREVIATED_MESSAGES
Initial value:
= [
'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'
]
Since
1.35

Definition at line 191 of file Language.php.

◆ WEEKDAY_MESSAGES

const MediaWiki\Language\Language::WEEKDAY_MESSAGES
Initial value:
= [
'sunday', 'monday', 'tuesday', 'wednesday', 'thursday',
'friday', 'saturday'
]
Since
1.35

Definition at line 183 of file Language.php.


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