There is also i18n-inflector-rails Rails plug-in which allows to register so called inflection methods in controllers.
These methods will transparently feed the I18n Inflector with data about gender or any other inflection kind you like.
Example:
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}"
And then in controllers:
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