Line | |
---|
1 | <?php |
---|
2 | /** |
---|
3 | * Smarty plugin |
---|
4 | * @package Smarty |
---|
5 | * @subpackage plugins |
---|
6 | */ |
---|
7 | |
---|
8 | |
---|
9 | /** |
---|
10 | * Smarty {t_plural} plugin |
---|
11 | * |
---|
12 | * Type: function<br> |
---|
13 | * Name: t_plural<br> |
---|
14 | * Purpose: replace message alias to appropriate strings |
---|
15 | * @author pineray 松田光貴 <matsudaterutaka at gmail dot com> |
---|
16 | * @param array |
---|
17 | * @param Smarty |
---|
18 | * @return string |
---|
19 | */ |
---|
20 | function smarty_function_t_plural($params, &$smarty) { |
---|
21 | // 書式判定用の数値が無ければエラーを出力 |
---|
22 | if (empty($params['counter'])) { |
---|
23 | $smarty->_trigger_fatal_error("[plugin] parameter 'counter' cannot be empty"); |
---|
24 | return; |
---|
25 | } |
---|
26 | $counter = $params['counter']; |
---|
27 | unset($params['counter']); |
---|
28 | // 単数形のエイリアスが無ければエラーを出力 |
---|
29 | if (empty($params['single'])) { |
---|
30 | $smarty->_trigger_fatal_error("[plugin] parameter 'single' cannot be empty"); |
---|
31 | return; |
---|
32 | } |
---|
33 | $single = $params['single']; |
---|
34 | unset($params['single']); |
---|
35 | // 複数形のエイリアスが無ければエラーを出力 |
---|
36 | if (empty($params['plural'])) { |
---|
37 | $smarty->_trigger_fatal_error("[plugin] parameter 'plural' cannot be empty"); |
---|
38 | return; |
---|
39 | } |
---|
40 | $plural = $params['plural']; |
---|
41 | unset($params['plural']); |
---|
42 | |
---|
43 | // オプション用の配列 |
---|
44 | $options = array(); |
---|
45 | // 言語コードの指定があればオプションにセット |
---|
46 | if (!empty($params['lang_code'])) { |
---|
47 | $options['lang_code'] = $params['lang_code']; |
---|
48 | unset($params['lang_code']); |
---|
49 | } |
---|
50 | // 機種の指定があればオプションにセット |
---|
51 | if (!empty($params['device_type_id'])) { |
---|
52 | $options['device_type_id'] = $params['device_type_id']; |
---|
53 | unset($params['device_type_id']); |
---|
54 | } |
---|
55 | |
---|
56 | return SC_I18n_Ex::t_plural($counter, $single, $plural, $params, $options); |
---|
57 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.