【问题标题】:Refinery CMS on Ruby Rails: Translating / Localising the Strings in the Blog ModuleRuby Rails 上的 Refinery CMS:翻译/本地化博客模块中的字符串
【发布时间】:2015-12-22 13:58:45
【问题描述】:

在炼油厂 CMS 的博客模块中,我想翻译源代码中的一些字符串。当我覆盖博客模块的 _post.html.erb 视图时,里面有这样的代码:

 <%= content_tag(:span, 
   "#{t('by', :scope => 'refinery.blog.posts.show')} #{@post.author.username}",
   :class => "blog_author") if @post.author.present? %>

我想本地化“by”字符串,以便在博客中,默认英文“By authorname”被另一种语言的短语替换。

现在,我已经修改了 rails config/locales 目录中的 en.yml 和 hr.yml 本地化文件并添加了翻译。但是,这对我页面上显示的字符串没有影响。

我尝试将 config/application.rb 中的 config.i18n.default_locale 变量设置为 :en 和我想要的语言,但是这也无济于事。

我来的最远的是,如果我将 initializers/refinery/i18n.rb 中的 config.current_locale 变量更改为 :de例如,它具有翻译炼油厂及其博客模块的管理界面的效果。然而,博客条目中的字符串保持不变。

我还在炼油厂博客组件的 gems 库中添加了一个包含我的语言环境翻译的 yml 文件,但它仍然无法正常工作。

任何有关如何翻译炼油厂博客模块中的字符串的帮助将不胜感激。我在互联网上搜索了如何翻译炼油厂,但没有找到任何关于翻译博客组件的具体信息,只有导轨的一般指南,这似乎对炼油厂博客没有帮助。

我正在使用以下 gems 版本:

  • 导轨 (4.2.4)
  • rails-i18n (4.0.7)
  • 铁路 (4.2.4)
  • refinerycms (3.0.0 1d13007)
  • refinerycms-acts-as-indexed (2.0.1)
  • refinerycms-authentication-devise (1.0.4)
  • refinerycms 博客 (3.0.0 5ee8336)
  • refinerycms-core (3.0.0 1d13007)
  • refinerycms-i18n (3.0.1 ff93ad9)
  • refinerycms-images (3.0.0 1d13007)
  • refinerycms-pages (3.0.0 1d13007)
  • refinerycms-resources (3.0.0 1d13007)
  • refinerycms-search (3.0.0 aa8098c)
  • refinerycms-settings (3.0.0)
  • refinerycms-wymeditor (1.0.6) ...

提前谢谢你!

附言

我已在 hr.yml 中添加了一个翻译字符串并设置了

config.i18n.default_locale = :hr
config.i18n.locale = :hr

application.rb中。

在 Rails 控制台中我得到:

*I18n.locale* => :hr, 
 I18n.translate('hello') => "Pozdrav svima" 

但是,当我启动应用程序时,rails 服务器消息中有:

*Parameters: {"locale"=>:en}*

没有翻译工作...为什么?

【问题讨论】:

    标签: ruby ruby-on-rails-3 localization internationalization refinerycms


    【解决方案1】:

    根据rails locale guide 可以根据 url 设置应用程序区域设置。对于 localhost,语言环境设置为英语。为了改变这一点,可以修改 application_controller.rb

    class ApplicationController < ActionController::Base
      # Prevent CSRF attacks by raising an exception.
      # For APIs, you may want to use :null_session instead.
      protect_from_forgery with: :exception
    
      before_action :set_locale
    
      def set_locale
        I18n.locale = I18n.default_locale
      end
    
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多