Project

dry_i18n

0.01
No commit activity in last 3 years
No release in over 3 years
Don't repeat yourself translating over and over common words you use for your project. Translate them once, and then you'll be able to reuse them directly on the I18n yml file
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

~> 1.11
~> 0.7.0
~> 10.0
~> 3.0
 Project Readme

DryI18n

Installation

Add this line to your application's Gemfile:

gem 'dry_i18n'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dry_i18n

Usage

With this Gem you'll be able tu reuse i18n key translations, avoiding in this way to repeat yourself.

Basically you just need to wrap the key you want to reuse with the markup @[key]

If the key you are reusing has interpolations, you just need to add a coma and pass a hash with the interpolation values @[key,{foo: 'foo', bar: 'bar'}]

You don't have to worry about the order you declare the keys on the yml files

###Some examples of usage:

1.- Basic reuse

en:
    secondary_key: "secondary key"
    main_key: "I am a main key which reuse a @[secondary_key]"
I18n.t("main_key") = "I am a main key which reuse a secondary key"

2.- Reusing with interpolation

en:
    secondary_key: "secondary key with %{interpolation}"
    main_key: "I am a main key which reuse a @[secondary_key,{interpolation: 'interpolation'}]"
I18n.t("main_key") = "I am a main key which reuse a secondary key with interpolation"

3.- Reusing with nested keys with or without interpolation

en:
    nth_key: "nested key with %{interpolation}"
    secondary_key: "secondary key with %{interpolation} and a @[nth_key,{interpolation: 'interpolation'}]"
    main_key: "I am a main key which reuse a @[secondary_key,{interpolation: 'interpolation'}], and it's own %{interpolation}"
I18n.t("main_key",{interpolation: 'interpolation'}) =
"I am a main key which reuse a secondary key with interpolation and a nested key with interpolation, and its own interpolation"

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/NachoPal/dry_i18n.

License

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