Skip to content

Commit

Permalink
add domain paramter support
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Nov 22, 2013
1 parent f13bd14 commit 1881c80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Expand Up @@ -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)

Expand Down
25 changes: 22 additions & 3 deletions block.t.php
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1881c80

Please sign in to comment.