translating from English to French for example
submit:
create: 'Create %{model}'
update: 'Update %{model}'
submit: 'Save %{model}'
would become
submit:
create: "Créer un(e) %{model}"
update: "Modifier ce(tte) %{model}"
submit: "Enregistrer ce(tte) %{model}"
What is the best way to implement the text in parenthesis (genderized) to work with any model passed. Thanks!
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
Take a look to i18n-inflector, it seems an interesting project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With