Add locales to Singular controller in rails4

岁酱吖の 提交于 2019-12-11 10:36:41

问题


I have a singular controller i want to add locales to that. It looks like

class AboutController < ApplicationController
    def home
    end

   def markdown_syntax
   end
 end

And my about.en.yml looks like

en:
 about:
   home:
    discover_message: 'Discover, Track and Compare Open Source'
    join_now: 'Join Now'
    whats_new: "What's New"
    popular_projects: 'Most Popular Projects'
    active_projects: 'Most Active Projects'

I am getting translation missing error because it doesn't recognizing from about.en.yml

Error Message:

translation missing: en.about.home.discover_message

回答1:


By default Rails is going to look for en.yml in the config/locales directory.

If you're using about.en.yml as the filename, then Rails is not going to find it unless you've configured things otherwise.




回答2:


Try to specify name of the controller in the locale file like this:

en:
  controllers:
    about:
      home:
        discover_message: 'Discover, Track and Compare Open Source'
        join_now: 'Join Now'
        whats_new: "What's New"
        popular_projects: 'Most Popular Projects'
        active_projects: 'Most Active Projects'

I have also changed 1 space indentation to 2 space indentation, which is standard.



来源:https://stackoverflow.com/questions/29650094/add-locales-to-singular-controller-in-rails4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!