gpt4 book ai didi

Symfony 2 如何设置回退

转载 作者:行者123 更新时间:2023-12-02 03:22:13 26 4
gpt4 key购买 nike

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

我已经在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com