Symfony 2 如何设置回退

标签 symfony

我正在尝试翻译我的项目。

我已经在 src/AppBundle/Translations/中创建了翻译文件

zh_CN.yml

title : Welcome to my Blog!
welcome.text : Hello! It's my personal blog.
welcome.text.description : I'm gonna use this for showing what i can :)

menu.main : Main

sidebar.account.anonymous : Log in
sidebar.account.logged : Account
sidebar.about.title : About me
sidebar.about.text : My name is Tigran Muradyan. Besides programming, I have lots of hobbies. One of them - playing on piano :)
sidebar.contact.title : Contact me

user.login : Login
user.password : Password
user.remember : Remember me
user.gender : Gender
user.phone : Phone
user.email : Email
user.about : About me
user.account.information : Account information
user.logout : Log out


article.creation.date : Creation date
article.author : Author
article.read.more : Read more

comments : Comments
comments.anonymous : Please log in to leave a comment.
comments.logged : Leave a comment

ru_RU.yml

title : Добро пожаловать на мой блог!
welcome.text : Привет! Это мой личный блог.
welcome.text.description : Я использую его, чтобы показать, что я умею :)

menu.main : Главная

sidebar.account.anonymous : Зайдите на сайт
sidebar.account.logged : Профиль
sidebar.about.title : Обо мне
sidebar.about.text : Меня зовут Тигран Мурадян. Помимо программирования, у меня есть много хобби. Одно из них - фортепиано :)
sidebar.contact.title : Свяжитесь со мной

user.login : Логин
user.password : Пароль
user.remember : Запомнить
user.gender : Пол
user.phone : Телефон
user.email : Электронная почта
user.about : Обо мне
user.account.information : Информация о аккаунте
user.logout : Выйти


article.creation.date : Дата публикации
article.author : Автор
article.read.more : Читать подбробнее

comments : Комментарии
comments.anonymous : Пожалуйста, зайдите под своим аккаунтом. чтобы оставить комментарий.
comments.logged : Оставить комментарий

但是当我输入模板 {{welcome.text|trans}} 时,它说没有找到变量。

我认为问题出在我的翻译设置上。他们在这里

framework:
    #esi:             ~
    translator:      { fallbacks: ["%locale%"] }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    #serializer:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # handler_id set to null will use default session handler from php.ini
        handler_id:  ~
    fragments:       ~
    http_method_override: true

我应该如何设置翻译以及如何加载它们?

谢谢

编辑:

参数.yml

# This file is auto-generated during the composer install
parameters:
    database_host: localhost
    database_port: null
    database_name: blog
    database_user: root
    database_password: null
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    secret: a2cb7f1e0ff91931e4c325b072ba3b6e34af4aa6

最佳答案

因为你没有变量 welcome.text 是吗?如果您使用不带撇号的文本,Twig 期望变量而不是文本。正确的做法是:

{{ 'welcome.text' | trans }}

关于Symfony 2 如何设置回退,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32590034/

相关文章:

mysql - 来自 127.0.0.1 的 TIME_WAIT 过多

php - Symfony 2 必须实现 UserProviderInterface

javascript - 从 Typeaahead.js 中的 symfony Controller 获取数据

php - Doctrine2 ORM 不会刷新在脚本之外更改的对象

php - 交响乐2 : How to concatenate multiple fields into one in a form

php - 如何仅序列化一对多关系的子集?

php - 如何从 Doctrine Fixture 引用中获取实体?

php - 如何将请求堆栈注入(inject) Twig 扩展

symfony - 使用 Symfony2 和 FOSUserBundle 更改角色时如何强制所有用户重新登录?

php - Symfony2 中使用 Solr 的搜索框