例如从英语翻译成法语
submit: create: 'Create %{model}' update: 'Update %{model}' submit: 'Save %{model}'
会成为
submit: create: "Créer un(e) %{model}" update: "Modifier ce(tte) %{model}" submit: "Enregistrer ce(tte) %{model}"
在括号(性别化)中实现文本的最佳方法是使用任何传递的模型.
谢谢!
解决方法
还有
i18n-inflector-rails Rails插件,允许在控制器中注册所谓的拐点方法.
这些方法将透明地向I18n Inflector提供有关性别或任何其他您喜欢的变形类型的数据.
例:
fr: i18n: inflections: gender: h: "hommes" f: "femmes" n: "neutre" m: @h default: n welcome: "@{h,n:Cher|f:Chère|Bonjour}{ }{h:Monsieur|f:Dame|n:Vous|à tous}"
然后在控制器中:
class ApplicationController < ActionController::Base before_filter :set_gender inflection_method :gender # inflection method for the kind gender def gender @gender end def set_gender if user_signed_in? # assuming Devise is in use @gender = current_user.gender # assuming there is @gender attribute else @gender = nil end end end class UsersController < ApplicationController def say_welcome t('welcome') # => "Cher Vous" (for empty gender or gender == :n) # => "Chère Dame" (for gender == :f) # etc. end end