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

Revision 22099, 1.4 KB checked in by pineray, 11 years ago (diff)

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

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

Line 
1<?php
2/**
3 * Smarty plugin
4 * @package Smarty
5 * @subpackage plugins
6 */
7
8
9/**
10 * Smarty {t} plugin
11 *
12 * Type:     function<br>
13 * Name:     t<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($params, &$smarty) {
21    // 多言語対応用の関数が定義されていなければエラーを出力
22    if (!function_exists('t')) {
23        $smarty->_trigger_fatal_error("[plugin] function 't' is not defined");
24        return;
25    }
26
27    // エイリアスが無ければエラーを出力
28    if (empty($params['string'])) {
29        $smarty->_trigger_fatal_error("[plugin] parameter 'string' cannot be empty");
30        return;
31    }
32    $string = $params['string'];
33    unset($params['string']);
34
35    // オプション用の配列
36    $options = array();
37    // 言語コードの指定があればオプションにセット
38    if (!empty($params['lang_code'])) {
39        $options['lang_code'] = $params['lang_code'];
40        unset($params['lang_code']);
41    }
42    // 機種の指定があればオプションにセット
43    if (!empty($params['device_type_id'])) {
44        $options['device_type_id'] = $params['device_type_id'];
45        unset($params['device_type_id']);
46    }
47
48    return t($string, $params, $options);
49}
Note: See TracBrowser for help on using the repository browser.