5use Gettext\Generators\PhpArray;
 
   10    private $dictionary = array();
 
   11    private $context_glue = 
"\004";
 
   12    private $plurals = array();
 
   23        if (is_object($translations) && $translations instanceof 
Translations) {
 
   25        } elseif (is_string($translations) && is_file($translations)) {
 
   26            $translations = include $translations;
 
   27        } elseif (!is_array($translations)) {
 
   28            throw new \InvalidArgumentException(
'Invalid Translator: only arrays, files or instance of Translations are allowed');
 
   31        foreach ($translations as $translation) {
 
   32            $this->addTranslations($translation);
 
   45        return $this->dpgettext($this->domain, 
null, $original);
 
   53    public function ngettext($original, $plural, $value)
 
   55        return $this->dnpgettext($this->domain, 
null, $original, $plural, $value);
 
   65        return $this->dnpgettext(
$domain, 
null, $original, $plural, $value);
 
   73    public function npgettext($context, $original, $plural, $value)
 
   75        return $this->dnpgettext($this->domain, $context, $original, $plural, $value);
 
   85        return $this->dpgettext($this->domain, $context, $original);
 
   95        return $this->dpgettext(
$domain, 
null, $original);
 
  105        $translation = $this->getTranslation(
$domain, $context, $original);
 
  107        if (isset($translation[1]) && $translation[1] !== 
'') {
 
  108            return $translation[1];
 
  122        $translation = $this->getTranslation(
$domain, $context, $original);
 
  124        if (isset($translation[
$key]) && $translation[
$key] !== 
'') {
 
  125            return $translation[
$key];
 
  128        return (
$key === 1) ? $original : $plural;
 
  138        $info = isset($translations[
'']) ? $translations[
''] : 
null;
 
  139        unset($translations[
'']);
 
  144        if (!$this->domain) {
 
  148        if (!isset($this->dictionary[
$domain])) {
 
  150            $pluralForms = empty(
$info[
'plural-forms']) ? 
'nplurals=2; plural=(n != 1)' : 
$info[
'plural-forms'];
 
  152            list($count, 
$code) = explode(
';', $pluralForms, 2);
 
  156            $this->plurals[
$domain] = array(
 
  157                'count' => (
int) str_replace(
'nplurals=', 
'', $count),
 
  158                'code' => str_replace(
'plural=', 
'return ', str_replace(
'n', 
'$n', 
$code)).
';',
 
  161            $this->dictionary[
$domain] = $translations;
 
  163            $this->dictionary[
$domain] = array_replace_recursive($this->dictionary[
$domain], $translations);
 
  178        $key = isset($context) ? $context.$this->context_glue.$original : $original;
 
  195        if (!isset($this->plurals[
$domain])) {
 
  196            return $n == 1 ? 1 : 2;
 
  199        if (!isset($this->plurals[
$domain][
'function'])) {
 
  200            $this->plurals[
$domain][
'function'] = create_function(
'$n', self::fixTerseIfs($this->plurals[
$domain][
'code']));
 
  203        if ($this->plurals[
$domain][
'count'] <= 2) {
 
  204            return (call_user_func($this->plurals[
$domain][
'function'], 
$n)) ? 2 : 1;
 
  209        return (call_user_func($this->plurals[
$domain][
'function'], 
$n)) + 1;
 
  237        preg_match(
'/(?P<expression>[^?]+)\?(?P<success>[^:]+):(?P<failure>[^;]+)/', 
$code, $matches);
 
  240        if (!isset($matches[0])) {
 
  244        $expression = $matches[
'expression'];
 
if(!array_key_exists('domain', $_REQUEST)) $domain
An exception for terminatinating execution or to throw for unit testing.
Class to manage a collection of translations.
static fixTerseIfs($code, $inner=false)
This function will recursively wrap failure states in brackets if they contain a nested terse if.
loadTranslations($translations)
Loads translation from a Translations instance, a file on an array.
getTranslation($domain, $context, $original)
Search and returns a translation.
ngettext($original, $plural, $value)
isPlural($domain, $n)
Executes the plural decision code given the number to decide which plural version to take.
npgettext($context, $original, $plural, $value)
pgettext($context, $original)
addTranslations(array $translations)
Set new translations to the dictionary.
dnpgettext($domain, $context, $original, $plural, $value)
dgettext($domain, $original)
dpgettext($domain, $context, $original)
dngettext($domain, $original, $plural, $value)
Interface used by all translators.
toArray($value)
Wrap the given value in an array if it is no array.