No release in over 3 years
Low commit activity in last 3 years
I18n interpolation support for nested values
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 5.1
~> 0.9

Runtime

~> 1.2
 Project Readme

i18n-interpolate_nested

Enables nested values when using I18n interpolation:

# config/locales/en.yml
en:
  greeting: "Hello, %{user.name}!"
user = OpenStruct.new(name: "Matz")
I18n.t(:greeting, user: user) # == "Hello, Matz!"

Interpolation keys are split into individual symbols (e.g. :user and :name in the above example), and passed to the #[] method of each nesting object. Thus, interpolation works with nested Hashes, Structs, OpenStructs, Active Record objects, etc.

Installation

Add the gem to your Gemfile:

$ bundle add i18n-interpolate_nested

If you are not using Rails, you will also need to invoke I18n::InterpolateNested::init in order to hook this gem into I18n:

require "i18n/interpolate_nested"

I18n::InterpolateNested.init

Contributing

Run bin/test to run the tests.

License

MIT License