Language\L10n method name fixes, update Smarty block.t.php
__pn for context plural has now correct name __np Update smarty plugin block.t.php to use __* named gettext methods for all calls, for __n/__np/__/__p calls we fallback to check internal set class on l10n object variable. This will be removed in future calls
This commit is contained in:
@@ -601,7 +601,7 @@ class L10n
|
||||
* @param int $number number value
|
||||
* @return string
|
||||
*/
|
||||
public function __pn(string $context, string $single, string $plural, int $number): string
|
||||
public function __np(string $context, string $single, string $plural, int $number): string
|
||||
{
|
||||
if ($this->l10n === null) {
|
||||
return $number > 1 ? $plural : $single;
|
||||
|
||||
@@ -164,8 +164,6 @@ class SmartyExtend extends \Smarty
|
||||
parent::__construct();
|
||||
// iinit lang
|
||||
$this->l10n = $l10n;
|
||||
// opt load functions so we can use legacy init for smarty run perhaps
|
||||
$this->l10n->loadFunctions();
|
||||
// parse and read, legacy stuff
|
||||
$this->encoding = $locale['encoding'];
|
||||
$this->lang = $locale['lang'];
|
||||
@@ -174,6 +172,13 @@ class SmartyExtend extends \Smarty
|
||||
$this->domain = $this->l10n->getDomain();
|
||||
$this->lang_dir = $this->l10n->getBaseLocalePath();
|
||||
|
||||
// opt load functions so we can use legacy init for smarty run perhaps
|
||||
$this->l10n->loadFunctions();
|
||||
__setlocale(LC_MESSAGES, $locale['locale']);
|
||||
__textdomain($this->domain);
|
||||
__bindtextdomain($this->domain, $this->lang_dir);
|
||||
__bind_textdomain_codeset($this->domain, $this->encoding);
|
||||
|
||||
// register smarty variable
|
||||
$this->registerPlugin('modifier', 'getvar', [&$this, 'getTemplateVars']);
|
||||
|
||||
|
||||
@@ -101,11 +101,76 @@ function smarty_block_t($params, $text, $template, &$repeat)
|
||||
}
|
||||
}
|
||||
|
||||
// get domain param
|
||||
if (isset($params['domain'])) {
|
||||
$domain = $params['domain'];
|
||||
unset($params['domain']);
|
||||
} else {
|
||||
$domain = null;
|
||||
}
|
||||
|
||||
// get context param
|
||||
if (isset($params['context'])) {
|
||||
$context = $params['context'];
|
||||
unset($params['context']);
|
||||
} else {
|
||||
$context = null;
|
||||
}
|
||||
|
||||
// use plural if required parameters are set
|
||||
if (isset($count) && isset($plural)) {
|
||||
$text = $template->l10n->__ngettext($text, $plural, $count);
|
||||
if (isset($domain) && isset($context)) {
|
||||
if (is_callable('__dnpgettext')) {
|
||||
$text = __dnpgettext($domain, $context, $text, $plural, $count);
|
||||
}
|
||||
} elseif (isset($domain)) {
|
||||
if (is_callable('__dngettext')) {
|
||||
$text = __dngettext($domain, $text, $plural, $count);
|
||||
}
|
||||
} elseif (isset($context)) {
|
||||
if (is_callable('__npgettext')) {
|
||||
$text == __npgettext($context, $text, $plural, $count);
|
||||
} elseif (
|
||||
$template->l10n instanceof \CoreLibs\Language\L10n &&
|
||||
method_exists($template->l10n, '__pn')
|
||||
) {
|
||||
$text = $template->l10n->__pn($text, $plural, $count);
|
||||
}
|
||||
} elseif (
|
||||
$template->l10n instanceof \CoreLibs\Language\L10n &&
|
||||
method_exists($template->l10n, '__n')
|
||||
) {
|
||||
$text = $template->l10n->__n($text, $plural, $count);
|
||||
// $text == __ngettext($text, $plural, $count);
|
||||
}
|
||||
} else { // use normal
|
||||
$text = $template->l10n->__($text);
|
||||
if (isset($domain) && isset($context)) {
|
||||
if (is_callable('__dpgettext')) {
|
||||
$text = __dpgettext($domain, $context, $text);
|
||||
}
|
||||
} elseif (isset($domain)) {
|
||||
if (is_callable('__dgettext')) {
|
||||
$text = __dgettext($domain, $text);
|
||||
}
|
||||
} elseif (isset($context)) {
|
||||
if (is_callable('__pgettext')) {
|
||||
$text = __pgettext($context, $text);
|
||||
} elseif (
|
||||
$template->l10n instanceof \CoreLibs\Language\L10n &&
|
||||
method_exists($template->l10n, '__p')
|
||||
) {
|
||||
$text = $template->l10n->__p($context, $text);
|
||||
}
|
||||
} else {
|
||||
if (is_callable('__gettext')) {
|
||||
$text = __gettext($text);
|
||||
} elseif (
|
||||
$template->l10n instanceof \CoreLibs\Language\L10n &&
|
||||
method_exists($template->l10n, '__')
|
||||
) {
|
||||
$text = $template->l10n->__($text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// run strarg if there are parameters
|
||||
|
||||
Reference in New Issue
Block a user