MultiFormalI18nTenancy <img src=“https://secure.travis-ci.org/Applicat/multi_formal_i18n_tenancy.png” /> <img src=“https://codeclimate.com/badge.png” /> <img src=“https://gemnasium.com/Applicat/multi_formal_i18n_tenancy.png?travis”/>

This gem extend the standard i18n backend (I18n::Backend::Simple) to introduce Conventions over configuration about 2 new types of locale files:

*_formal.yml

Given you want to offer your users the option to be addressed formally or informally through a session locale switch:

I18n.locale = :de # or :de_formal

So this is a DRY solution for the workaround about having duplication of de locales in the de_formal namespace even though informal & formal translation are the same.

This locale file owns all translations from its base *.yml and lets you override them through the same translation keys (except of the deviant locale namespaces de and de_formal at the beginning).

#locales_path/tenants/your_tenant_name/**/your_tenant_name.yml

Given you want to have tenant specific locales through a session locale switch:

I18n.locale :your_tenant_name_de # or :your_tenant_name_de_formal

(‘Your Tenant Name’.parameterize.gsub(‘-’, ‘_’) + ‘_de’).to_sym == :your_tenant_name_de

<strong>Precondition:</strong> Assure that you recursively add locale files to i18n’s locale path e.g. through your Rails 3 application.rb:

config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]

This locale file owns all translations from its base *.yml and optional *_formal.yml under #locales_path/tenants/your-tenant-name/ (recurively) and lets you override them through the same translation keys (except of the deviant locale namespaces de and de_formal at the beginning).

Installation

Add this to your Gemfile and run the bundle command.

gem "multi_formal_i18n_tenancy"

The gem (= engine) will automatically set the backend for your Rails application.

OPTIONAL: you have to manually set the i18n backend for your non-rails Ruby application:

I18n.backend = MultiFormalI18nTenancy::Backend.new

Wiki Docs

Compatibility

Tested on MacOS with: Rails 3.1 & Ruby 1.9.2, Rails 3.2.6 & Ruby 1.9.3.

Future =

  • Support of more backends than only standard simple one

Contribution

Just follow the screencast of Ryan Bates on railscasts.com:

http://railscasts.com/episodes/300-contributing-to-open-source

Add a description about your changes to CHANGELOG.md under section multi_formal_i18n_tenancy (unreleased).

License

This project uses MIT-LICENSE.