Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonathanhefner/i18n-interpolate_nested
I18n interpolation support for nested values
https://github.com/jonathanhefner/i18n-interpolate_nested
i18n rails ruby ruby-on-rails
Last synced: 16 days ago
JSON representation
I18n interpolation support for nested values
- Host: GitHub
- URL: https://github.com/jonathanhefner/i18n-interpolate_nested
- Owner: jonathanhefner
- License: mit
- Created: 2018-07-03T01:36:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-18T17:36:02.000Z (over 1 year ago)
- Last Synced: 2024-10-10T03:21:35.421Z (about 1 month ago)
- Topics: i18n, rails, ruby, ruby-on-rails
- Language: Ruby
- Size: 48.8 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# i18n-interpolate_nested
Enables nested values when using I18n interpolation:
```yaml
# config/locales/en.yml
en:
greeting: "Hello, %{user.name}!"
``````ruby
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:
```bash
$ 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:```ruby
require "i18n/interpolate_nested"I18n::InterpolateNested.init
```## Contributing
Run `bin/test` to run the tests.
## License
[MIT License](MIT-LICENSE)