Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
[zen-18] refactor TextDomain and update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed Jun 24, 2012
1 parent 34adb69 commit dc708db
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Translator/Loader/Gettext.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function load($filename, $locale)
list($header, $content) = explode(':', $rawHeader, 1);

if (trim(strtolower($header)) === 'plural-forms') {
$textDomain->setPluralRule(
$textDomain->pluralRule(
PluralRule::fromString($content)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Translator/Loader/PhpArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function load($filename, $locale)

if (array_key_exists('', $textDomain)) {
if (isset($textDomain['']['plural_forms'])) {
$textDomain->setPluralRule(
$textDomain->pluralRule(
PluralRule::fromString($textDomain['']['plural_forms'])
);
}
Expand Down
21 changes: 6 additions & 15 deletions src/Translator/TextDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,19 @@ class TextDomain extends ArrayObject
protected $pluralRule;

/**
* Get the plural rule.
* Get or set the plural rule.
*
* @param PluralRule $rule
* @return PluralRule
*/
public function getPluralRule()
public function pluralRule(PluralRule $rule = null)
{
if ($this->pluralRule === null) {
if ($rule !== null) {
$this->pluralRule = $rule;
} elseif ($this->pluralRule === null) {
$this->pluralRule = PluralRule::fromString('nplurals=2; plural=n==1');
}

return $this->pluralRule;
}

/**
* Set the plural rule.
*
* @param PluralRule $rule
* @return TextDomain
*/
public function setPluralRule(PluralRule $rule)
{
$this->pluralRule = $rule;
return $this;
}
}
2 changes: 1 addition & 1 deletion src/Translator/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function translatePlural(
return ($number != 1 ? $singular : $plural);
}

$index = $this->messages[$textDomain][$locale]['']->evaluate($number);
$index = $this->messages[$textDomain][$locale]->pluralRule()->evaluate($number);

if (!isset($translation[$index])) {
throw new Exception\OutOfBoundsException(sprintf(
Expand Down

0 comments on commit dc708db

Please sign in to comment.