Ruby Rails上的Refinery CMS:翻译/本地化Blog模块中的字符串 [英] Refinery CMS on Ruby Rails: Translating / Localising the Strings in the Blog Module

查看:116
本文介绍了Ruby Rails上的Refinery CMS:翻译/本地化Blog模块中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In the blog module for refinery CMS there are some strings in the source code that I would like to translate. When I override the view for _post.html.erb of the blog module there is code like this inside:

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

我想对"by"字符串进行本地化,以便在博客中将默认的英语按作者名"替换为另一种语言的短语.

I would like to localize the "by" string, so that in the blog, the default english "By authorname" is replaced by a phrase in another language.

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

Now, I have modified the en.yml and hr.yml localisation files in the rails config/locales directory and added the translation. However, this makes no effect to the strings displayed on my page.

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

I have tried setting the config.i18n.default_locale variable in config/application.rb to :en and to my desired language but this also accomplishes nothing.

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

The furthest I came was that if I change the config.current_locale variable in initializers/refinery/i18n.rb to :de for example, that has the effect of translating the admin interface for refinery and its blog module. And yet, the strings in the blog entries remain the same.

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

I have also added a yml file with translations for my locale in the gems library of the refinery blog component, but it still does not work.

在精炼博客模块中如何翻译字符串的任何帮助将不胜感激.我已经在互联网上搜索了如何翻译精炼厂的信息,但是没有设法找到有关博客组件翻译的任何特定信息,只能找到有关rails的一般指南,而这些指南似乎对精炼厂博客没有帮助.

Any help on how to translate the strings in the refinery blog module would be appreciated. I have searched the internet on how to translate refinery, but haven't managed to find any specific information for the translation of the the blog component, only general guides for rails, which don't seem to help with the refinery blog.

我正在使用以下gem版本:

I am using the following gems versions:

  • 导轨(4.2.4)
  • rails-i18n(4.0.7)
  • 铁路(4.2.4)
  • 炼油厂cms(3.0.0 1d13007)
  • 按索引编制的精炼厂cms-acts-as(2.0.1)
  • refinerycms-authentication-devise(1.0.4)
  • refinerycms-blog(3.0.0 5ee8336)
  • 精炼厂cms-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设置(3.0.0)
  • 炼油厂cms-wymeditor(1.0.6) ...
  • rails (4.2.4)
  • rails-i18n (4.0.7)
  • railties (4.2.4)
  • refinerycms (3.0.0 1d13007)
  • refinerycms-acts-as-indexed (2.0.1)
  • refinerycms-authentication-devise (1.0.4)
  • refinerycms-blog (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) ...

提前谢谢!

PS

我已将翻译字符串添加到 hr.yml 并设置

I have addded a translation string to hr.yml and set the

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

application.rb 中.

在Rails控制台中,我得到:

In the rails console I get:

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

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

But, when I start the application, in the rails server messages there is:

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

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

and no translations work... Why?

推荐答案

根据跟踪语言环境指南 可以根据url设置应用程序语言环境.对于本地主机,将语言环境设置为英语.为了改变这一点,可以修改 application_controller.rb

According to the rails locale guide the application locale can be set based on the url. For localhost, the locale was set to english. In order to change this, one can modify the 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

这篇关于Ruby Rails上的Refinery CMS:翻译/本地化Blog模块中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆