multi_formal_i18n_tenancy 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -6,7 +6,7 @@ This gem extend the standard i18n backend (I18n::Backend::Simple) to introduce {
6
6
 
7
7
  <b>1 ) *_formal.yml</b>
8
8
 
9
- Given you want to offer your users the option to be addressed formally or informally through a {session locale switch}[http://https://github.com/Applicat/multi_formal_i18n_tenancy#Backend Locale Switch]:
9
+ Given you want to offer your users the option to be addressed formally or informally through a {session locale switch}[https://github.com/Applicat/multi_formal_i18n_tenancy#backend-locale-switch]:
10
10
 
11
11
  Then this is a {DRY}[http://en.wikipedia.org/wiki/Don%27t_repeat_yourself] solution for the workaround about having duplication of de locales in the de_formal namespace even though informal & formal translation are the same.
12
12
 
@@ -14,7 +14,7 @@ This locale file will own all translations from its base *.yml and lets you over
14
14
 
15
15
  <b>2 ) #{locales_path}/tenants/your_tenant_name/**/your_tenant_name.yml</b>
16
16
 
17
- Given you want to have tenant specific locales through a {session locale switch}[http://https://github.com/Applicat/multi_formal_i18n_tenancy#Backend Locale Switch]:
17
+ Given you want to have tenant specific locales through a {session locale switch}[https://github.com/Applicat/multi_formal_i18n_tenancy#backend-locale-switch]:
18
18
 
19
19
  <b>Precondition:</b> Assure that you recursively add locale files to i18n's locale path e.g. through your Rails 3 application.rb:
20
20
 
@@ -75,7 +75,7 @@ Dependency: https://github.com/iain/http_accept_language
75
75
  locale ||= I18n.default_locale
76
76
 
77
77
  unless Settings.tenant.name == 'global'
78
- locale = ("#{Settings.tenant.name}_#{locale}").to_sym
78
+ locale = ("#{Settings.tenant.name.parameterize.gsub('-', '_')}_#{locale}").to_sym
79
79
  end
80
80
  end
81
81
 
@@ -91,7 +91,6 @@ Tested on MacOS with: Rails 3.1 & Ruby 1.9.2, Rails 3.2.6 & Ruby 1.9.3.
91
91
 
92
92
  = Future
93
93
 
94
- * automatically add an before filter to rails controller which includes the tenant scope in the locale
95
94
  * Support of more backends than only standard simple one
96
95
 
97
96
  == Contribution
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/string/inflections'
2
+ require 'active_support/core_ext/hash/deep_merge'
2
3
 
3
4
  module MultiFormalI18nTenancy
4
5
  end
@@ -56,8 +56,9 @@ class MultiFormalI18nTenancy::Backend < I18n::Backend::Simple
56
56
 
57
57
  # de_formal > your_enterprise_name_de
58
58
  base_locale = locale.to_s.gsub(FORMAL_LOCALE_PATTERN, '')
59
- base_translations = (translations[base_locale.to_sym] || {}).clone.deep_symbolize_keys # deep_symbolize_keys?
60
- translations[locale].deep_merge!(base_translations)
59
+ base_translations = (translations[base_locale.to_sym] || {}).clone.deep_symbolize_keys
60
+
61
+ translations[locale] = base_translations.deep_merge(translations[locale])
61
62
  elsif tenant
62
63
  base_locale.gsub!(/^#{tenant}_/, '')
63
64
  else
@@ -116,7 +117,7 @@ class MultiFormalI18nTenancy::Backend < I18n::Backend::Simple
116
117
  deepest_available_locale || I18n.default_locale
117
118
  end
118
119
 
119
- private
120
+ #private
120
121
 
121
122
  def tenant_from_locale?(locale)
122
123
  tenant = locale.to_s.gsub(FORMAL_LOCALE_PATTERN, '').split('_')
@@ -130,4 +131,16 @@ class MultiFormalI18nTenancy::Backend < I18n::Backend::Simple
130
131
 
131
132
  tenant && @filenames.select{|f| f.match("/tenants/#{tenant}/")}.any? ? tenant : nil
132
133
  end
134
+
135
+ def delete_right_key_if_left_has_key(left_hash, right_hash)
136
+ right_hash.each do |key,value|
137
+ next unless left_hash.has_key?(key)
138
+
139
+ if value.is_a?(Hash)
140
+ delete_right_key_if_left_has_key(left_hash[key], value)
141
+ else
142
+ right_hash.delete(key) if left_hash.has_key?(key)
143
+ end
144
+ end
145
+ end
133
146
  end
@@ -1,3 +1,3 @@
1
1
  module MultiFormalI18nTenancy
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/spec/fixtures/de.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  de:
2
2
  formal_available: 'Du'
3
3
  formal_unavailable: 'Du'
4
+ de_formal_formal_available: 'Du'
@@ -1,2 +1,3 @@
1
1
  de_formal:
2
- formal_available: 'Sie'
2
+ formal_available: 'Sie'
3
+ de_formal_formal_available: 'Sie'
@@ -23,8 +23,10 @@ describe MultiFormalI18nTenancy::Backend do
23
23
  it 'returns the formal translation' do
24
24
  I18n.locale = :de
25
25
  I18n.t('formal_available').should == 'Du'
26
+ I18n.t('de_formal_formal_available').should == 'Du'
26
27
  I18n.locale = :de_formal
27
28
  I18n.t('formal_available').should == 'Sie'
29
+ I18n.t('de_formal_formal_available').should == 'Sie'
28
30
  end
29
31
  end
30
32
 
@@ -41,8 +43,10 @@ describe MultiFormalI18nTenancy::Backend do
41
43
  it 'returns the formal translation' do
42
44
  I18n.locale = :your_tenant_name_de
43
45
  I18n.t('formal_available').should == 'Du auch'
46
+ I18n.t('de_formal_formal_available').should == 'Du'
44
47
  I18n.locale = :your_tenant_name_de_formal
45
48
  I18n.t('formal_available').should == 'Sie auch'
49
+ I18n.t('de_formal_formal_available').should == 'Sie'
46
50
  end
47
51
  end
48
52
 
@@ -189,4 +193,25 @@ describe MultiFormalI18nTenancy::Backend do
189
193
  end
190
194
  end
191
195
  end
196
+ =begin
197
+ describe '#delete_right_key_if_left_key' do
198
+ include_context :all_locale_file_constellations
199
+
200
+ it 'principally works' do
201
+ I18n.backend = MultiFormalI18nTenancy::Backend.new
202
+
203
+ left_hash = { key_1: 'value 1', key_2: { key_2_1: 'value 2.1' }}
204
+ right_hash = { key_1: 'value 2', key_2: { key_2_1: 'value 2.1 a', key_2_2: 'value 2.2' } }
205
+
206
+ #I18n.backend.delete_right_key_if_left_key(left_hash, right_hash)
207
+
208
+ #left_hash.deep_merge!(right_hash)
209
+ left_hash = right_hash.deep_merge(left_hash)
210
+
211
+ left_hash[:key_1].should == 'value 1'
212
+ left_hash[:key_2][:key_2_1].should == 'value 2.1'
213
+ left_hash[:key_2][:key_2_2].should == 'value 2.2'
214
+ end
215
+ end
216
+ =end
192
217
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_formal_i18n_tenancy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-13 00:00:00.000000000 Z
12
+ date: 2012-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70220249428440 !ruby/object:Gem::Requirement
16
+ requirement: &70348032887440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70220249428440
24
+ version_requirements: *70348032887440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70220249426980 !ruby/object:Gem::Requirement
27
+ requirement: &70348032885840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 2.11.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70220249426980
35
+ version_requirements: *70348032885840
36
36
  description: Your formal locales will inherit translations from their base locale
37
37
  and locales stored in an enterprise folder can override base + formal translations
38
38
  email:
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  segments:
78
78
  - 0
79
- hash: 2083026653359506385
79
+ hash: -2510370042609232382
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  segments:
87
87
  - 0
88
- hash: 2083026653359506385
88
+ hash: -2510370042609232382
89
89
  requirements: []
90
90
  rubyforge_project:
91
91
  rubygems_version: 1.8.17