i18n_multitenant 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +4 -0
- data/README.md +8 -1
- data/lib/i18n_multitenant/version.rb +1 -1
- data/lib/i18n_multitenant.rb +4 -4
- data/spec/lib/i18n_multitenant_spec.rb +7 -6
- data/spec/spec_helper.rb +1 -6
- data/spec/support/config/locales/es.yml +1 -0
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7dbda6fcab7fa556f25c5156a8d3fff69e206e353fcaf8f8071522efeeb11b2d
|
4
|
+
data.tar.gz: 83805f25a2147d1a9d0808298053bdc84b9852c8d4e9b26883615bc069a44731
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c6b91eccdde995714c9198b950571d04c1debf75e5da97f94b72996355bb8707fb3fb7cc9a74e1bcc21ac69bed82194ac1c2cc83a7ed1bcaeac40ab94db8b74
|
7
|
+
data.tar.gz: dfe4ba88a27514f7f213794e0f8b995724b421ca915a8e3e3726f27584aee9aabfb1b166a008b084d5a1e120b457560fcbd9a0e26ed0018d48d34864b44ec9ab
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -10,9 +10,16 @@ i18n Multi-Tenant
|
|
10
10
|
This gem is a small utility that provides the basic configuration to perform
|
11
11
|
tenant-specific translations in multi-tenant apps.
|
12
12
|
|
13
|
+
Read more about it in the [blog announcement](https://maximomussini.com/posts/i18n-multitenant/).
|
14
|
+
|
13
15
|
## Setting the locale
|
14
16
|
```ruby
|
15
17
|
I18nMultitenant.set(locale: :en, tenant: 'Tenant Name')
|
18
|
+
|
19
|
+
# Or:
|
20
|
+
I18nMultitenant.with_locale(locale: :en, tenant: 'Tenant Name') do
|
21
|
+
...
|
22
|
+
end
|
16
23
|
```
|
17
24
|
|
18
25
|
## Locale files
|
@@ -47,7 +54,7 @@ you will need to sanitize the names yourself before handing them over to `set`.
|
|
47
54
|
Add this line to your application's Gemfile and run `bundle install`:
|
48
55
|
|
49
56
|
```ruby
|
50
|
-
|
57
|
+
gem 'i18n_multitenant'
|
51
58
|
```
|
52
59
|
|
53
60
|
Or install it yourself running:
|
data/lib/i18n_multitenant.rb
CHANGED
@@ -20,14 +20,14 @@ module I18nMultitenant
|
|
20
20
|
#
|
21
21
|
# I18nMultitenant.set(locale: :es)
|
22
22
|
# => :es
|
23
|
-
def self.set(options)
|
24
|
-
I18n.locale = locale_for(options)
|
23
|
+
def self.set(**options)
|
24
|
+
I18n.locale = locale_for(**options)
|
25
25
|
end
|
26
26
|
|
27
27
|
# Public: Executes block using the specified locale configuration, restoring
|
28
28
|
# it after the block is executed.
|
29
|
-
def self.with_locale(options)
|
30
|
-
I18n.with_locale(locale_for(options)) { yield }
|
29
|
+
def self.with_locale(**options)
|
30
|
+
I18n.with_locale(locale_for(**options)) { yield }
|
31
31
|
end
|
32
32
|
|
33
33
|
# Internal: Get the internal locale for a tenant-specific locale.
|
@@ -11,9 +11,10 @@ RSpec.describe I18nMultitenant do
|
|
11
11
|
}
|
12
12
|
|
13
13
|
describe 'set' do
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
it 'fails on incorrect options' do
|
15
|
+
expect {
|
16
|
+
I18nMultitenant.set(locales: [:en, :es])
|
17
|
+
}.to raise_error(ArgumentError, /unknown keyword: :locales/)
|
17
18
|
end
|
18
19
|
|
19
20
|
context 'setting only the locale' do
|
@@ -33,7 +34,7 @@ RSpec.describe I18nMultitenant do
|
|
33
34
|
|
34
35
|
context 'non existing locale' do
|
35
36
|
Given(:locale) { 'en-US' }
|
36
|
-
Then {
|
37
|
+
Then { result == Failure(I18n::InvalidLocale, /not a valid locale/) }
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -78,7 +79,7 @@ RSpec.describe I18nMultitenant do
|
|
78
79
|
context 'non existing tenant/locale combination' do
|
79
80
|
Given(:locale) { 'en-US' }
|
80
81
|
Given(:tenant) { 'Enterprise' }
|
81
|
-
Then {
|
82
|
+
Then { result == Failure(I18n::InvalidLocale, /"en-US-ENTERPRISE" is not a valid locale/) }
|
82
83
|
end
|
83
84
|
end
|
84
85
|
end
|
@@ -119,7 +120,7 @@ RSpec.describe I18nMultitenant do
|
|
119
120
|
|
120
121
|
context 'non-existing locale' do
|
121
122
|
When(:locale) { I18n.locale = 'en-US' }
|
122
|
-
Then {
|
123
|
+
Then { locale == Failure(I18n::InvalidLocale, /not a valid locale/) }
|
123
124
|
end
|
124
125
|
|
125
126
|
context 'locale and tenant (internal representation)' do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_multitenant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -59,7 +59,7 @@ homepage: https://github.com/ElMassimo/i18n_multitenant
|
|
59
59
|
licenses:
|
60
60
|
- MIT
|
61
61
|
metadata: {}
|
62
|
-
post_install_message:
|
62
|
+
post_install_message:
|
63
63
|
rdoc_options:
|
64
64
|
- "--charset=UTF-8"
|
65
65
|
require_paths:
|
@@ -75,9 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
|
-
|
79
|
-
|
80
|
-
signing_key:
|
78
|
+
rubygems_version: 3.3.7
|
79
|
+
signing_key:
|
81
80
|
specification_version: 4
|
82
81
|
summary: Translation for multi-tenant applications.
|
83
82
|
test_files:
|