Giter Club home page Giter Club logo

i18n_multitenant's Introduction

i18n Multi-Tenant

Gem Version Build Status Test Coverage Code Climate License

This gem is a small utility that provides the basic configuration to perform tenant-specific translations in multi-tenant apps.

Setting the locale

I18nMultitenant.set(locale: :en, tenant: 'Tenant Name')

# Or:
I18nMultitenant.with_locale(locale: :en, tenant: 'Tenant Name') do
...
end

Locale files

The library leverages the use of fallbacks, using the tenant name as a locale variant.

You can organize the files in nested folders as you find suitable, the only requirement is that the root of a translation file uses the following convention:

lang-TENANT_NAME:
  ...

For a few different examples, check out the locale files used in tests, but here are few valid roots:

en:
en-US:
en-US-TENANT_NAME:

Any name can be passed through the :tenant option, and it will be normalized to be uppercase and not contain any hyphens, dots, or spaces.

If you need to use names that are not be valid yml keys even after this process, you will need to sanitize the names yourself before handing them over to set.

Installation

Add this line to your application's Gemfile and run bundle install:

gem 'i18n_multitenant'

Or install it yourself running:

gem install i18n_multitenant

Configuration

In Rails everything should be configured out of the box, but you can perform the configuration yourself in other applications by calling:

I18nMultitenant.configure(I18n) # or pass I18n.config

Front-end Translations

If you also need to perform translations in the front-end, you can use a library like i18n-js. You can easily configure i18n-js to support multi-tenant translations by leveraging i18n itself:

I18n.locale = <%= I18n.locale.to_json.html_safe %>;
I18n.locales[I18n.locale] = <%= I18n.fallbacks[I18n.locale].to_json.html_safe %>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.