Symfony 基本翻译示例 [英] Symfony Basic Translation Example
问题描述
我是 Symfony2 的新手.尝试建立翻译服务.我正在按照官方文档中给出的步骤进行操作.但没有成功.
I am new to Symfony2. Trying to establish translation Service. I am following the steps given in the official documentation. But not successful.
以下是步骤
在 'symfony/app/config/config.yml' 翻译服务中通过定义语言环境
"#translator:{ fallback: %locale% }"
在'symfony/app/config/parameters.yml'
中定义了locale参数"locale:de"
In 'symfony/app/config/parameters.yml'
defined locale parameter "locale:de"
在'src/MyBundle/translateBundle/Resources/translations/messages.de.xlf'
中创建
<?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>Symfony2 is great</source>
<target>J'aime Symfony2</target>
</trans-unit>
</body>
</file>
</xliff>
现在我希望通过这个编码我应该得到:'J'aime Symfony2' on execution of following code.
Now I hope with this coding now I should get: 'J'aime Symfony2' on execution of following code.
<?php
namespace MyDays\translateBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends Controller {
public function indexAction() {
$t = $this->get ( 'translator' )->trans ( 'Symfony2 is great' );
return new Response ( $t );
}
}
但仍然得到原始文本,因为Symfony2 很棒"!除了文档中给出的步骤之外,我还需要做些什么吗?
But still getting original text as 'Symfony2 is great'! Is there anything I have to do apart from the steps given in documentation?
推荐答案
config.yml
translator...
之前的 #
是否已经去掉>?
Have you removed #
before translator...
in config.yml
?
此外,您还需要在添加新翻译文件后清除缓存.
Also you need to clear the cache after adding a new translation file.
这篇关于Symfony 基本翻译示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!