[Svn-src-all:3252] [version-2_12-multilang 22153] #163 テキスト出力多言語対応
pineray
admin @ mail.ec-cube.net
2012年 12月 20日 (木) 15:24:17 JST
Subversion committed to /home/svn/open 22153
http://svn.ec-cube.net/open_trac/changeset/22153
┌────────────────────────────┐
│更新者 : pineray │
│更新日時: 2012-12-20 15:24:17 +0900 (木, 20 12月 2012)│
└────────────────────────────┘
Log:
--------------------------------------------------------
#163 テキスト出力多言語対応
値を翻訳しながら変数にセットするコンパイラ関数を追加.
Changed: [U:修正,A:追加,D:削除]
--------------------------------------------------------
A branches/version-2_12-multilang/data/smarty_extends/compiler.assign_t.php
A branches/version-2_12-multilang/data/smarty_extends/compiler.assign_t_plural.php
追加: branches/version-2_12-multilang/data/smarty_extends/compiler.assign_t.php
===================================================================
--- branches/version-2_12-multilang/data/smarty_extends/compiler.assign_t.php (rev 0)
+++ branches/version-2_12-multilang/data/smarty_extends/compiler.assign_t.php 2012-12-20 06:24:17 UTC (rev 22153)
@@ -0,0 +1,65 @@
+<?php
+/**
+ * Smarty plugin
+ * @package Smarty
+ * @subpackage plugins
+ */
+
+/**
+ * Smarty {assign_t} compiler function plugin
+ *
+ * Type: compiler function<br>
+ * Name: assign_t<br>
+ * Purpose: assign a translated value to a template variable
+ * @author pineray 松田光貴 <matsudaterutaka at gmail dot com>
+ * @param string containing var-attribute and value-attribute
+ * @param Smarty_Compiler
+ */
+function smarty_compiler_assign_t($tag_attrs, &$compiler)
+{
+ // 多言語対応用の関数が定義されていなければエラーを出力
+ if (!function_exists('t')) {
+ $compiler->_syntax_error("[compiler] function 't' is not defined", E_USER_WARNING);
+ return;
+ }
+
+ $params = $compiler->_parse_attrs($tag_attrs);
+
+ // セット対象が無ければエラーを出力
+ if (!isset($params['var'])) {
+ $compiler->_syntax_error("assign: missing 'var' parameter", E_USER_WARNING);
+ return;
+ }
+ $var = $params['var'];
+ unset($params['var']);
+
+ // エイリアスが無ければエラーを出力
+ if (empty($params['string'])) {
+ $compiler->_syntax_error("[compiler] parameter 'string' cannot be empty", E_USER_WARNING);
+ return;
+ }
+
+ foreach ($params as $key => $param) {
+ eval("\$params[{$key}] = {$param};");
+ }
+
+ $string = $params['string'];
+ unset($params['string']);
+
+ // オプション用の配列
+ $options = array();
+ // 言語コードの指定があればオプションにセット
+ if (!empty($params['lang_code'])) {
+ $options['lang_code'] = $params['lang_code'];
+ unset($params['lang_code']);
+ }
+ // 機種の指定があればオプションにセット
+ if (!empty($params['device_type_id'])) {
+ $options['device_type_id'] = $params['device_type_id'];
+ unset($params['device_type_id']);
+ }
+
+ $translated = '"' . t($string, $params, $options) . '"';
+
+ return "\$this->assign({$var}, {$translated});";
+}
追加: branches/version-2_12-multilang/data/smarty_extends/compiler.assign_t_plural.php
===================================================================
--- branches/version-2_12-multilang/data/smarty_extends/compiler.assign_t_plural.php (rev 0)
+++ branches/version-2_12-multilang/data/smarty_extends/compiler.assign_t_plural.php 2012-12-20 06:24:17 UTC (rev 22153)
@@ -0,0 +1,79 @@
+<?php
+/**
+ * Smarty plugin
+ * @package Smarty
+ * @subpackage plugins
+ */
+
+/**
+ * Smarty {assign_t_plural} compiler function plugin
+ *
+ * Type: compiler function<br>
+ * Name: assign_t_plural<br>
+ * Purpose: assign a translated value to a template variable
+ * @author pineray 松田光貴 <matsudaterutaka at gmail dot com>
+ * @param string containing var-attribute and value-attribute
+ * @param Smarty_Compiler
+ */
+function smarty_compiler_assign_t_plural($tag_attrs, &$compiler)
+{
+ // 多言語対応用の関数が定義されていなければエラーを出力
+ if (!function_exists('t')) {
+ $compiler->_syntax_error("[compiler] function 't' is not defined", E_USER_WARNING);
+ return;
+ }
+
+ $params = $compiler->_parse_attrs($tag_attrs);
+
+ // セット対象が無ければエラーを出力
+ if (!isset($params['var'])) {
+ $compiler->_syntax_error("assign: missing 'var' parameter", E_USER_WARNING);
+ return;
+ }
+ $var = $params['var'];
+ unset($params['var']);
+
+ // 書式判定用の数値が無ければエラーを出力
+ if (empty($params['counter'])) {
+ $compiler->_syntax_error("[compiler] parameter 'counter' cannot be empty", E_USER_WARNING);
+ return;
+ }
+ // 単数形のエイリアスが無ければエラーを出力
+ if (empty($params['single'])) {
+ $compiler->_syntax_error("[compiler] parameter 'single' cannot be empty", E_USER_WARNING);
+ return;
+ }
+ // 複数形のエイリアスが無ければエラーを出力
+ if (empty($params['plural'])) {
+ $compiler->_syntax_error("[compiler] parameter 'plural' cannot be empty", E_USER_WARNING);
+ return;
+ }
+
+ foreach ($params as $key => $param) {
+ eval("\$params[{$key}] = {$param};");
+ }
+
+ $counter = $params['counter'];
+ unset($params['counter']);
+ $single = $params['single'];
+ unset($params['single']);
+ $plural = $params['plural'];
+ unset($params['plural']);
+
+ // オプション用の配列
+ $options = array();
+ // 言語コードの指定があればオプションにセット
+ if (!empty($params['lang_code'])) {
+ $options['lang_code'] = $params['lang_code'];
+ unset($params['lang_code']);
+ }
+ // 機種の指定があればオプションにセット
+ if (!empty($params['device_type_id'])) {
+ $options['device_type_id'] = $params['device_type_id'];
+ unset($params['device_type_id']);
+ }
+
+ $translated = '"' . t_plural($counter, $single, $plural, $params, $options) . '"';
+
+ return "\$this->assign({$var}, {$translated});";
+}
Svn-src-all メーリングリストの案内