source: branches/version-2_12-multilang/data/smarty_extends/function.t_plural.php @ 22099

Revision 22099, 2.0 KB checked in by pineray, 12 years ago (diff)

#163 (テキスト出力多言語対応)

文字列変換用の関数をグローバルに変更.

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 */
20function smarty_function_t_plural($params, &$smarty) {
21    // 多言語対応用の関数が定義されていなければエラーを出力
22    if (!function_exists('t_plural')) {
23        $smarty->_trigger_fatal_error("[plugin] function 't_plural' is not defined");
24        return;
25    }
26
27    // 書式判定用の数値が無ければエラーを出力
28    if (empty($params['counter'])) {
29        $smarty->_trigger_fatal_error("[plugin] parameter 'counter' cannot be empty");
30        return;
31    }
32    $counter = $params['counter'];
33    unset($params['counter']);
34    // 単数形のエイリアスが無ければエラーを出力
35    if (empty($params['single'])) {
36        $smarty->_trigger_fatal_error("[plugin] parameter 'single' cannot be empty");
37        return;
38    }
39    $single = $params['single'];
40    unset($params['single']);
41    // 複数形のエイリアスが無ければエラーを出力
42    if (empty($params['plural'])) {
43        $smarty->_trigger_fatal_error("[plugin] parameter 'plural' cannot be empty");
44        return;
45    }
46    $plural = $params['plural'];
47    unset($params['plural']);
48
49    // オプション用の配列
50    $options = array();
51    // 言語コードの指定があればオプションにセット
52    if (!empty($params['lang_code'])) {
53        $options['lang_code'] = $params['lang_code'];
54        unset($params['lang_code']);
55    }
56    // 機種の指定があればオプションにセット
57    if (!empty($params['device_type_id'])) {
58        $options['device_type_id'] = $params['device_type_id'];
59        unset($params['device_type_id']);
60    }
61
62    return t_plural($counter, $single, $plural, $params, $options);
63}
Note: See TracBrowser for help on using the repository browser.