Tag: 国际化

Twitter引导Rails 3中的语言环境选择器下拉列表

我在一般的Bootstrapped Rails 3应用程序中有一个非Bootstrapped语言环境选择器,我想要Bootstrap-ify。 关于如何在下拉菜单中的表单中创建(我假设)无序列表,我有点难过。 TL; DR转到此问题底部的编辑3以获取已完成的解决方案。 当前代码以下列方式实现: 应用程序/视图/布局/ _header.html.haml %header.navbar.navbar-fixed-top .navbar-inner .container # … %nav %ul.nav.pull-right # … %li= render ‘layouts/locale_selector’, controller: controller, action: action # (controller, action params passed in from application.html.haml) 应用程序/视图/布局/ _locale_selector.html.haml = form_tag({ controller: controller, action: action }, method: ‘get’, class: ‘locale’) do = select_tag ‘set_locale’, options_for_select(locale_languages, I18n.locale) = hidden_field_tag ‘page’, […]

路由:无法获取默认范围(:locale)以使用user_path(id),始终必须明确提交区域设置

我已经对这个话题进行了一些研究,但我似乎无法弄明白。 我已经按照官方指南设置了I18n,但是我没有正确设置默认语言环境(当没有指定明确的语言环境时)。 # routes.rb require ‘sidekiq/web’ Iq::Application.routes.draw do scope “(:locale)”, locale: /de|en/ do # … end end # application_controller.rb class ApplicationController I18n.locale }) end end 在OS X控制台中: $ rake routes | grep user … user GET (/:locale)/users/:id(.:format) users#show {:locale=>/de|en/} … 在Rails控制台中: $ Rails c $ app.users_path => “/users” app.users_path locale: :de => “/de/users” $ app.user_path […]

动态添加到I18N的翻译

我添加了人工资金访问器,如下所述: 在Ruby on Rails表单中输入数字时的小数和逗号 现在,我的模型中有两个属性用于相同类型的数据:原始版本和人类可读版本。 问题:由于我使用的是activerecord-translation-yml-files,我必须为原始属性和humanized_attribute添加相同的翻译,因为我的表单显示了humanized_attribute的名称,但是在validation错误时,原始名称属性显示。 是否可以动态添加翻译? 这样我可以在调用humanized_accessor-class-method时为字段的人性化版本添加翻译,从yml文件中获取原始翻译字符串,而不是将它们(具有相同的值)写入yml -file,只是为了让DRY更多。

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 3 – 多种货币

如果我这样做: number_to_currency(100,:locale=>’en-GB’) 我希望得到这样的东西: £100.00 但相反,我得到了 $100 如果我传入语言环境,这是相同的:en,’fr-FR’或其他。 Rails是否有基于区域设置的默认货币列表,或者我是否必须自己为地球上的每个国家设置I18映射? 任何帮助赞赏。 托宾

启动轨道I18n和url助手似乎将区域设置与id混淆

我刚刚开始尝试更新我们的rails 3.2应用程序以实现国际化。 我在路线中有一个可选的范围,比如 范围“(:locale)”,locale:/ en | es | zh-HK | de | fr / do 如http://guides.rubyonrails.org/i18n.html所述 。 我的url助手就像 watch_url(@watch) 在表单中获取错误 没有路由匹配{:action =>“show”,:controller =>“watches”,:locale =>#”“,”收件人“ =>“”,“attributes”=>“”},状态:{},隐藏:false,评论:“”>} 关于它为什么会发生以及我如何解决它的任何想法? 谢谢! 编辑: 在我的应用程序控制器中,我有 before_filter :set_locale def set_locale I18n.locale = params[:locale] || I18n.default_locale end 和手表控制器的路线(这是一个8岁的专有应用程序,我们有100多个控制器:(,所以我不会包括所有路线)… $ rake routes | grep watch watches GET (/:locale)/watches(.:format) watches#index {:locale=>/en|es|zh-HK|de|fr/} POST (/:locale)/watches(.:format) watches#create {:locale=>/en|es|zh-HK|de|fr/} […]

18n_routing并重定向到正确的URL

我在Rails 3中开发了一个关于食物和食谱的多语言社交网络。 我使用了http://github.com/kwi/i18n_routing中的i18n_routing gem。 一切正常,但我们遇到了问题。 如果用户(使用英文版)共享一个项目,例如在Facebook上,我们得到一个这样的URL: http : //domain.com/en/the-best-food-recipe/recipes/123 。 现在,如果另一个用户使用意大利语登录并单击该URL,则社交网络将以英语打开,即使我有用户会话并且我知道他的语言是意大利语。 有没有办法将URL翻译回意大利语,以便我可以轻松地将用户重定向到: http : //domain.com/it/the-best-food-recipe/ricette/123 ? 提前致谢

围绕`mount`的`scope`无效?

(虽然这讨论了Blacklight引擎,但我相信这个问题实际上纯粹是关于Rails。) 我正在尝试为我的Blacklight应用添加国际化。 为此,我 将config/routes.rb所有内容config/routes.rb到scope “(:locale)”, locale: /en|ja/ ,和 在app/controllers/application_controller.rb我添加了before_action :set_locale并覆盖了default_url_options 正如Rails i18n指南所建议的那样。 大多数事情都有效,但有一点我无法弄清楚。 我的所有应用程序路由都已正确映射,例如http://www.example.com/en/catalog/12345正确匹配(/:locale)/catalog/:id(.:format) ,并被路由到catalog#show用{:id=>/[^\/]+(?=\.json|\.html|$|\/)/, :locale=>/en|ja/} )显示。 所有Devise的url都很好。 一切正常……除了mount Blacklight引擎。 显然,Blacklight引擎不听scope 。 rake routes显示: Routes for Blacklight::Engine: search_history GET /search_history(.:format) search_history#index …. 而不是(:locale)/search_history(.:format) ,我希望如此。 我修改了Blacklight模板,以便我得到一个语言选择器,用日语和英语指向当前页面,但是当我导航到search_history , url_for在面对:locale参数时突然抛出。 为什么mount会忽略scope ? 如何解决我的问题(引擎路由也响应:locale )? 这是我默认的Blacklight生成的config/routes.rb ,用scope修改: Rails.application.routes.draw do scope “(:locale)”, locale: /en|ja/ do mount Blacklight::Engine => ‘/’ root […]

Gem Spree_i18n在服务器启动时抛出错误:无法加载翻译

的Gemfile: gem ‘spree’, ‘1.2.0’ #:git => ‘git://github.com/spree/spree.git’ gem ‘spree_auth_devise’, :git => ‘git://github.com/spree/spree_auth_devise’ # original repository not compatible at the moment, use fork # gem ‘spree_i18n’, :git => ‘git://github.com/spree/spree_i18n.git’ gem ‘spree_i18n’, :git => ‘git://github.com/kares/spree_i18n.git’ application.rb中: config.i18n.default_locale = :de Spree.rb :(初学者 ) Spree.config do |config| … config.default_locale = “de” end 还有什么: 我已将所有可能的语言yml文件复制到app / config / locale 我跑了“ […]

在RoR中构建翻译的有效方法?

我希望有人可以看一下,因为我之前从未翻译过任何英文,所以我不确定是否会有语法冲突。 我有: en: articles: name: “Articles” comments: name: “Comments” # things no_results: “There are no %{things}” my: “My %{things}” 然后在视图文件中,例如: #title= t(‘articles.name’) %ul %li= link_to t(‘my’, things: t(‘articles.name’)), articles_path(user) .no_results= t(‘no_results’, things: t(‘comments.name’).downcase) 我正在尝试做的是干掉我的翻译,但也没有使用方法搞得一团糟: 变复数 singularize downcase 利用 在文本中使用时,似乎最常见的模型forms是大写和多元化,这就是我选择“文章”与“文章”或“文章”的原因。 您是否支持视图文件中的上述方法,例如: articles: one: “Article” other: “Articles” ..可能会发展成这个烂摊子: articles: one: “Article” other: “Articles” one_l: “article” other_l: “articles”