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

提供: 初心者エンジニアの簡易メモ
ナビゲーションに移動 検索に移動
ページの作成:「==phpの翻訳コード== echo $this->get('translator')->trans('Hello World'); ==言語設定変更方法== # app/config/config.yml framework: translator: { fallb...」
 
 
(同じ利用者による、間の7版が非表示)
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


==言語設定変更方法==
==言語設定変更方法==
# app/config/config.yml
-app/config/config.yml
  framework:
  framework:
     translator: { fallback: en }
     translator: { fallback: en }
もしくは・・
-app/config/config.yml
framework:
    translator:      { fallback: "%locale%" }
-app/config/parameters.yml
locale: en


==言語ファイル==
==言語ファイル==
Resources/translations/message.en.yml
-app/Resources/translations/message.en.yml
symfony2:
    is:
        great: Symfony2 is great
        amazing: Symfony2 is amazing
    has:
        bundles: Symfony2 has bundles
  user:
  user:
     login: Login
     login: Login
bundle側のResourcesではない
==翻訳cache削除==
翻訳ファイルを新規で作った場合はcacheの削除が必要
php app/console cache:clear
==参考==
http://docs.symfony.gr.jp/symfony2/book/translation.html

2017年1月6日 (金) 05:40時点における最新版

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 }

もしくは・・

-app/config/config.yml

framework:
    translator:      { fallback: "%locale%" }

-app/config/parameters.yml

locale: en

言語ファイル

-app/Resources/translations/message.en.yml

user:
   login: Login

bundle側のResourcesではない

翻訳cache削除

翻訳ファイルを新規で作った場合はcacheの削除が必要

php app/console cache:clear

参考

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