Experimental Plural Translation Implementation

Personal BACKUP
This commit is contained in:
Alexander Fuhr 2014-09-11 18:04:10 +02:00
parent 3615b96093
commit 583fd46f15
6 changed files with 35 additions and 0 deletions

View File

@ -924,4 +924,9 @@ class Module
{
return mt($this->name, $string);
}
protected function translatePlural($string, $string2, $n)
{
return mtp($this->name, $string, $string2, $n);
}
}

View File

@ -14,6 +14,10 @@ if (extension_loaded('gettext')) {
{
return Translator::translate($messageId, $domain);
}
function mtp($domain, $messageId, $messageId2, $n)
{
return Translator::translatePlural($messageId, $messageId2, $n, $domain);
}
} else {
function t($messageId)
{

View File

@ -48,6 +48,12 @@ class Translator
return $res;
}
public static function translatePlural($msgid1, $msgid2, $n, $domain)
{
$res = dngettext($domain, $msgid1, $msgid2, $n);
return $res;
}
/**
* Register a new gettext domain
*

View File

@ -225,6 +225,20 @@ class ActionController extends Zend_Controller_Action
return Translator::translate($text, $this->view->translationDomain);
}
/**
* Translate a plural string
*
* @param $msgid1
* @param $msgid2
* @param $n
*
* @return string
*/
public function translatePlural($msgid1, $msgid2, $n)
{
return Translator::translatePlural($msgid1, $msgid2, $n, $this->view->translationDomain);
}
protected function ignoreXhrBody()
{
if ($this->isXhr()) {

View File

@ -132,6 +132,11 @@ class View extends Zend_View_Abstract
return Translator::translate($text, $this->translationDomain);
}
public function translatePlural($text, $text2, $n)
{
return Translator::translatePlural($text, $text2, $n, $this->translationDomain);
}
/**
* Load helpers
*/

View File

@ -237,6 +237,7 @@ class GettextTranslationHelper
'/usr/bin/xgettext',
'--language=PHP',
'--keyword=translate',
'--keyword=translatePlural:1,2',
'--keyword=mt:2',
'--keyword=t',
'--sort-output',