4

我正在使用这个 railscast制作我的网站多语言

但一开始我得到一个错误:

I18n::InvalidLocaleData in Users#index

Showing .../app/views/users/index.html.erb where line #1 raised:

can not load translations from .../config/locales/en.yml, expected it to return a hash, but does not

index.html.erb:

<% provide(:title, t('users.index.title.site_title')) %>
<h1><%= t 'users.index.title.head' %></h1>

<%= form_tag users_path, :method => 'get' do %>
  <%= hidden_field_tag :direction, params[:direction] %>
  <%= hidden_field_tag :sort, params[:sort] %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag (t 'users.index.search_form.search'), :name => nil %>
  </p>
<% end %>

配置/语言环境/en.yml

en:
    users:
        index:
            title:
                site_title: "Users"
                head: "Users"
            search_form:
                search: "Search"
4

1 回答 1

6

语言环境数据应该缩进两个空格,而不是四个,所以正确的版本是:

en:
  users:
    index:
      title:
        site_title: "Users"
        head: "Users"
      search_form:
        search: "Search"

另外,请检查您使用的是空格还是制表符,后者会造成麻烦。

于 2013-09-19T12:59:37.757 回答