💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
1、默认翻译语言设置 `app/config.yml` ~~~ framework: translator: { fallbacks: ["%locale%"] } default_locale: "%locale%" ~~~ 2、翻译文件存放位置 ~~~ app/Resources/translations/ app/Resources/<bundle name>/translations/ XxxBundle/Resources/translations/ ~~~ 3、翻译文件命名规则 `domain.locale.loader` ~~~ messages.en.yml admin.fr.php sonata.zh.xliff ~~~ 4、翻译文件格式示例 ~~~ <!-- messages.zh.xliff --> <?xml version="1.0"?> <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> <file source-language="en" datatype="plaintext" original="file.ext"> <body> <trans-unit id="1"> <source>Hello</source> <target>你好</target> </trans-unit> </body> </file> </xliff> ~~~ ~~~ # messages.zh.yml Hello: 你好 ~~~ ~~~ // messages.zh.php return array( 'Hello' => '你好', ); ~~~ 5、翻译基本用法 Controller下: `$this->get('translator')->trans($id, array $parameters = array(), $domain = null, $locale = null);` ~~~ use Symfony\Component\HttpFoundation\Response; public function indexAction() { $sentence = 'xxxxxx……'.$name; $translated = $this->get('translator')->trans($sentence); return new Response($translated); } ~~~ Twig下: ~~~ {% trans %} {{ sentence }} {% endtrans %} ~~~ ~~~ {{ sentence|trans($parameters,$domain,$locale) }} 举例: {{ sentence|trans({'%name%':'Lilei'},'messages','en') }} ~~~ 6、翻译语言临时更换设置 `$this->get('translator')->setLocale($locale);`