Translator
class Translator (View source)
Provides a simple gettext replacement that works independently from the system's gettext abilities.
It can read MO files and use them for translating strings.
It caches ll strings and translations to speed up the string lookup.
Constants
ERROR_NONE |
None error. |
ERROR_DOES_NOT_EXIST |
File does not exist. |
ERROR_BAD_MAGIC |
File has bad magic number. |
ERROR_READING |
Error while reading file, probably too short. |
MAGIC_BE |
Big endian mo file magic bytes. |
MAGIC_LE |
Little endian mo file magic bytes. |
Properties
int | $error | Parse error code (0 if no error). |
Methods
No description
Translates a string.
Check if a string is translated.
Sanitize plural form expression for use in ExpressionLanguage.
Extracts number of plurals from plurals form expression.
Parse full PO header and extract only plural forms line.
Plural version of gettext.
Translate with context.
Plural version of pgettext.
Set translation in place
Set the translations
Get the translations
Details
__construct(CacheInterface|string|null $cache)
No description
string
gettext(string $msgid)
Translates a string.
bool
exists(string $msgid)
Check if a string is translated.
static string
sanitizePluralExpression(string $expr)
Sanitize plural form expression for use in ExpressionLanguage.
static int
extractPluralCount(string $expr)
Extracts number of plurals from plurals form expression.
static string
extractPluralsForms(string $header)
Parse full PO header and extract only plural forms line.
string
ngettext(string $msgid, string $msgidPlural, int $number)
Plural version of gettext.
string
pgettext(string $msgctxt, string $msgid)
Translate with context.
string
npgettext(string $msgctxt, string $msgid, string $msgidPlural, int $number)
Plural version of pgettext.
void
setTranslation(string $msgid, string $msgstr)
Set translation in place
void
setTranslations(array $translations)
Set the translations
array
getTranslations()
Get the translations