-->

添加了语言环境中rails4奇异控制器(Add locales to Singular contro

2019-10-22 16:20发布

我有一个单一的控制器我想语言环境补充。 看起来像

class AboutController < ApplicationController
    def home
    end

   def markdown_syntax
   end
 end

而我about.en.yml样子

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'

我正在翻译缺失错误,因为它没有从认识about.en.yml

错误信息:

translation missing: en.about.home.discover_message

Answer 1:

默认情况下,Rails的是要寻找en.ymlconfig/locales目录。

如果您使用about.en.yml作为文件名,然后Rails的是不会发现它,除非你另有配置的东西。



Answer 2:

尝试在这样的语言环境文件控制器的指定名称:

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'

我也改变了1个空间缩进到2空间缩进,这是标准的。



文章来源: Add locales to Singular controller in rails4