Bug fix in smarty block.t plugin

Equal instead of assign for plural text translate calls.

Update smarty tests with more detail checks of translations
This commit is contained in:
Clemens Schwaighofer
2022-04-18 10:52:37 +09:00
parent daf1f9263c
commit 3c35341e8b
3 changed files with 26 additions and 5 deletions

View File

@@ -160,6 +160,12 @@ _textdomain($domain);
_bindtextdomain($domain, $path);
_bind_textdomain_codeset($domain, $encoding);
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
$single_string = 'single';
$multi_string = 'multi';
for ($n = 0; $n <= 3; $n++) {
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
. _ngettext($single_string, $multi_string, $n) . "<br>";
}
$locale = 'en_US.UTF-8';
_setlocale(LC_MESSAGES, $locale);
@@ -167,6 +173,12 @@ _textdomain($domain);
_bindtextdomain($domain, $path);
_bind_textdomain_codeset($domain, $encoding);
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
$single_string = 'single';
$multi_string = 'multi';
for ($n = 0; $n <= 3; $n++) {
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
. _ngettext($single_string, $multi_string, $n) . "<br>";
}
print "</body></html>";

View File

@@ -14,7 +14,12 @@
<b>Translate Test with replace:</b><br>
ORIGINAL: Original with string: %1 ({$replace})<br>
TRANSLATED: {t 1=$replace}Original with string: %1{/t}<br>
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}<br>
{capture assign="extra_title"}{t}INPUT TEST{/t}{/capture}
Capture test: {$extra_title}<br>
{section name=plural_test start=0 loop=3}
Plural test {$smarty.section.plural_test.index}: {t count=$smarty.section.plural_test.index plural="multi"}single{/t}<br>
{/section}
</div>
<div>
<b>Variable variables:</b><br>

View File

@@ -57,14 +57,18 @@ function smarty_gettext_strarg($str/*, $varargs... */)
* - escape - sets escape mode:
* - 'html' for HTML escaping, this is the default.
* - 'js' for javascript escaping.
* - 'url' for url escaping.
* - 'no'/'off'/0 - turns off escaping
* - plural - The plural version of the text (2nd parameter of ngettext())
* - count - The item count for plural mode (3rd parameter of ngettext())
* - domain - Textdomain to be used, default if skipped (dgettext() instead of gettext())
* - context - gettext context. reserved for future use.
*
*/
// cs modified: __ calls instead of direct gettext calls
function smarty_block_t($params, $text, $template, &$repeat)
function smarty_block_t($params, $text)
{
if (!isset($text)) {
return $text;
@@ -122,15 +126,15 @@ function smarty_block_t($params, $text, $template, &$repeat)
}
} elseif (isset($context)) {
if (is_callable('_npgettext')) {
$text == _npgettext($context, $text, $plural, $count);
$text = _npgettext($context, $text, $plural, $count);
}/* elseif (is_callable('npgettext')) {
$text = npgettext($context, $text, $plural, $count);
} */
} else {
if (is_callable('_ngettext')) {
$text == _ngettext($text, $plural, $count);
$text = _ngettext($text, $plural, $count);
} elseif (is_callable('ngettext')) {
$text == ngettext($text, $plural, $count);
$text = ngettext($text, $plural, $count);
}
}
} else { // use normal