Page MenuHomePhabricator

final class PhutilTranslator
libphutil Technical Documentation (Internationalization)

This class is not documented.

Methods

public static function getInstance()

This method is not documented.
Return
wild

public static function setInstance($instance)

This method is not documented.
Parameters
PhutilTranslator$instance
Return
wild

public function setLocale($locale)

This method is not documented.
Parameters
PhutilLocale$locale
Return
wild

public function setWillTranslateCallback($callback)

This method is not documented.
Parameters
$callback
Return
wild

public function getWillTranslateCallback()

This method is not documented.
Return
wild

public function setTranslations($translations)

Add translations which will be later used by translate(). The parameter is an array of strings (for simple translations) or arrays (for translations with variants). The number of items in the array is language specific. It is array($singular, $plural) for English.

array(
  'color' => 'colour',
  '%d beer(s)' => array('%d beer', '%d beers'),
);

The arrays can be nested for strings with more variant parts:

array(
  '%d char(s) on %d row(s)' => array(
    array('%d char on %d row', '%d char on %d rows'),
    array('%d chars on %d row', '%d chars on %d rows'),
  ),
);

The translation should have the same placeholders as originals. Swapping parameter order is possible:

array(
  '%s owns %s.' => '%2$s is owned by %1$s.',
);
Parameters
array$translationsIdentifier in key, translation in value.
Return
PhutilTranslatorProvides fluent interface.

public function translate($text)

This method is not documented.
Parameters
$text
Return
wild

private function chooseVariant($translations, $variant)

This method is not documented.
Parameters
array$translations
$variant
Return
wild

public function translateDate($format, $date)

Translate date formatted by $date->format().

Parameters
string$formatFormat accepted by `DateTime::format()`.
DateTime$date
Return
stringFormatted and translated date.

public function formatNumber($number, $decimals)

Format number with grouped thousands and optional decimal part. Requires translations of '.' (decimal point) and ',' (thousands separator). Both these translations must be 1 byte long with PHP < 5.4.0.

Parameters
float$number
int$decimals
Return
string

public function validateTranslation($original, $translation)

This method is not documented.
Parameters
$original
$translation
Return
wild