gettext-setup 0.20 → 0.21

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: d7e38f366af80d198454018ed027f8cd39040989
4
- data.tar.gz: e51b0feb490ce576d595847018c13ba63a482ce7
3
+ metadata.gz: b248dce3a387753f61e2e062421ae04cc466aa5b
4
+ data.tar.gz: 68b67f382958948a1185cb81c91336668da56780
5
5
  SHA512:
6
- metadata.gz: 59bf78ab3acf525cb9d3c0f038645fe9f8f89e05536fe596f48824db6ed4e1a364f67baaccd67653f4d4da28d7b76d0cb05564d9181f5053ef35bd77c2570347
7
- data.tar.gz: fa84ab8b31e2a12e1f95a2ed2cfd26cf146a32c2ea88dfb018cfd8bf48e5dc2376e35cb5819f6d6468a0518f960080e2b6b03d63170687c30af49fce8bc05c7c
6
+ metadata.gz: 8a80db6aecd41ccc0c21e5f8b901cc89a292a7389ea63c207440bdd9b52a1f46be57fbcf5de936d42ba3f34e2b940a4b15a9b99689276f0ad5acfd30d13bf187
7
+ data.tar.gz: 3132f258171d67558835213f5c23568dcbea6d664a5881c08d59d08d1da09aefc9bc3e89925c719e307e81bd1b38777e2857220dd768f169c391fcfcc45f821d
@@ -2,56 +2,12 @@
2
2
  # puts File.absolute_path('Gemfile', Dir.pwd)
3
3
  # Bundler.read_file(File.absolute_path('Gemfile', Dir.pwd))
4
4
  #
5
- require 'open3'
6
5
  require_relative '../gettext-setup/gettext_setup'
6
+ require_relative 'task_helper.rb'
7
7
  #
8
8
  # GettextSetup.initialize(File.absolute_path('locales', Dir.pwd))
9
9
 
10
10
  namespace :gettext do
11
- def locale_path
12
- GettextSetup.locales_path
13
- end
14
-
15
- def text_domain
16
- FastGettext.text_domain
17
- end
18
-
19
- def files_to_translate
20
- files = GettextSetup.config['source_files'].map do |p|
21
- Dir.glob(p)
22
- end.flatten
23
- # check for optional list of files to exclude from string
24
- # extraction
25
- exclusions = (GettextSetup.config['exclude_files'] || []).map do |p|
26
- Dir.glob(p)
27
- end.flatten
28
-
29
- # if file is a directory, take it out of the array. directories
30
- # cause rxgettext to error out.
31
- (files - exclusions).reject { |file| File.directory?(file) }
32
- end
33
-
34
- def pot_file_path
35
- File.join(locale_path, GettextSetup.config['project_name'] + '.pot')
36
- end
37
-
38
- def generate_new_pot
39
- config = GettextSetup.config
40
- package_name = config['package_name']
41
- project_name = config['project_name']
42
- bugs_address = config['bugs_address']
43
- copyright_holder = config['copyright_holder']
44
- # Done this way to allow the user to enter an empty string in the config.
45
- comments_tag = config.key?('comments_tag') ? config['comments_tag'] : 'TRANSLATORS'
46
- version = `git describe`
47
- system("rxgettext -o locales/#{project_name}.pot --no-wrap --sort-by-file " \
48
- "--add-comments#{comments_tag.to_s == '' ? '' : '=' + comments_tag} --msgid-bugs-address '#{bugs_address}' " \
49
- "--package-name '#{package_name}' " \
50
- "--package-version '#{version}' " \
51
- "--copyright-holder='#{copyright_holder}' --copyright-year=#{Time.now.year} " +
52
- files_to_translate.join(' '))
53
- end
54
-
55
11
  desc 'Generate a new POT file and replace old if strings changed'
56
12
  task :update_pot do
57
13
  if !File.exist? pot_file_path
@@ -61,18 +17,12 @@ namespace :gettext do
61
17
  old_pot = pot_file_path + '.old'
62
18
  File.rename(pot_file_path, old_pot)
63
19
  generate_new_pot
64
- begin
65
- _, stderr, status = Open3.capture3("msgcmp --use-untranslated '#{old_pot}' '#{pot_file_path}'")
66
- if status == 1 || /this message is not used/.match(stderr)
67
- File.delete(old_pot)
68
- puts 'String changes detected, replacing with updated POT file'
69
- else
70
- puts 'No string changes detected, keeping old POT file'
71
- File.rename(old_pot, pot_file_path)
72
- end
73
- rescue IOError
74
- # Ignore; probably means msgcmp isn't installed.
20
+ if string_changes?(old_pot, pot_file_path)
75
21
  File.delete(old_pot)
22
+ puts 'String changes detected, replacing with updated POT file'
23
+ else
24
+ puts 'No string changes detected, keeping old POT file'
25
+ File.rename(old_pot, pot_file_path)
76
26
  end
77
27
  end
78
28
  end
@@ -0,0 +1,58 @@
1
+ require 'open3'
2
+
3
+ def locale_path
4
+ GettextSetup.locales_path
5
+ end
6
+
7
+ def text_domain
8
+ FastGettext.text_domain
9
+ end
10
+
11
+ def files_to_translate
12
+ files = GettextSetup.config['source_files'].map do |p|
13
+ Dir.glob(p)
14
+ end.flatten
15
+ # check for optional list of files to exclude from string
16
+ # extraction
17
+ exclusions = (GettextSetup.config['exclude_files'] || []).map do |p|
18
+ Dir.glob(p)
19
+ end.flatten
20
+
21
+ # if file is a directory, take it out of the array. directories
22
+ # cause rxgettext to error out.
23
+ (files - exclusions).reject { |file| File.directory?(file) }
24
+ end
25
+
26
+ def pot_file_path
27
+ File.join(locale_path, GettextSetup.config['project_name'] + '.pot')
28
+ end
29
+
30
+ def generate_new_pot
31
+ config = GettextSetup.config
32
+ package_name = config['package_name']
33
+ project_name = config['project_name']
34
+ bugs_address = config['bugs_address']
35
+ copyright_holder = config['copyright_holder']
36
+ # Done this way to allow the user to enter an empty string in the config.
37
+ comments_tag = config.key?('comments_tag') ? config['comments_tag'] : 'TRANSLATORS'
38
+ version = `git describe`
39
+ system("rxgettext -o locales/#{project_name}.pot --no-wrap --sort-by-file " \
40
+ "--add-comments#{comments_tag.to_s == '' ? '' : '=' + comments_tag} --msgid-bugs-address '#{bugs_address}' " \
41
+ "--package-name '#{package_name}' " \
42
+ "--package-version '#{version}' " \
43
+ "--copyright-holder='#{copyright_holder}' --copyright-year=#{Time.now.year} " +
44
+ files_to_translate.join(' '))
45
+ end
46
+
47
+ def string_changes?(old_pot, new_pot)
48
+ # Warnings will be in another language if locale is not set to en_US
49
+ _, stderr, status = Open3.capture3("LANG=en_US msgcmp --use-untranslated '#{old_pot}' '#{new_pot}'")
50
+ if status.exitstatus == 1 || /this message is not used/.match(stderr) || /this message is used but not defined/.match(stderr)
51
+ return true
52
+ end
53
+ return false
54
+ rescue IOError
55
+ # probably means msgcmp is not present on the system
56
+ # so return true to be on the safe side
57
+ return true
58
+ end
@@ -0,0 +1,33 @@
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: Sinatra i18n demo init-11-ga552a06\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 ""
26
+
27
+ #: ../../lib/gettext_setup_spec.rb:25
28
+ msgid "Goodbye, world!"
29
+ msgstr ""
30
+
31
+ #: ../../lib/gettext_setup_spec.rb:25
32
+ msgid "new string"
33
+ msgstr ""
@@ -0,0 +1,29 @@
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: Sinatra i18n demo init-11-ga552a06\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 ""
26
+
27
+ #: ../../lib/gettext_setup_spec.rb:25
28
+ msgid "changed string"
29
+ msgstr ""
@@ -0,0 +1,29 @@
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: Sinatra i18n demo init-11-ga552a06\n"
10
+ "\n"
11
+ "Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
12
+ "POT-Creation-Date: 2017-04-17 17:38-0500\n"
13
+ "PO-Revision-Date: 2017-04-17 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 ""
26
+
27
+ #: ../../lib/different_file.rb:25
28
+ msgid "Goodbye, world!"
29
+ msgstr ""
@@ -0,0 +1,29 @@
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: Sinatra i18n demo init-11-ga552a06\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 ""
26
+
27
+ #: ../../lib/gettext_setup_spec.rb:25
28
+ msgid "Goodbye, world!"
29
+ msgstr ""
@@ -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: Sinatra i18n demo init-11-ga552a06\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 ""
@@ -1,6 +1,8 @@
1
1
  require 'rspec/expectations'
2
2
  require_relative '../spec_helper'
3
3
 
4
+ require_relative '../../lib/gettext-setup'
5
+
4
6
  describe GettextSetup do
5
7
  before(:each) do
6
8
  GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'locales'))
@@ -50,8 +52,13 @@ describe GettextSetup do
50
52
  expect(GettextSetup.default_locale).to eq('en')
51
53
  expect(GettextSetup.candidate_locales).to include('en')
52
54
  GettextSetup.clear
53
- ENV['LANG'] = 'de_DE'
54
- expect(GettextSetup.candidate_locales).to eq('de_DE,de,en')
55
+ begin
56
+ old_locale = ENV['LANG']
57
+ ENV['LANG'] = 'de_DE'
58
+ expect(GettextSetup.candidate_locales).to eq('de_DE,de,en')
59
+ ensure
60
+ ENV['LANG'] = old_locale
61
+ end
55
62
  end
56
63
  end
57
64
  context 'multiple locales' do
data/spec/spec_helper.rb CHANGED
@@ -3,4 +3,10 @@ SimpleCov.start do
3
3
  add_filter '/spec/'
4
4
  end
5
5
 
6
- require_relative '../lib/gettext-setup'
6
+ def msgcmp_present?
7
+ # Try to call out to msgcmp, if it doesn't error, we have the tool
8
+ `msgcmp`
9
+ return true
10
+ rescue IOError
11
+ return false
12
+ end
@@ -0,0 +1,28 @@
1
+ require 'rspec/expectations'
2
+ require_relative '../spec_helper.rb'
3
+
4
+ require_relative '../../lib/tasks/task_helper.rb'
5
+
6
+ describe 'string_changes?', if: msgcmp_present? do
7
+ old_pot = File.absolute_path('../fixtures/pot_update/old.pot', File.dirname(__FILE__))
8
+
9
+ it 'should detect string addition' do
10
+ new_pot = File.absolute_path('../fixtures/pot_update/add.pot', File.dirname(__FILE__))
11
+ expect(string_changes?(old_pot, new_pot)).to eq(true)
12
+ end
13
+
14
+ it 'should detect string removal' do
15
+ new_pot = File.absolute_path('../fixtures/pot_update/remove.pot', File.dirname(__FILE__))
16
+ expect(string_changes?(old_pot, new_pot)).to eq(true)
17
+ end
18
+
19
+ it 'should detect string changes' do
20
+ new_pot = File.absolute_path('../fixtures/pot_update/change.pot', File.dirname(__FILE__))
21
+ expect(string_changes?(old_pot, new_pot)).to eq(true)
22
+ end
23
+
24
+ it 'should not detect non-string changes' do
25
+ new_pot = File.absolute_path('../fixtures/pot_update/non_string_changes.pot', File.dirname(__FILE__))
26
+ expect(string_changes?(old_pot, new_pot)).to eq(false)
27
+ end
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettext-setup
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.20'
4
+ version: '0.21'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fast_gettext
@@ -204,6 +204,7 @@ files:
204
204
  - lib/gettext-setup.rb
205
205
  - lib/gettext-setup/gettext_setup.rb
206
206
  - lib/tasks/gettext.rake
207
+ - lib/tasks/task_helper.rb
207
208
  - locales/config-sample.yaml
208
209
  - spec/fixtures/alt_locales/alt_locales.pot
209
210
  - spec/fixtures/alt_locales/config.yaml
@@ -211,8 +212,14 @@ files:
211
212
  - spec/fixtures/locales/config.yaml
212
213
  - spec/fixtures/locales/de/sinatra-i18n.po
213
214
  - spec/fixtures/locales/sinatra-i18n.pot
215
+ - spec/fixtures/pot_update/add.pot
216
+ - spec/fixtures/pot_update/change.pot
217
+ - spec/fixtures/pot_update/non_string_changes.pot
218
+ - spec/fixtures/pot_update/old.pot
219
+ - spec/fixtures/pot_update/remove.pot
214
220
  - spec/lib/gettext_setup_spec.rb
215
221
  - spec/spec_helper.rb
222
+ - spec/tasks/update_pot_spec.rb
216
223
  homepage: https://github.com/puppetlabs/gettext-setup-gem
217
224
  licenses:
218
225
  - Apache-2.0
@@ -233,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
240
  version: '0'
234
241
  requirements: []
235
242
  rubyforge_project:
236
- rubygems_version: 2.5.1
243
+ rubygems_version: 2.5.2
237
244
  signing_key:
238
245
  specification_version: 4
239
246
  summary: A gem to ease internationalization with fast_gettext
@@ -244,6 +251,11 @@ test_files:
244
251
  - spec/fixtures/locales/config.yaml
245
252
  - spec/fixtures/locales/de/sinatra-i18n.po
246
253
  - spec/fixtures/locales/sinatra-i18n.pot
254
+ - spec/fixtures/pot_update/add.pot
255
+ - spec/fixtures/pot_update/change.pot
256
+ - spec/fixtures/pot_update/non_string_changes.pot
257
+ - spec/fixtures/pot_update/old.pot
258
+ - spec/fixtures/pot_update/remove.pot
247
259
  - spec/lib/gettext_setup_spec.rb
248
260
  - spec/spec_helper.rb
249
- has_rdoc:
261
+ - spec/tasks/update_pot_spec.rb