gettext-setup 0.16 → 0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49df38cdb7e32dbfe0aec6c12460aa5b5ea26f85
4
- data.tar.gz: fbed21a4922999e95f06962024d5967d07d5c064
3
+ metadata.gz: 51e24d5a0de0289dfab4f0013cffdd6c753a97f5
4
+ data.tar.gz: 56b6f3143b3be413900d8fac7d409e53b9eb886a
5
5
  SHA512:
6
- metadata.gz: aa1b607f4692eb1b2d489c027f9ac6042c0ed9140bd48690777d267e4905cd2727a7cd7b1a467d6c03d9c2aca58c1207f9e3cceda77e4bc4467a059f637d6805
7
- data.tar.gz: 6d3b4954a99628ad36e6fbb414ab0ed2b068a3f2224c40287779c1ee67eeb62c43f7f5f14ffd7f3bad55821bcc62ddefa8676dc49cba2033b0108b7957507f2e
6
+ metadata.gz: 4b8877f0d9a611c1af3c8bd01e14d1e513cee3a8f8dd65397f9be38ce08fd98880ee09535d5c4a68f6f9780746e37a14704e4140e758da22c7da155b5e76cf48
7
+ data.tar.gz: 3f30f76c29b8e1da5a2a87b43e9e1c1ad83192974b13d05281620b20e549900361812c2f825c06e15a93f7f064f019c10f89229afd76eb2a9ed55319917dcdc2
@@ -5,6 +5,8 @@ require 'locale'
5
5
 
6
6
  module GettextSetup
7
7
  @@config = nil
8
+ @@translation_repositories = {}
9
+ FastGettext.default_available_locales = []
8
10
 
9
11
  # `locales_path` should include:
10
12
  # - config.yaml
@@ -24,19 +26,28 @@ module GettextSetup
24
26
  # Define our text domain, and set the path into our root. I would prefer to
25
27
  # have something smarter, but we really want this up earlier even than our
26
28
  # config loading happens so that errors there can be translated.
27
- FastGettext.add_text_domain(config['project_name'],
28
- :path => locales_path,
29
- :type => options[:file_format] || :po,
30
- :ignore_fuzzy => false)
31
- FastGettext.default_text_domain = config['project_name']
29
+ add_repository_to_chain(config['project_name'], options)
30
+
31
+ # 'chain' is the only available multi-domain type in fast_gettext 1.1.0 We should consider
32
+ # investigating 'merge' once we can bump our dependency
33
+ FastGettext.add_text_domain('master_domain', type: :chain, chain: @@translation_repositories.values)
34
+ FastGettext.default_text_domain = 'master_domain'
32
35
 
33
36
  # Likewise, be explicit in our default language choice.
34
37
  FastGettext.default_locale = default_locale
35
- FastGettext.default_available_locales = locales
38
+ FastGettext.default_available_locales = FastGettext.default_available_locales | locales
36
39
 
37
40
  Locale.set_default(default_locale)
38
41
  end
39
42
 
43
+ def self.add_repository_to_chain(project_name,options)
44
+ repository = FastGettext::TranslationRepository.build(project_name,
45
+ :path => locales_path,
46
+ :type => options[:file_format] || :po,
47
+ :ignore_fuzzy => false)
48
+ @@translation_repositories[project_name] = repository unless @@translation_repositories.key? project_name
49
+ end
50
+
40
51
  def self.locales_path
41
52
  @@locales_path
42
53
  end
@@ -45,6 +56,10 @@ module GettextSetup
45
56
  @@config ||= {}
46
57
  end
47
58
 
59
+ def self.translation_repositories
60
+ @@translation_repositories
61
+ end
62
+
48
63
  def self.default_locale
49
64
  config['default_locale'] || "en"
50
65
  end
@@ -86,12 +101,12 @@ module GettextSetup
86
101
  pair[0] = FastGettext.default_locale if pair[0] == '*'
87
102
  pair
88
103
  end.sort_by do |(locale,qvalue)|
89
- qvalue.to_f
104
+ -1 * qvalue.to_f
90
105
  end.select do |(locale,_)|
91
106
  FastGettext.available_locales.include?(locale)
92
107
  end
93
- if available_locales and available_locales.last
94
- available_locales.last.first
108
+ if available_locales and available_locales.first
109
+ available_locales.first.first
95
110
  else
96
111
  # We can't satisfy the request preference. Just use the default locale.
97
112
  default_locale
@@ -66,13 +66,18 @@ namespace :gettext do
66
66
  old_pot = pot_file_path + ".old"
67
67
  File.rename(pot_file_path, old_pot)
68
68
  generate_new_pot
69
- stdout, stderr, status = Open3.capture3("msgcmp --use-untranslated '#{old_pot}' '#{pot_file_path}'")
70
- if status == 1 || /this message is not used/.match(stderr)
69
+ begin
70
+ _, stderr, status = Open3.capture3("msgcmp --use-untranslated '#{old_pot}' '#{pot_file_path}'")
71
+ if status == 1 || /this message is not used/.match(stderr)
72
+ File.delete(old_pot)
73
+ puts "String changes detected, replacing with updated POT file"
74
+ else
75
+ puts "No string changes detected, keeping old POT file"
76
+ File.rename(old_pot, pot_file_path)
77
+ end
78
+ rescue IOError
79
+ # Ignore; probably means msgcmp isn't installed.
71
80
  File.delete(old_pot)
72
- puts "String changes detected, replacing with updated POT file"
73
- else
74
- puts "No string changes detected, keeping old POT file"
75
- File.rename(old_pot, pot_file_path)
76
81
  end
77
82
  end
78
83
  end
@@ -0,0 +1,25 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) 2016 Puppet Labs, LLC.
3
+ # This file is distributed under the same license as the Sinatra i18n demo package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, 2016.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: alt_locales init-11-ga532a06\n"
10
+ "\n"
11
+ "Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
12
+ "POT-Creation-Date: 2016-06-07 17:38-0500\n"
13
+ "PO-Revision-Date: 2016-06-07 17:38-0500\n"
14
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
15
+ "Language-Team: LANGUAGE <LL@li.org>\n"
16
+ "Language: \n"
17
+ "MIME-Version: 1.0\n"
18
+ "Content-Type: text/plain; charset=UTF-8\n"
19
+ "Content-Transfer-Encoding: 8bit\n"
20
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
21
+
22
+ #. GettextSetup.initialize(File::join(File::dirname(File::dirname(__FILE__)), 'fixtures'))
23
+ #: ../../lib/gettext_setup_spec.rb:25
24
+ msgid "Hello, world!"
25
+ msgstr ""
@@ -0,0 +1,22 @@
1
+ ---
2
+ # This is the project-specific configuration file for setting up
3
+ # fast_gettext for your project.
4
+ gettext:
5
+ # This is used for the name of the .pot and .po files; they will be
6
+ # called <project_name>.pot?
7
+ project_name: 'alt_locales'
8
+ # This is used in comments in the .pot and .po files to indicate what
9
+ # project the files belong to and should bea little more desctiptive than
10
+ # <project_name>
11
+ package_name: alt_locales
12
+ # The locale that the default messages in the .pot file are in
13
+ default_locale: en
14
+ # The email used for sending bug reports.
15
+ bugs_address: docs@puppetlabs.com
16
+ # The holder of the copyright.
17
+ copyright_holder: Puppet Labs, LLC.
18
+ # Patterns for +Dir.glob+ used to find all files that might contain
19
+ # translatable content, relative to the project root directory
20
+ source_files:
21
+ - 'test_translation.rb'
22
+ - '../lib/**/*.rb'
@@ -0,0 +1,23 @@
1
+ # German translations for Sinatra i18n demo package.
2
+ # Copyright (C) 2016 Puppet Labs, LLC.
3
+ # This file is distributed under the same license as the Sinatra i18n demo package.
4
+ # Automatically generated, 2016.
5
+ #
6
+ msgid ""
7
+ msgstr ""
8
+ "Project-Id-Version: Sinatra i18n demo \n"
9
+ "Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
10
+ "POT-Creation-Date: 2016-04-05 10:39-0700\n"
11
+ "PO-Revision-Date: 2016-02-26 18:21-0800\n"
12
+ "Last-Translator: Automatically generated\n"
13
+ "Language-Team: none\n"
14
+ "Language: jp\n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=UTF-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
+
20
+ #: ../app.rb:14
21
+ msgid "Hello, world!"
22
+ msgstr "こんにちは世界"
23
+
@@ -31,6 +31,9 @@ describe GettextSetup do
31
31
  expect(GettextSetup.negotiate_locale('en;q=1, de;q=2')).to eq('de')
32
32
  expect(GettextSetup.negotiate_locale('en;q=1, de;q=0')).to eq('en')
33
33
  end
34
+ it "chooses the first value when q values are equal" do
35
+ expect(GettextSetup.negotiate_locale('de;q=1, en;q=1')).to eq('de')
36
+ end
34
37
  end
35
38
  context 'set_default_locale' do
36
39
  before :each do
@@ -45,10 +48,51 @@ describe GettextSetup do
45
48
  context 'clear' do
46
49
  it "can clear the locale" do
47
50
  expect(GettextSetup.default_locale).to eq('en')
48
- expect(GettextSetup.candidate_locales).to eq('en_US,en')
51
+ expect(GettextSetup.candidate_locales).to include('en')
49
52
  GettextSetup.clear
50
53
  ENV['LANG'] = 'de_DE'
51
54
  expect(GettextSetup.candidate_locales).to eq('de_DE,de,en')
52
55
  end
53
56
  end
57
+ context 'multiple locales' do
58
+ # locales/ loads the de locale and alt_locales/ loads the jp locale
59
+ before(:all) do
60
+ GettextSetup.initialize(File::join(File::dirname(File::dirname(__FILE__)), 'fixtures', 'alt_locales'))
61
+ end
62
+ it 'can aggregate locales across projects' do
63
+ expect(FastGettext.default_available_locales).to include('en','de','jp')
64
+ end
65
+ it 'can switch to loaded locale' do
66
+ FastGettext.locale = GettextSetup.negotiate_locale('de,en')
67
+ expect(FastGettext.locale).to eq('de')
68
+ FastGettext.locale = GettextSetup.negotiate_locale('jp')
69
+ expect(FastGettext.locale).to eq('jp')
70
+ end
71
+ end
72
+ context 'translation repository chain' do
73
+ before(:all) do
74
+ GettextSetup.initialize(File::join(File::dirname(File::dirname(__FILE__)), 'fixtures', 'alt_locales'))
75
+ end
76
+ it 'chain is not nil' do
77
+ expect(GettextSetup.translation_repositories).not_to be_nil
78
+ end
79
+ it 'can translate without switching text domains' do
80
+ FastGettext.locale = "de"
81
+ expect(_('Hello, world!')).to eq('Hallo, Welt!')
82
+ FastGettext.locale = "jp"
83
+ expect(_('Hello, world!')).to eq('こんにちは世界')
84
+ end
85
+ it 'does not allow duplicate repositories' do
86
+ GettextSetup.initialize(File::join(File::dirname(File::dirname(__FILE__)), 'fixtures', 'alt_locales'))
87
+ repos = GettextSetup.translation_repositories
88
+ expect(repos.select { |k,v| k == 'alt_locales' }.size).to eq(1)
89
+ end
90
+ it 'does allow multiple unique domains' do
91
+ GettextSetup.initialize(File::join(File::dirname(File::dirname(__FILE__)), 'fixtures', 'locales'))
92
+ repos = GettextSetup.translation_repositories
93
+ expect(repos.size) == 2
94
+ expect(repos.select { |k,v| k == 'alt_locales' }.size).to eq(1)
95
+ expect(repos.select { |k,v| k == 'sinatra-i18n' }.size).to eq(1)
96
+ end
97
+ end
54
98
  end
metadata CHANGED
@@ -1,181 +1,195 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettext-setup
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.16'
4
+ version: '0.17'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-11 00:00:00.000000000 Z
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: fast_gettext
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - '>='
17
+ - - "~>"
17
18
  - !ruby/object:Gem::Version
18
- version: 3.0.2
19
- name: gettext
20
- prerelease: false
19
+ version: 1.1.0
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.2
26
+ version: 1.1.0
27
27
  - !ruby/object:Gem::Dependency
28
+ name: locale
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
- version: 1.1.0
33
- name: fast_gettext
34
- prerelease: false
33
+ version: '0'
35
34
  type: :runtime
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.0
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: bundler
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - '>='
45
+ - - "~>"
45
46
  - !ruby/object:Gem::Version
46
- version: '0'
47
- name: locale
47
+ version: '1.3'
48
+ type: :development
48
49
  prerelease: false
49
- type: :runtime
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: gettext
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
- - - ~>
59
+ - - ">="
59
60
  - !ruby/object:Gem::Version
60
- version: '1.3'
61
- name: bundler
62
- prerelease: false
61
+ version: 3.0.2
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '1.3'
68
+ version: 3.0.2
69
69
  - !ruby/object:Gem::Dependency
70
+ name: rake
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
- - - '>='
73
+ - - ">="
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0'
75
- name: rake
76
- prerelease: false
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
+ name: rack-test
84
85
  requirement: !ruby/object:Gem::Requirement
85
86
  requirements:
86
- - - '>='
87
+ - - ">="
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
- name: rack-test
90
- prerelease: false
91
90
  type: :development
91
+ prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
+ name: rspec
98
99
  requirement: !ruby/object:Gem::Requirement
99
100
  requirements:
100
- - - ~>
101
+ - - "~>"
101
102
  - !ruby/object:Gem::Version
102
103
  version: '3.1'
103
- name: rspec
104
- prerelease: false
105
104
  type: :development
105
+ prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '3.1'
111
111
  - !ruby/object:Gem::Dependency
112
+ name: rspec-core
112
113
  requirement: !ruby/object:Gem::Requirement
113
114
  requirements:
114
- - - ~>
115
+ - - "~>"
115
116
  - !ruby/object:Gem::Version
116
117
  version: '3.1'
117
- name: rspec-core
118
- prerelease: false
119
118
  type: :development
119
+ prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '3.1'
125
125
  - !ruby/object:Gem::Dependency
126
+ name: rspec-expectations
126
127
  requirement: !ruby/object:Gem::Requirement
127
128
  requirements:
128
- - - ~>
129
+ - - "~>"
129
130
  - !ruby/object:Gem::Version
130
131
  version: '3.1'
131
- name: rspec-expectations
132
- prerelease: false
133
132
  type: :development
133
+ prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ~>
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '3.1'
139
139
  - !ruby/object:Gem::Dependency
140
+ name: rspec-mocks
140
141
  requirement: !ruby/object:Gem::Requirement
141
142
  requirements:
142
- - - ~>
143
+ - - "~>"
143
144
  - !ruby/object:Gem::Version
144
145
  version: '3.1'
145
- name: rspec-mocks
146
- prerelease: false
147
146
  type: :development
147
+ prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ~>
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '3.1'
153
153
  - !ruby/object:Gem::Dependency
154
+ name: simplecov
154
155
  requirement: !ruby/object:Gem::Requirement
155
156
  requirements:
156
- - - '>='
157
+ - - ">="
157
158
  - !ruby/object:Gem::Version
158
159
  version: '0'
159
- name: simplecov
160
- prerelease: false
161
160
  type: :development
161
+ prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - '>='
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
+ name: webmock
168
169
  requirement: !ruby/object:Gem::Requirement
169
170
  requirements:
170
- - - '>='
171
+ - - ">="
171
172
  - !ruby/object:Gem::Version
172
173
  version: '0'
173
- name: webmock
174
+ type: :development
174
175
  prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rubocop
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
175
188
  type: :development
189
+ prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
- - - '>='
192
+ - - ">="
179
193
  - !ruby/object:Gem::Version
180
194
  version: '0'
181
195
  description: A gem to ease i18n
@@ -191,6 +205,9 @@ files:
191
205
  - lib/gettext-setup/gettext_setup.rb
192
206
  - lib/tasks/gettext.rake
193
207
  - locales/config-sample.yaml
208
+ - spec/fixtures/alt_locales/alt_locales.pot
209
+ - spec/fixtures/alt_locales/config.yaml
210
+ - spec/fixtures/alt_locales/jp/alt_locales.po
194
211
  - spec/fixtures/locales/config.yaml
195
212
  - spec/fixtures/locales/de/sinatra-i18n.po
196
213
  - spec/fixtures/locales/sinatra-i18n.pot
@@ -200,29 +217,33 @@ homepage: https://github.com/puppetlabs/gettext-setup-gem
200
217
  licenses:
201
218
  - Apache-2.0
202
219
  metadata: {}
203
- post_install_message:
220
+ post_install_message:
204
221
  rdoc_options: []
205
222
  require_paths:
206
223
  - lib
207
224
  required_ruby_version: !ruby/object:Gem::Requirement
208
225
  requirements:
209
- - - '>='
226
+ - - ">="
210
227
  - !ruby/object:Gem::Version
211
- version: '0'
228
+ version: 1.9.2
212
229
  required_rubygems_version: !ruby/object:Gem::Requirement
213
230
  requirements:
214
- - - '>='
231
+ - - ">="
215
232
  - !ruby/object:Gem::Version
216
233
  version: '0'
217
234
  requirements: []
218
- rubyforge_project:
219
- rubygems_version: 2.4.5
220
- signing_key:
235
+ rubyforge_project:
236
+ rubygems_version: 2.5.1
237
+ signing_key:
221
238
  specification_version: 4
222
239
  summary: A gem to ease internationalization with fast_gettext
223
240
  test_files:
224
- - spec/spec_helper.rb
241
+ - spec/fixtures/alt_locales/alt_locales.pot
242
+ - spec/fixtures/alt_locales/config.yaml
243
+ - spec/fixtures/alt_locales/jp/alt_locales.po
225
244
  - spec/fixtures/locales/config.yaml
226
- - spec/fixtures/locales/sinatra-i18n.pot
227
245
  - spec/fixtures/locales/de/sinatra-i18n.po
246
+ - spec/fixtures/locales/sinatra-i18n.pot
228
247
  - spec/lib/gettext_setup_spec.rb
248
+ - spec/spec_helper.rb
249
+ has_rdoc: