Diviner

Class PhutilTranslator

Definedsrc/internationalization/PhutilTranslator.php:6
GroupInternationalization

Tasks

Unspecified

Methods

public PhutilTranslator addTranslations(array $translations)

parametersarray$translationsIdentifier in key, translation in value.
returnPhutilTranslatorProvides fluent interface.

Add translations which will be later used by translate(). The parameter is an array of strings (for simple translations) or arrays (for translastions 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.',
);

private chooseVariant(array $translations, $variant)

parametersarray$translations
wild$variant
returnwild
This method is not documented.

public string formatNumber($number, $decimals = 0)

parametersfloat$number
int$decimals
returnstring

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.

public static getInstance()

returnwild
This method is not documented.

public static setInstance(PhutilTranslator $instance)

parametersPhutilTranslator$instance
returnwild
This method is not documented.

public setLanguage($language)

parameterswild$language
returnwild
This method is not documented.

public translate($text)

parameterswild$text
returnwild
This method is not documented.

public string translateDate($format, DateTime $date)

parametersstring$formatFormat accepted by DateTime::format().
DateTime$date
returnstringFormatted and translated date.

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

public validateTranslation($original, $translation)

parameterswild$original
wild$translation
returnwild
This method is not documented.