Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
805c695d68 |
@@ -545,7 +545,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
} else {
|
} else {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
$l10n->__pn($context, $original_single, $original_plural, $n),
|
$l10n->__np($context, $original_single, $original_plural, $n),
|
||||||
'assert failed for plural: ' . $n . ' in context: ' . $context
|
'assert failed for plural: ' . $n . ' in context: ' . $context
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -967,7 +967,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* fuctions check
|
* fuctions check
|
||||||
* TODO: others d/dn/dp/dpn gettext functions
|
* TODO: others d/dn/dp/dnp gettext functions
|
||||||
*
|
*
|
||||||
* @covers __setlocale
|
* @covers __setlocale
|
||||||
* @covers __bindtextdomain
|
* @covers __bindtextdomain
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ $single_string = 'single';
|
|||||||
$multi_string = 'multi';
|
$multi_string = 'multi';
|
||||||
for ($n = 0; $n <= 3; $n++) {
|
for ($n = 0; $n <= 3; $n++) {
|
||||||
echo "CONTEXT MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
echo "CONTEXT MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
||||||
. $l->__pn($context, $single_string, $multi_string, $n) . "<br>";
|
. $l->__np($context, $single_string, $multi_string, $n) . "<br>";
|
||||||
}
|
}
|
||||||
// change domain
|
// change domain
|
||||||
$domain = 'frontend';
|
$domain = 'frontend';
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ $smarty->setSmartyPaths();
|
|||||||
// smarty test
|
// smarty test
|
||||||
$smarty->DATA['SMARTY_TEST'] = 'Test Data';
|
$smarty->DATA['SMARTY_TEST'] = 'Test Data';
|
||||||
$smarty->DATA['TRANSLATE_TEST'] = $l10n->__('Are we translated?');
|
$smarty->DATA['TRANSLATE_TEST'] = $l10n->__('Are we translated?');
|
||||||
|
$smarty->DATA['TRANSLATE_TEST_FUNCTION'] = __gettext('Are we translated?');
|
||||||
$smarty->DATA['TRANSLATE_TEST_SMARTY'] = $smarty->l10n->__('Are we translated?');
|
$smarty->DATA['TRANSLATE_TEST_SMARTY'] = $smarty->l10n->__('Are we translated?');
|
||||||
$smarty->DATA['replace'] = 'Replaced';
|
$smarty->DATA['replace'] = 'Replaced';
|
||||||
// variable variables
|
// variable variables
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
<div>
|
<div>
|
||||||
<b>Outside translation test</b><br>
|
<b>Outside translation test</b><br>
|
||||||
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}<br>
|
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}<br>
|
||||||
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}
|
TRANSLATION CLASS (OUT FUNCTION): {$TRANSLATE_TEST_FUNCTION}<br>
|
||||||
|
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}<br>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<b>Translate Test with replace:</b><br>
|
<b>Translate Test with replace:</b><br>
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
<div>
|
|
||||||
{$SMARTY_TEST}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<select id="drop_down_test" name="drop_down_test">
|
|
||||||
{html_options options=$drop_down_test selected=$drop_down_test_selected}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="jq-container">
|
|
||||||
<div id="jq-test" class="jp-test">
|
|
||||||
<div id="test-div" class="test-div">
|
|
||||||
Some content here or asdfasdfasf
|
|
||||||
</div>
|
|
||||||
<div id="translate-div">
|
|
||||||
{* TRANSLATION SMARTY: {t}I should be translated{/t} *}
|
|
||||||
TRANSLATION SMARTY: I should be translated
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="loop-test">
|
|
||||||
<div>LOOP TEST</div>
|
|
||||||
{section name=page_list start=1 loop=$loop_start+1}
|
|
||||||
<div>LOOP OUTPUT: {$smarty.section.page_list.index}</div>
|
|
||||||
{/section}
|
|
||||||
</div>
|
|
||||||
{* progresss indicator *}
|
|
||||||
<div id="indicator"></div>
|
|
||||||
{* the action confirm box *}
|
|
||||||
<div id="actionBox" class="actionBoxElement"></div>
|
|
||||||
{* The Overlay box *}
|
|
||||||
<div id="overlayBox" class="overlayBoxElement"></div>
|
|
||||||
@@ -601,7 +601,7 @@ class L10n
|
|||||||
* @param int $number number value
|
* @param int $number number value
|
||||||
* @return string
|
* @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) {
|
if ($this->l10n === null) {
|
||||||
return $number > 1 ? $plural : $single;
|
return $number > 1 ? $plural : $single;
|
||||||
|
|||||||
@@ -164,8 +164,6 @@ class SmartyExtend extends \Smarty
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
// iinit lang
|
// iinit lang
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
// opt load functions so we can use legacy init for smarty run perhaps
|
|
||||||
$this->l10n->loadFunctions();
|
|
||||||
// parse and read, legacy stuff
|
// parse and read, legacy stuff
|
||||||
$this->encoding = $locale['encoding'];
|
$this->encoding = $locale['encoding'];
|
||||||
$this->lang = $locale['lang'];
|
$this->lang = $locale['lang'];
|
||||||
@@ -174,6 +172,13 @@ class SmartyExtend extends \Smarty
|
|||||||
$this->domain = $this->l10n->getDomain();
|
$this->domain = $this->l10n->getDomain();
|
||||||
$this->lang_dir = $this->l10n->getBaseLocalePath();
|
$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
|
// register smarty variable
|
||||||
$this->registerPlugin('modifier', 'getvar', [&$this, 'getTemplateVars']);
|
$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
|
// use plural if required parameters are set
|
||||||
if (isset($count) && isset($plural)) {
|
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
|
} 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
|
// run strarg if there are parameters
|
||||||
|
|||||||
Reference in New Issue
Block a user