• Stars
    star
    16
  • Rank 1,266,202 (Top 26 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🌎 Provides a convenient way to use tenant-specific translations

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.

Read more about it in the blog announcement.

Setting the locale 🌎

You can set a locale globally using:

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

It's usually preferable to set a locale locally by scoping the change to a block:

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

For example, using an around_action in Rails:

around_action do
  I18nMultitenant.with_locale(locale: :en, tenant: 'Tenant Name') { yield }
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 %>

More Repositories

1

vite_ruby

⚑️ Vite.js in Ruby, bringing joy to your JavaScript experience
Ruby
1,124
star
2

iles

🏝 The joyful site generator
TypeScript
1,043
star
3

vite-plugin-image-presets

πŸ–Ό Image Presets for Vite.js apps
TypeScript
243
star
4

vite-plugin-environment

Easily expose environment variables in Vite.js
TypeScript
132
star
5

vite-plugin-full-reload

♻️ Automatically reload the page when files are modified
JavaScript
121
star
6

oj_serializers

⚑️ Faster JSON serialization for Ruby on Rails. Easily migrate away from Active Model Serializers.
Ruby
98
star
7

js_from_routes

πŸ›£οΈ Generate path helpers and API methods from your Rails routes
Ruby
86
star
8

request_store_rails

πŸ“¦ Per-request global storage for Rails prepared for multi-threaded apps
Ruby
83
star
9

types_from_serializers

βœ… Generate TypeScript interfaces from your JSON serializers
Ruby
71
star
10

vuex-stores

πŸ—„ Store objects for Vuex, a simple and more fluid API for state-management.
JavaScript
63
star
11

vue-custom-element-example

An example on how to define custom elements using Vue 3
TypeScript
54
star
12

mongoid_includes

🌿 Improves eager loading support for Mongoid
Ruby
46
star
13

jekyll-vite

⚑️🩸 Use Vite.js in Jekyll as your assets pipeline
Ruby
44
star
14

queryable

❔ Gives your queries a home and avoid tucking scopes inside your models
Ruby
42
star
15

vite-plugin-stimulus-hmr

⚑️ HMR for Stimulus controllers in Vite.js
TypeScript
42
star
16

stimulus-vite-helpers

Helpers to easily load all your Stimulus controllers when using Vite.js
TypeScript
37
star
17

capybara-compose

βœ… Easily write fluent integration tests with Capybara in Ruby
Ruby
31
star
18

better_settings

βš™ Settings for Ruby apps – fast, immutable, better.
Ruby
20
star
19

vite-plugin-bugsnag

Report builds and upload source maps to Bugsnag
TypeScript
18
star
20

vite-plugin-manifest-sri

Subresource Integrity for Vite.js manifest files
JavaScript
13
star
21

resourcerer

✨ Works like magic to dry up your controllers
Ruby
10
star
22

sublime-toggle-dark-mode

🌚🌞 Toggle between dark and light mode in Sublime Text 4
JavaScript
9
star
23

pakiderm

🐘 Pakiderm will never forget the return value
Ruby
7
star
24

presenter_rails

πŸ”­ Expose your view models in a convenient way
Ruby
6
star
25

vite-plugin-erb

Use ERB files in Vite.js projects with a Ruby backend
TypeScript
5
star
26

journeyman

Let your factories use your business logic, making them flexible and easier to update.
Ruby
5
star
27

jekyll-vite-minima

⚑️🩸 Use Vite.js in Jekyll minima theme as your assets pipeline
Ruby
3
star
28

automatic-music-transcription

Automatically exported from code.google.com
C
2
star
29

vite-plugin-xdm

Use XDM in VIte.js
JavaScript
2
star
30

crouton

🍞 Context sensitive notifications for Rails
Ruby
1
star
31

fast-food-mvc

Automatically exported from code.google.com
C#
1
star
32

ElMassimo

1
star
33

vite-vue-router-hmr-repro

Vue
1
star