2016-11-21 81 views
1

我在Middleman安装中使用文件locales/en.ymllocales/ar.yml设置语言环境。Middleman中嵌套的I18n语言环境

所面临的挑战是,我已经得到了很多织补文本的翻译,并希望有东西嵌套像这样:

--- 
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 => “您好,欢迎光临......”}

回答

2

您可以通过引用作为一个字符串:

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

或附带短标签:

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

先生,你救了我的命。 – bartimar