2014-02-15 79 views
1

我在application.rb中設置默認語言環境:es與導軌定位奇怪的行爲

config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 
config.i18n.default_locale = :es 

es.yml文件看起來像這樣:

es: 
    hello: 
    world: "Hola mundo" 
    activerecord: 
    attributes: 
     post: 
     title: "Titulo" 
    errors: 
     models: 
     post: 
      attributes: 
      title: 
       blank: "Hey el %{attribute} está en blanco!" 
       too_short: "%{count} carácteres mínimos" 
      text: 
       blank: "Hey el %{attribute} está en blanco!" 
       too_short: "%{count} carácteres mínimos" 

我試圖讓那些嵌套的翻譯鍵工作在像<%= t :'hello.world' %>這樣的視圖中,使用此配置我得到以下錯誤:

can not load translations from /home/edd/Programming/ruby/rails/blog/config/locales/en.yml: #<Psych::SyntaxError: (/home/edd/Programming/ruby/rails/blog/config/locales/en.yml): found character that cannot start any token while scanning for the next token at line 23 column 1>

此錯誤提到en.yml它的結構是這樣的:

en: 
    hello: 
    world: "Hello world" 
    activerecord: 
    attributes: 
     post: 
     title: "Title" 
    ... 

如果我刪除它開始工作的輔助性T嵌套部分開始工作:

en: 
    world: "Hello world" 

什麼可以在這裏發生了什麼?在此先感謝您的意見。

+0

你確定你的文件中的所有空間是實際的空間?有沒有「奇怪的字符」呢? – fotanus

+1

根據錯誤消息,您應該調查第23行或前一行的前導字符。 –

回答

0

檢查第23行是否有奇怪的字符,例如:一系列標籤中的空格等。

如果是這樣,請移除並確保均勻。

2

我們需要確保空間來解決這個問題。

例如: -

en: 
    articles: 
    index: 
     heading_list: 'Gurudath Articles List In English' 
     description: 'Gurudath Articles Description In English'