【发布时间】:2018-10-27 08:07:58
【问题描述】:
在I18n locale file(例如el.yml)中:
- 我可以使用
translation方法来使用已经定义的翻译吗? - 我可以在里面使用
ruby code吗?
例如,在locale yml file中,有几个地方我要使用“Invalid”这个词。所以一种方法是每次都翻译“无效”这个词
另一种方法是translate it once,在顶部,然后在包含这个词的语言环境 yml 内的每个翻译中,我可以使用类似 t(:invalid)..
例如:
el:
# global translations - in order to be used later in the file
locked: 'kleidomeno'
invalid: 'mi egiro'
password: 'kodikos'
devise:
failure:
invalid: "#{Invalid} %{authentication_keys} or #{password}."
locked: "Your account is #{locked}."
last_attempt: "You have one more attempt before your account is #{locked}."
not_found_in_database: "#{invalid} %{authentication_keys} ή #{password}."
【问题讨论】:
-
为什么要在 I18n 文件中使用 Ruby?你能解释一下你想要达到的目标吗?
-
亲爱的@spickemann,我在上面的问题中添加了澄清......
标签: ruby-on-rails ruby internationalization translation