Permalink
Browse files

make translators implement number rendering to support languages that…

… have multiple plural forms
  • Loading branch information...
1 parent 10b54ac commit b1f144fe023c0161703c4d73ae98eaadf6ccfe8a @cweiske cweiske committed Jun 4, 2012
Showing with 15 additions and 12 deletions.
  1. +7 −6 src/Date/HumanDiff.php
  2. +2 −1 src/Date/HumanDiff/Locale.php
  3. +6 −5 src/Date/HumanDiff/LocaleArray.php
View
13 src/Date/HumanDiff.php
@@ -103,8 +103,8 @@ public function get($timestamp, $reference = null)
foreach ($this->formats as $format) {
if ($delta < $format[0]) {
- return sprintf(
- $this->getTranslation($format[1]),
+ return $this->getTranslation(
+ $format[1],
round($delta / $format[2])
);
}
@@ -192,18 +192,19 @@ protected function makeTimestamp($something)
/**
* Get the translation for the given string.
*
- * @param string $string String to translate
+ * @param string $string String to translate
+ * @param integer $number Number to render into the string
*
* @return string Translated string. Original string when no translation
* exists.
*/
- protected function getTranslation($string)
+ protected function getTranslation($string, $number)
{
if ($this->translator === null) {
- return $string;
+ return sprintf($string, $number);
}
- return $this->translator->get($string);
+ return $this->translator->get($string, $number);
}
/**
View
3 src/Date/HumanDiff/Locale.php
@@ -6,10 +6,11 @@
* Get the translation for the given string.
*
* @param string $string String to translate
+ * @param integer $number Number to render into the string
*
* @return string Translated string
*/
- public function get($string);
+ public function get($string, $number);
}
?>
View
11 src/Date/HumanDiff/LocaleArray.php
@@ -6,17 +6,18 @@
/**
* Get the translation for the given string.
*
- * @param string $string String to translate
+ * @param string $string String to translate
+ * @param integer $number Number to render into the string
*
* @return string Translated string. Original string when no translation
* exists.
*/
- public function get($string)
+ public function get($string, $number)
{
- if (!isset($this->trans[$string])) {
- return $string;
+ if (isset($this->trans[$string])) {
+ $string = $this->trans[$string];
}
- return $this->trans[$string];
+ return sprintf($string, $number);
}
}

0 comments on commit b1f144f

Please sign in to comment.