「Php/Symfony/Symfony2/翻訳」の版間の差分

提供: 初心者エンジニアの簡易メモ
ナビゲーションに移動 検索に移動
編集の要約なし
編集の要約なし
1行目: 1行目:
==phpの翻訳コード==
==phpの翻訳コード==
  echo $this->get('translator')->trans('Hello World');
  echo $this->get('translator')->trans('Hello World');
==phpの翻訳コード(変換する場合)==
echo $this->get('translator')->trans('user.login'); // Login


==言語設定変更方法==
==言語設定変更方法==
9行目: 12行目:
==言語ファイル==
==言語ファイル==
-Resources/translations/message.en.yml
-Resources/translations/message.en.yml
user:
    login: Login
  symfony2:
  symfony2:
     is:
     is:
15行目: 20行目:
     has:
     has:
         bundles: Symfony2 has bundles
         bundles: Symfony2 has bundles
user:
    login: Login


==翻訳cache削除==
==翻訳cache削除==

2017年1月5日 (木) 08:50時点における版

phpの翻訳コード

echo $this->get('translator')->trans('Hello World');

phpの翻訳コード(変換する場合)

echo $this->get('translator')->trans('user.login'); // Login

言語設定変更方法

-app/config/config.yml

framework:
    translator: { fallback: en }

言語ファイル

-Resources/translations/message.en.yml

user:
   login: Login
symfony2:
   is:
       great: Symfony2 is great
       amazing: Symfony2 is amazing
   has:
       bundles: Symfony2 has bundles

翻訳cache削除

php app/console cache:clear

参考

http://docs.symfony.gr.jp/symfony2/book/translation.html