【问题标题】:Nested I18n locales in MiddlemanMiddleman 中的嵌套 I18n 语言环境
【发布时间】:2016-11-21 10:40:06
【问题描述】:

我在中间人安装中设置了语言环境,使用文件 locales/en.ymllocales/ar.yml

挑战在于我要翻译很多糟糕的文本,并且希望将内容嵌套如下:

---
en:
  main_page:
    hello_and_welcome: "Hello and Welcome to ..."
    bye_and_well_bye: "Bye now"

我以前可以在我的页面中以I18n.t(:hello) 的形式访问这些词。当我使用嵌套 YAML 时它会如何工作?

尝试了I18n.t(:main_page, :hello_and_welcome),但返回了:

{:hello_and_welcome=>"您好,欢迎来到..."}

【问题讨论】:

    标签: middleman


    【解决方案1】:

    您可以将引用作为字符串传递:

    <%= I18n.t('main_page.hello_and_welcome') %>
    

    或使用短标签:

    <%= t('main_page.hello_and_welcome') %>
    

    【讨论】:

    • 先生,您刚刚救了我的命。
    猜你喜欢
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多