doubi1797 2013-12-16 01:29
浏览 19
已采纳

无法在Symfony 2中实现国际化

I am following every step in the Translation document of Symfony. But I still cannot make Internationalisation works in Symfony. Instead of translated message I receive the same message. What I am doing wrong? Here is my setup:

1) app/config/config.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }

framework:
    #esi:             ~
    translator:      { fallback: fa }

2) app/parameters.yml

parameters:
    database_driver: pdo_mysql
    database_host: 127.0.0.1
    database_port: null
    database_user: root
    locale: fa

3) Translation file located in src/App/AppBundle/Resources/translations/addproduct.fa.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>Title</source>
                <target>عنوان</target>
            </trans-unit>
        </body>
    </file>
</xliff>

4) Controller

/**
 * @Route("{_locale}/test")
 */
public function Test()
{
    $translated = $this->get('translator')->trans('Title');

    return new Response($translated);
}
  • 写回答

1条回答 默认 最新

  • doushi2047 2013-12-16 01:48
    关注
    1. Number 3) should be a file in the src/App/AppBundle/Resources/translations directory. The file name needs to follow the domain.locale.loader convention as outlined here, for example app.fa.xliff.

    2. If you named the file app.fa.xliff, then 'app' is your domain. You need to reference this domain in the ->trans method:

    $translated = $this->get('translator')->trans('Title', array(), 'app');

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog