Tag: 本地化

Rails控制台无法启动I18n的错误

当我尝试启动控制台时,我得到了 /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/base.rb:158:in `load_file’: can not load translations from /var/www/railsapp/config/locales/ru.yml, expected it to return a hash, but does not (I18n::InvalidLocaleData) from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/base.rb:15:in `block in load_translations’ from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/base.rb:15:in `each’ from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/base.rb:15:in `load_translations’ from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/simple.rb:57:in `init_translations’ from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/simple.rb:71:in `lookup’ from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n/backend/base.rb:26:in `translate’ from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n.rb:156:in `block in translate’ from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n.rb:152:in `catch’ from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/i18n-0.6.1/lib/i18n.rb:152:in `translate’ from /home/username/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.1.0/lib/active_record/railtie.rb:102:in `block in ‘ […]

rails中的human_attribute_name和转换文件

我正在运行一个带有英语和西class牙语翻译文件的站点,默认为英语。 使用如下翻译: en: tenants: about: “About” 至 es: tenants: about: “Acera” 运用 t “tenants.about” 工作没有问题,并在适当时从en.yml和es.yml文件中正确读取。 但是,在尝试使用human_attribute_name属性从spanish es.yml文件的另一部分提取模型属性时,不会读取值。 所以像 Job.human_attribute_name(:title) 返回“title”而不是“Título”。 具有人性化属性的相同es.yml文件的部分如下: es: tenants: about: “Acerca” activerecord: attributes: job: title: “Título de la oferta de trabajo” location: “Localización de la oferta de trabajo” job_type: “Tipo de trabajo” description: “Descripción” 任何见解将不胜感激。

Ruby on Rails用法语发送flash消息

使用法语在rails应用程序上工作,但是每当我在flash消息中包含重音时,它就会破坏站点。 例如 format.html {redirect_to @message.annonce, notice:”Votre message a été envoyé”} format.html {redirect_to @message.annonce, notice:”Votre email n’a pas pu être envoyer à cause d’une erreur.”} 我的config / application.rb看起来像这样 config.i18n.default_locale = :fr config.encoding = “utf-8” 人们怎么做到这一点?

如何通过URL更改区域设置?

在我的双语Rails 4应用程序中,我有一个像这样的LocalesController : class LocalesController < ApplicationController def change_locale if params[:set_locale] session[:locale] = params[:set_locale] url_hash = Rails.application.routes.recognize_path URI(request.referer).path url_hash[:locale] = params[:set_locale] redirect_to url_hash end end end 用户可以通过以下表单更改其语言环境: def locale_switcher form_tag url_for(:controller => ‘locales’, :action => ‘change_locale’), :method => ‘get’, :id => ‘locale_switcher’ do select_tag ‘set_locale’, options_for_select(LANGUAGES, I18n.locale.to_s) end 这很有效。 但是,现在用户无法通过URL更改语言。 例如,如果用户在www.app.com/en/projects页面www.app.com/en/projects ,然后手动将URL更改为www.app.com/fr/projects ,他应该看到该页面的法语版本,但没有任何反应。 这在许多Rails应用程序中可能无关紧要,但在我的应用程序中它非常重要。 怎么修好? […]

在Rails中本地化嵌套的虚拟属性

如何在Rails中本地化嵌套的虚拟属性 ? 该模型: class User < ActiveRecord::Base attr_accessor :company_information # This is used in callbacks etc end 和观点: = simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), html: {class: ‘form-horizontal’}) do |f| = devise_error_messages! = f.input :email = f.input :password = f.input :password_confirmation = f.simple_fields_for :company_information do |c| = c.input :name # This is what I […]

创建灵活的,本地化的Ruby-on-Rails值列表

我有一个值列表(初级,中级,高级,流利,本机),我想: 充当SELECT列表的模型 充当将id转换为HTML表中的值的模型 用于多个控制器和视图 遵守保留业务规则的顺序(按技能等级排序) 在未来的某个时刻进行本地化 有没有办法实现这个列表来满足我的全部或大部分需求?

为什么Rails中的语言环境设置充当全局(使用Thin时)?

我刚刚意识到推荐的Rails方法可以在控制器中设置区域设置 before_filter :set_locale def set_locale I18n.locale = params[:locale] || I18n.default_locale end 全局设置区域设置。 上面的代码有效,但我想知道如果你必须明确键入它, default_locale真的是默认的吗? 我期望的是每个请求都有一个区域设置(就像我们有每个请求的会话一样)并做类似的事情: def set_locale locale = params[:locale] if params[:locale] end 并且默认情况下使用I18n.default_locale 。 这将理想地匹配路径中的可选区域设置: # config/routes.rb scope “(:locale)”, :locale => /en|nl/ do resources :books end 目前,如果出于某种原因我在某些操作中跳过了区域设置,它会使用上一个请求中设置的区域设置,该区域设置可能来自其他用户! 并且不存在潜在的竞争条件,因为一个请求可以更改全局I18n.locale而另一个请求(在I18n.locale之前设置了另一个语言环境)处于渲染的中间? 更新:我现在发现的一些细节,来自I18n文件: 将当前语言环境设置为伪全局,即在Thread.current散列中def locale =(locale) 现在我想了解每个请求是否是一个单独的线程。 更新2:请参阅我的答案以获得解释。

Heroku语言区域设置无法正常工作

它看起来像我在heroku上的语言区域设置不起作用。 On my local mashine : 1. maj Heroku : 01 May 00:00 我的看法: :short %> 地点: en: hello: “Hello world” views: pagination: previous: “« Tilbage” next: “Næste side »” # active_support date: # See http://sproget.dk/svarbase/SV00000046/ and http://en.wikipedia.org/wiki/Date_formats # either use traditional (2.10.03, 2. oktober 2003): “%e.%m.%y”, “%e. %B %Y” # or international ISO 8601 […]

如何在rails上的.yml本地化文件中打破行?

我有一个带有一些本地化的terms.en.yml文件,例如: en: devise: registrations: terms: text: ‘This agreement was written in English (US). To the extent any translated version of this agreement conflicts with the English version, the English version controls. Please note that Section 16 contains certain changes to the general terms for users outside the United States.\n\ Some new line’ 我怎么能在那里打破一条线或创建一个段落? 这里有一些信息,但它对我没有帮助,我做错了。 http://yaml.org/spec/1.1/#b-paragraph-separator

number_to_currency语言环境转换

为什么number_to_currency(33.50, :locale => :fr)显示$ 33.50? 它应该根据区域设置以不同的货币显示。 我期待33,50 €的结果。 非常感谢!