问题
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