I18n::Object provides you can get to use wrapper classes for easy handling/testing of I18n by just only configuration.
MIT License
I18n::Object
provides you can use wrapper classes for easy handling/testing of I18n by just only configuration.
This gem resolves these problems:
I18n#translate
to avoid TYPOs and translation missings!!This i18n-object
provides you can get to use wrapper classes just only assign namespaces in the initializer file:
# config/initializers/i18n_object.rb
I18n::Object.namespaces = %w[
notification
slack_notificaiton/admin
slack_notificaiton/consumer
]
And you have to define YAML files on config/locales
like this:
en:
notification:
say: Hi, %{name}!
slack_notification:
admin:
say: Hi, admin!
consumer:
say: Hi, consumer!
Then you can use wrapper classes:
Notificaiton.say(name: 'alice') # Hi, alice!
SlackNotification::Admin.say # Hi, admin!
SlackNotification::Consumer.say # Hi, consumer!
Notification.hello # No Method Error
Finally you can get relief from pain of TYPOs and translation missings.
i18n-object
to your Gemfile
:gem 'i18n-object'
$ bin/rails generate i18n:object:install
# Assign I18n Object names:
#
# e.g.)
#
# I18n::Object.namespaces = %w[
# notification
# slack_notificaiton/admin
# slack_notificaiton/consumer
# ]
#
# en:
# notification:
# say: Hi, %{name}!
# slack_notification:
# admin:
# say: Hi, admin!
# consumer:
# say: Hi, consumer!
#
# Notificaiton.say(name: 'alice') # Hi, alice!
# Notification.hello # NoMethodError
# SlackNotification::Admin.say # Hi, admin!
# SlackNotification::Consumer.say # Hi, consumer!
I18n::Object.namespaces = %w[
]
The gem is available as open source under the terms of the MIT License.