From 1881c80eea283608221d35543a724ed412de7ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 22 Nov 2013 21:05:10 +0200 Subject: [PATCH] add domain paramter support --- ChangeLog.md | 1 + block.t.php | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index efda625..9907b16 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,7 @@ IMPROVEMENTS: - add line numbers support. adopted [patch](https://sourceforge.net/p/smarty-gettext/patches/3/) from old project + - add domain paramter support. adopted [patch](https://sourceforge.net/p/smarty-gettext/patches/5/) from old project ## 1.0.1 (2013-11-21) diff --git a/block.t.php b/block.t.php index eff7417..80446a7 100644 --- a/block.t.php +++ b/block.t.php @@ -70,6 +70,7 @@ function smarty_gettext_strarg($str/*, $varargs... */) { * - '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()) * * @param array $params * @param string $text @@ -101,11 +102,29 @@ function smarty_block_t($params, $text) { } } + // set domain + if (isset($params['domain'])) { + $domain = $params['domain']; + unset($params['domain']); + } else { + $domain = null; + } + // use plural if required parameters are set if (isset($count) && isset($plural)) { - $text = ngettext($text, $plural, $count); - } else { // use normal - $text = gettext($text); + // use specified textdomain if available + if (isset($domain)) { + $text = dngettext($domain, $text, $plural, $count); + } else { + $text = ngettext($text, $plural, $count); + } + } else { + // use specified textdomain if available + if (isset($domain)) { + $text = dgettext($domain, $text); + } else { + $text = gettext($text); + } } // run strarg if there are parameters