{"id":15412530,"url":"https://github.com/elmassimo/i18n_multitenant","last_synced_at":"2025-04-19T03:11:36.759Z","repository":{"id":15733075,"uuid":"78678389","full_name":"ElMassimo/i18n_multitenant","owner":"ElMassimo","description":"🌎 Provides a convenient way to use tenant-specific translations","archived":false,"fork":false,"pushed_at":"2022-02-27T22:06:16.000Z","size":21,"stargazers_count":18,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-14T08:51:35.664Z","etag":null,"topics":["i18n","multi-tenant","rails","ruby","translations"],"latest_commit_sha":null,"homepage":"https://maximomussini.com/posts/i18n-multitenant/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ElMassimo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-11T20:47:35.000Z","updated_at":"2024-06-28T18:55:36.000Z","dependencies_parsed_at":"2022-08-07T08:01:17.877Z","dependency_job_id":null,"html_url":"https://github.com/ElMassimo/i18n_multitenant","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElMassimo%2Fi18n_multitenant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElMassimo%2Fi18n_multitenant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElMassimo%2Fi18n_multitenant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElMassimo%2Fi18n_multitenant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ElMassimo","download_url":"https://codeload.github.com/ElMassimo/i18n_multitenant/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249598073,"owners_count":21297463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["i18n","multi-tenant","rails","ruby","translations"],"created_at":"2024-10-01T16:53:38.286Z","updated_at":"2025-04-19T03:11:36.734Z","avatar_url":"https://github.com/ElMassimo.png","language":"Ruby","readme":"i18n Multi-Tenant\n====================\n\n[![Gem Version](https://badge.fury.io/rb/i18n_multitenant.svg)](http://badge.fury.io/rb/i18n_multitenant)\n[![Build Status](https://github.com/ElMassimo/i18n_multitenant/workflows/test/badge.svg)](https://github.com/ElMassimo/i18n_multitenant/actions)\n[![Test Coverage](https://codeclimate.com/github/ElMassimo/i18n_multitenant/badges/coverage.svg)](https://codeclimate.com/github/ElMassimo/i18n_multitenant/coverage)\n[![Code Climate](https://codeclimate.com/github/ElMassimo/i18n_multitenant/badges/gpa.svg)](https://codeclimate.com/github/ElMassimo/i18n_multitenant)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ElMassimo/i18n_multitenant/blob/master/LICENSE.txt)\n\nThis gem is a small utility that provides the basic configuration to perform\ntenant-specific translations in multi-tenant apps.\n\nRead more about it in the [blog announcement](https://maximomussini.com/posts/i18n-multitenant/).\n\n## Setting the locale 🌎\n\nYou can set a locale globally using:\n\n```ruby\nI18nMultitenant.set(locale: :en, tenant: 'Tenant Name')\n```\n\nIt's usually preferable to set a locale locally by scoping the change to a block: \n\n```ruby\nI18nMultitenant.with_locale(locale: :en, tenant: 'Tenant Name') do\n  # perform translations\nend\n```\n\nFor example, using an `around_action` in Rails:\n\n```ruby\naround_action do\n  I18nMultitenant.with_locale(locale: :en, tenant: 'Tenant Name') { yield }\nend\n```\n\n## Locale files 📝\n\nThe library leverages the use of fallbacks, using the tenant name as a locale variant.\n\nYou can organize the files in nested folders as you find suitable, the only\nrequirement is that the root of a translation file uses the following convention:\n\n```yaml\nlang-TENANT_NAME:\n  ...\n```\n\nFor a few different examples, check out the [locale files used in tests](https://github.com/ElMassimo/i18n_multitenant/tree/master/spec/support/config), but here are few valid roots:\n\n```yaml\nen:\nen-US:\nen-US-TENANT_NAME:\n```\n\nAny name can be passed through the `:tenant` option, and it will be normalized\nto be uppercase and not contain any hyphens, dots, or spaces.\n\nIf you need to use names that are not be valid yml keys even after this process,\nyou will need to sanitize the names yourself before handing them over to `set`.\n\n\n## Installation 💿\n\nAdd this line to your application's Gemfile and run `bundle install`:\n\n```ruby\ngem 'i18n_multitenant'\n```\n\nOr install it yourself running:\n\n```sh\ngem install i18n_multitenant\n```\n\n## Configuration ⚙️\n\nIn Rails everything should be configured out of the box, but you can perform\nthe configuration yourself in other applications by calling:\n\n```ruby\nI18nMultitenant.configure(I18n) # or pass I18n.config\n```\n\n## Front-end Translations\nIf you also need to perform translations in the front-end, you can use a library\nlike [`i18n-js`](https://github.com/fnando/i18n-js). You can easily configure\n`i18n-js` to support multi-tenant translations by leveraging `i18n` itself:\n\n```erb\nI18n.locale = \u003c%= I18n.locale.to_json.html_safe %\u003e;\nI18n.locales[I18n.locale] = \u003c%= I18n.fallbacks[I18n.locale].to_json.html_safe %\u003e\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felmassimo%2Fi18n_multitenant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felmassimo%2Fi18n_multitenant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felmassimo%2Fi18n_multitenant/lists"}