Page MenuHomePhabricator

abstract class PhutilLocale
libphutil Technical Documentation (Internationalization)

Defines a locale for translations.

Examples might include "English (US)" or "Japanese".

Methods

abstract public function getLocaleCode()

Get the local identifier code, like "en_US".

Return
stringLocale identifier code.

abstract public function getLocaleName()

Get the human-readable locale name, like "English (US)".

Return
stringHuman-readable locale name.

public function getFallbackLocaleCode()

Set a fallback locale which can be used as a default if this locale is missing translations.

For locales like "English (Great Britain)", missing translations can be sourced from "English (US)".

Return
string|nullLocale code of fallback locale, or null if there is no fallback locale.

public function selectGenderVariant($variant, $translations)

Select a gender variant for this locale. By default, locales use a simple rule with two gender variants, listed in "<male, female>" order.

Parameters
const$variant`PhutilPerson` gender constant.
list<wild>$translationsList of variants.
Return
stringVariant for use.

public function selectPluralVariant($variant, $translations)

Select a plural variant for this locale. By default, locales use a simple rule with two plural variants, listed in "<singular, plural>" order.

Parameters
int$variantPlurality of the value.
list<wild>$translationsList of variants.
Return
stringVariant for use.

public function isSillyLocale()

Flags a locale as silly, like "English (Pirate)".

These locales are fun but disastrously inappropriate for serious businesses.

Return
boolTrue if this locale is silly.

public function isTestLocale()

Flags a locale as a testing locale, like "English (US, ALL CAPS)". These locales are useful for translation development, but not for normal users.

Return
boolTrue if this is a locale for testing or development.

Indicates that the translator should post-process translations in this locale by calling didTranslateString().

Doing this incurs a performance penalty, and is not useful for most languages. However, it can be used to implement test translations like "English (US, ALL CAPS)".

Return
boolTrue to postprocess strings.

public function didTranslateString($raw_pattern, $translated_pattern, $args, $result_text)

Callback for post-processing translations.

By default, this callback is not invoked. To activate it, return true from shouldPostProcessTranslations(). Activating this callback incurs a performance penalty.

Parameters
string$raw_patternThe raw input pattern.
string$translated_patternThe selected translation pattern.
list<wild>$argsThe raw input arguments.
string$result_textThe translated string.
Return
stringPost-processed translation string.

public static function loadAllLocales()

Load all available locales.

Return
map<string, PhutilLocale>Map from codes to locale objects.

public static function loadLocale($locale_code)

Load a specific locale using a locale code.

Parameters
string$locale_codeLocale code.
Return
PhutilLocaleLocale object.

private static function checkLocaleFallback($map, $locale, $seen)

Recursively check locale fallbacks for cycles.

Parameters
map<string,$mapPhutilLocale> Map of locales.
PhutilLocale$localeCurrent locale.
map<string,$seenstring> Map of visited locales.
Return
void