0.0
No commit activity in last 3 years
No release in over 3 years
I18n::Object provides you can get to use wrapper classes for easy handling/testing of I18n by just only configuration.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 10.0
~> 3.0

Runtime

 Project Readme

I18n::Object

I18n::Object provides you can use wrapper classes for easy handling/testing of I18n by just only configuration.

The Value of I18n::Object

This gem resolves these problems:

  • It's not a easy to deal with deep nested YAML files from both product and test codes.
  • We need wrapper class for easy handling/testing of 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.

Installation

  1. Add i18n-object to your Gemfile:
gem 'i18n-object'
  1. Execute this command to generate an initializer:
$ bin/rails generate i18n:object:install
  1. Assign namespaces and prepare locale files:
# 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[
]

License

The gem is available as open source under the terms of the MIT License.