gettext-setup 0.23 → 0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gettext-setup/pot.rb +5 -1
- data/lib/tasks/gettext.rake +9 -2
- data/spec/fixtures/tmp_locales/config.yaml +22 -0
- data/spec/fixtures/tmp_locales/de/sinatra-i18n.po +23 -0
- data/spec/fixtures/tmp_locales/sinatra-i18n.pot +40 -0
- data/spec/lib/{gettext_setup_spec.rb → gettext-setup/gettext_setup_spec.rb} +10 -7
- data/spec/lib/{metadata_pot_spec.rb → gettext-setup/metadata_pot_spec.rb} +3 -3
- data/spec/lib/{pot_spec.rb → gettext-setup/pot_spec.rb} +34 -50
- data/spec/lib/tasks/gettext_rake_spec.rb +103 -0
- data/spec/spec_helper.rb +0 -9
- metadata +16 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76721ee7a2e3870cbdb1a258b0158f1e65028f36
|
4
|
+
data.tar.gz: 01e7351ecc3386294020afa1e978a3bb9d5098ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b36a89fd9842e6fea600ee76935c84f13ff61509956d8ac2fb280b82eb9b0ce47251a70db692b6db4a6c604940b54a190c988bb6fdbbe6b92d056e2e37edcf76
|
7
|
+
data.tar.gz: 43567030ca8a0d62dc0079cda4522d0fa3673c9cf4b9c41cfc45aaa3704eb9fddc343a930ac404a57371c8e58971fd97a9718a3f69487b13822d98fe33e94e43
|
data/lib/gettext-setup/pot.rb
CHANGED
@@ -119,18 +119,22 @@ module GettextSetup
|
|
119
119
|
puts 'No existing POT file, generating new'
|
120
120
|
result = GettextSetup::Pot.generate_new_pot(locales_path, path)
|
121
121
|
puts "POT file #{path} has been generated" if result
|
122
|
+
result
|
122
123
|
else
|
123
124
|
old_pot = path + '.old'
|
124
125
|
File.rename(path, old_pot)
|
125
126
|
result = GettextSetup::Pot.generate_new_pot(locales_path, path)
|
126
127
|
if !result
|
127
128
|
puts 'POT creation failed'
|
129
|
+
result
|
128
130
|
elsif GettextSetup::Pot.string_changes?(old_pot, path)
|
129
|
-
File.delete(old_pot)
|
130
131
|
puts 'String changes detected, replacing with updated POT file'
|
132
|
+
File.delete(old_pot)
|
133
|
+
true
|
131
134
|
else
|
132
135
|
puts 'No string changes detected, keeping old POT file'
|
133
136
|
File.rename(old_pot, path)
|
137
|
+
true
|
134
138
|
end
|
135
139
|
end
|
136
140
|
end
|
data/lib/tasks/gettext.rake
CHANGED
@@ -9,9 +9,11 @@ namespace :gettext do
|
|
9
9
|
|
10
10
|
task :update_pot do
|
11
11
|
begin
|
12
|
-
GettextSetup::Pot.update_pot
|
12
|
+
result = GettextSetup::Pot.update_pot
|
13
|
+
exit 1 unless result
|
13
14
|
rescue GettextSetup::NoConfigFoundError => e
|
14
15
|
puts e.message
|
16
|
+
exit 1
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -21,6 +23,8 @@ namespace :gettext do
|
|
21
23
|
result = GettextSetup::Pot.generate_new_pot
|
22
24
|
if result
|
23
25
|
puts "POT file #{GettextSetup::Pot.pot_file_path} has been generated"
|
26
|
+
else
|
27
|
+
exit 1
|
24
28
|
end
|
25
29
|
rescue GettextSetup::NoConfigFoundError => e
|
26
30
|
puts e.message
|
@@ -33,6 +37,8 @@ namespace :gettext do
|
|
33
37
|
result = GettextSetup::MetadataPot.generate_metadata_pot
|
34
38
|
if result
|
35
39
|
puts "POT metadata file #{GettextSetup::MetadataPot.metadata_path} has been generated"
|
40
|
+
else
|
41
|
+
exit 1
|
36
42
|
end
|
37
43
|
rescue GettextSetup::NoConfigFoundError => e
|
38
44
|
puts e.message
|
@@ -42,7 +48,8 @@ namespace :gettext do
|
|
42
48
|
desc 'Update PO file for a specific language'
|
43
49
|
task :po, [:language] do |_, args|
|
44
50
|
begin
|
45
|
-
GettextSetup::Pot.generate_new_po(args.language)
|
51
|
+
result = GettextSetup::Pot.generate_new_po(args.language)
|
52
|
+
exit 1 unless result
|
46
53
|
rescue GettextSetup::NoConfigFoundError => e
|
47
54
|
puts e.message
|
48
55
|
end
|
@@ -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: 'sinatra-i18n'
|
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: Sinatra i18n demo
|
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
|
+
- 'lib/**/*.rb'
|
22
|
+
- 'spec/**/*.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: de\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 "Hallo, Welt!"
|
23
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# SOME DESCRIPTIVE TITLE.
|
2
|
+
# Copyright (C) 2017 Puppet Labs, LLC.
|
3
|
+
# This file is distributed under the same license as the Sinatra i18n demo package.
|
4
|
+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2017.
|
5
|
+
#
|
6
|
+
#, fuzzy
|
7
|
+
msgid ""
|
8
|
+
msgstr ""
|
9
|
+
"Project-Id-Version: Sinatra i18n demo 0.21-4-geccdac4\n"
|
10
|
+
"\n"
|
11
|
+
"Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
|
12
|
+
"POT-Creation-Date: 2017-04-11 20:08-0500\n"
|
13
|
+
"PO-Revision-Date: 2017-04-11 20:08-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
|
+
#: ../../lib/gettext_setup_spec.rb:26 ../../lib/gettext_setup_spec.rb:89 ../../lib/gettext_setup_spec.rb:91
|
23
|
+
msgid "Hello, world!"
|
24
|
+
msgstr ""
|
25
|
+
|
26
|
+
#: ../../lib/pot_spec.rb:52
|
27
|
+
msgid "merged-po-file"
|
28
|
+
msgstr ""
|
29
|
+
|
30
|
+
#: ../../lib/pot_spec.rb:74
|
31
|
+
msgid "no-pot-file"
|
32
|
+
msgstr ""
|
33
|
+
|
34
|
+
#: ../../lib/pot_spec.rb:85
|
35
|
+
msgid "some-spec-only-string"
|
36
|
+
msgstr ""
|
37
|
+
|
38
|
+
#: ../../lib/pot_spec.rb:104
|
39
|
+
msgid "unchanged-string"
|
40
|
+
msgstr ""
|
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'rspec/expectations'
|
2
|
-
require_relative '
|
2
|
+
require_relative '../../spec_helper'
|
3
3
|
|
4
|
-
require_relative '
|
4
|
+
require_relative '../../../lib/gettext-setup'
|
5
5
|
|
6
6
|
describe GettextSetup do
|
7
|
+
locales_path = File.absolute_path(File.join(File.dirname(__FILE__), '../../fixtures/locales'))
|
8
|
+
fixture_locales_path = File.absolute_path(File.join(File.dirname(__FILE__), '../../fixtures/fixture_locales'))
|
9
|
+
|
7
10
|
before(:each) do
|
8
|
-
GettextSetup.initialize(
|
11
|
+
GettextSetup.initialize(locales_path)
|
9
12
|
end
|
10
13
|
let(:config) do
|
11
14
|
GettextSetup.config
|
@@ -73,7 +76,7 @@ describe GettextSetup do
|
|
73
76
|
context 'multiple locales' do
|
74
77
|
# locales/ loads the de locale and fixture_locales/ loads the jp locale
|
75
78
|
before(:all) do
|
76
|
-
GettextSetup.initialize(
|
79
|
+
GettextSetup.initialize(fixture_locales_path)
|
77
80
|
end
|
78
81
|
it 'can aggregate locales across projects' do
|
79
82
|
expect(FastGettext.default_available_locales).to include('en')
|
@@ -89,7 +92,7 @@ describe GettextSetup do
|
|
89
92
|
end
|
90
93
|
context 'translation repository chain' do
|
91
94
|
before(:all) do
|
92
|
-
GettextSetup.initialize(
|
95
|
+
GettextSetup.initialize(fixture_locales_path)
|
93
96
|
end
|
94
97
|
it 'chain is not nil' do
|
95
98
|
expect(GettextSetup.translation_repositories).not_to be_nil
|
@@ -101,12 +104,12 @@ describe GettextSetup do
|
|
101
104
|
expect(_('Hello, world!')).to eq('こんにちは世界')
|
102
105
|
end
|
103
106
|
it 'does not allow duplicate repositories' do
|
104
|
-
GettextSetup.initialize(
|
107
|
+
GettextSetup.initialize(fixture_locales_path)
|
105
108
|
repos = GettextSetup.translation_repositories
|
106
109
|
expect(repos.select { |k, _| k == 'fixture_locales' }.size).to eq(1)
|
107
110
|
end
|
108
111
|
it 'does allow multiple unique domains' do
|
109
|
-
GettextSetup.initialize(
|
112
|
+
GettextSetup.initialize(locales_path)
|
110
113
|
repos = GettextSetup.translation_repositories
|
111
114
|
expect(repos.size == 2)
|
112
115
|
expect(repos.select { |k, _| k == 'fixture_locales' }.size).to eq(1)
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'rspec/expectations'
|
2
|
-
require_relative '
|
2
|
+
require_relative '../../spec_helper'
|
3
3
|
|
4
|
-
require_relative '
|
4
|
+
require_relative '../../../lib/gettext-setup'
|
5
5
|
|
6
6
|
describe GettextSetup::MetadataPot do
|
7
7
|
before(:each) do
|
8
|
-
GettextSetup.initialize(File.
|
8
|
+
GettextSetup.initialize(File.absolute_path(File.join(File.dirname(__FILE__), '../../fixtures/locales')))
|
9
9
|
end
|
10
10
|
context '#metadata_path' do
|
11
11
|
it 'finds the right metadata path' do
|
@@ -1,42 +1,42 @@
|
|
1
1
|
require 'rspec/expectations'
|
2
|
-
require_relative '
|
2
|
+
require_relative '../../spec_helper.rb'
|
3
3
|
|
4
|
-
require_relative '
|
4
|
+
require_relative '../../../lib/gettext-setup'
|
5
5
|
describe GettextSetup::Pot do
|
6
6
|
NoConfigFoundError = GettextSetup::NoConfigFoundError
|
7
7
|
|
8
8
|
def fixture_locales_path
|
9
|
-
File.join(File.dirname(__FILE__), '
|
9
|
+
File.join(File.dirname(__FILE__), '../../fixtures/fixture_locales')
|
10
10
|
end
|
11
11
|
|
12
12
|
def spec_locales_path
|
13
|
-
File.join(File.dirname(__FILE__), '
|
13
|
+
File.join(File.dirname(__FILE__), '../../fixtures/spec_locales')
|
14
14
|
end
|
15
15
|
|
16
16
|
def locales_path
|
17
|
-
File.join(File.dirname(__FILE__), '
|
17
|
+
File.join(File.dirname(__FILE__), '../../fixtures/locales')
|
18
18
|
end
|
19
19
|
|
20
20
|
describe 'string_changes?', if: msgcmp_present? do
|
21
|
-
old_pot = File.absolute_path('
|
21
|
+
old_pot = File.absolute_path('../../fixtures/string_changes/old.pot', File.dirname(__FILE__))
|
22
22
|
|
23
23
|
it 'should detect string addition' do
|
24
|
-
new_pot = File.absolute_path('
|
24
|
+
new_pot = File.absolute_path('../../fixtures/string_changes/add.pot', File.dirname(__FILE__))
|
25
25
|
expect(GettextSetup::Pot.string_changes?(old_pot, new_pot)).to eq(true)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should detect string removal' do
|
29
|
-
new_pot = File.absolute_path('
|
29
|
+
new_pot = File.absolute_path('../../fixtures/string_changes/remove.pot', File.dirname(__FILE__))
|
30
30
|
expect(GettextSetup::Pot.string_changes?(old_pot, new_pot)).to eq(true)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should detect string changes' do
|
34
|
-
new_pot = File.absolute_path('
|
34
|
+
new_pot = File.absolute_path('../../fixtures/string_changes/change.pot', File.dirname(__FILE__))
|
35
35
|
expect(GettextSetup::Pot.string_changes?(old_pot, new_pot)).to eq(true)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should not detect non-string changes' do
|
39
|
-
new_pot = File.absolute_path('
|
39
|
+
new_pot = File.absolute_path('../../fixtures/string_changes/non_string_changes.pot', File.dirname(__FILE__))
|
40
40
|
expect(GettextSetup::Pot.string_changes?(old_pot, new_pot)).to eq(false)
|
41
41
|
end
|
42
42
|
end
|
@@ -44,16 +44,13 @@ describe GettextSetup::Pot do
|
|
44
44
|
context 'generate_new_pot' do
|
45
45
|
it "fails when GettextSetup can't find a config.yaml" do
|
46
46
|
path = File.join(Dir.mktmpdir, 'empty.pot')
|
47
|
-
|
48
|
-
expect { GettextSetup::Pot.generate_new_pot(Dir.mktmpdir, path) }.to raise_error(NoConfigFoundError)
|
49
|
-
end
|
47
|
+
expect { GettextSetup::Pot.generate_new_pot(Dir.mktmpdir, path) }.to raise_error(NoConfigFoundError)
|
50
48
|
end
|
51
49
|
it 'builds a POT file' do
|
52
50
|
path = File.join(Dir.mktmpdir, 'new.pot')
|
53
|
-
|
51
|
+
expect do
|
54
52
|
GettextSetup::Pot.generate_new_pot(fixture_locales_path, path)
|
55
|
-
end
|
56
|
-
expect(out).to eq('') # STDOUT is determined in `update_pot`.
|
53
|
+
end.to output('').to_stdout # STDOUT is determined in `update_pot`.
|
57
54
|
contents = File.read(path)
|
58
55
|
expect(contents).to match(/Fixture locales/)
|
59
56
|
expect(contents).to match(/docs@puppetlabs.com/)
|
@@ -66,43 +63,37 @@ describe GettextSetup::Pot do
|
|
66
63
|
it "fails when GettextSetup can't find a config.yaml" do
|
67
64
|
path = File.join(Dir.mktmpdir, 'fails.pot')
|
68
65
|
po_path = File.join(Dir.mktmpdir, 'fails.po')
|
69
|
-
|
70
|
-
expect { GettextSetup::Pot.generate_new_po('ja', Dir.mktmpdir, path, po_path) }.to raise_error(NoConfigFoundError)
|
71
|
-
end
|
66
|
+
expect { GettextSetup::Pot.generate_new_po('ja', Dir.mktmpdir, path, po_path) }.to raise_error(NoConfigFoundError)
|
72
67
|
end
|
73
68
|
it 'complains when no language is supplied' do
|
74
|
-
stdout = with_captured_stdout do
|
75
|
-
GettextSetup::Pot.generate_new_po(nil, fixture_locales_path, Dir.mktmpdir, Dir.mktmpdir)
|
76
|
-
end
|
77
69
|
result = "You need to specify the language to add. Either 'LANGUAGE=eo rake gettext:po' or 'rake gettext:po[LANGUAGE]'\n"
|
78
|
-
expect
|
70
|
+
expect do
|
71
|
+
GettextSetup::Pot.generate_new_po(nil, fixture_locales_path, Dir.mktmpdir, Dir.mktmpdir)
|
72
|
+
end.to output(result).to_stdout
|
79
73
|
end
|
80
74
|
it 'generates new PO file', if: msginit_present? do
|
81
75
|
po_path = File.join(Dir.mktmpdir, 'aa', 'tmp.po')
|
82
76
|
pot_path = File.join(locales_path, 'sinatra-i18n.pot')
|
83
77
|
|
84
|
-
|
78
|
+
expect do
|
85
79
|
GettextSetup::Pot.generate_new_po('aa', locales_path, pot_path, po_path)
|
86
|
-
end
|
87
|
-
expect(stdout).to eq("PO file #{po_path} created\n")
|
80
|
+
end.to output("PO file #{po_path} created\n").to_stdout
|
88
81
|
end
|
89
82
|
it 'merges PO files', if: [msginit_present?, msgmerge_present?] do
|
90
83
|
_('merged-po-file')
|
91
84
|
po_path = File.join(Dir.mktmpdir, 'aa', 'tmp.po')
|
92
85
|
pot_path = GettextSetup::Pot.pot_file_path
|
93
86
|
|
94
|
-
|
87
|
+
expect do
|
95
88
|
GettextSetup::Pot.generate_new_po('aa', fixture_locales_path, pot_path, po_path)
|
96
|
-
end
|
97
|
-
expect(stdout).to eq("PO file #{po_path} created\n")
|
89
|
+
end.to output("PO file #{po_path} created\n").to_stdout
|
98
90
|
contents = File.read(po_path)
|
99
91
|
expect(contents).to match(/msgid "Hello, world!"/)
|
100
92
|
|
101
93
|
new_pot_path = File.join(spec_locales_path, 'sinatra-i18n.pot')
|
102
|
-
|
94
|
+
expect do
|
103
95
|
GettextSetup::Pot.generate_new_po('aa', spec_locales_path, new_pot_path, po_path)
|
104
|
-
end
|
105
|
-
expect(new_stdout).to eq("PO file #{po_path} merged\n")
|
96
|
+
end.to output("PO file #{po_path} merged\n").to_stdout
|
106
97
|
new_contents = File.read(po_path)
|
107
98
|
expect(new_contents).to match(/merged-po-file/)
|
108
99
|
end
|
@@ -111,52 +102,45 @@ describe GettextSetup::Pot do
|
|
111
102
|
context 'update_pot' do
|
112
103
|
it "fails when GettextSetup can't find a config.yaml" do
|
113
104
|
path = File.join(Dir.mktmpdir, 'fail-update.pot')
|
114
|
-
|
115
|
-
expect { GettextSetup::Pot.update_pot(Dir.mktmpdir, path) }.to raise_error(NoConfigFoundError)
|
116
|
-
end
|
105
|
+
expect { GettextSetup::Pot.update_pot(Dir.mktmpdir, path) }.to raise_error(NoConfigFoundError)
|
117
106
|
end
|
118
107
|
it 'creates POT when absent' do
|
119
108
|
_('no-pot-file')
|
120
109
|
path = File.join(Dir.mktmpdir, 'some-pot.pot')
|
121
|
-
|
110
|
+
expect do
|
122
111
|
GettextSetup::Pot.update_pot(spec_locales_path, path)
|
123
|
-
end
|
124
|
-
expect(stdout).to eq("No existing POT file, generating new\nPOT file #{path} has been generated\n")
|
112
|
+
end.to output("No existing POT file, generating new\nPOT file #{path} has been generated\n").to_stdout
|
125
113
|
contents = File.read(path)
|
126
114
|
expect(contents).to match(/msgid "no-pot-file"/)
|
127
115
|
end
|
128
116
|
it 'updates POT when something changes', if: [msginit_present?, msgmerge_present?] do
|
129
117
|
_('some-spec-only-string')
|
130
118
|
path = File.join(Dir.mktmpdir, 'some-pot.pot')
|
131
|
-
|
119
|
+
expect do
|
132
120
|
GettextSetup::Pot.update_pot(fixture_locales_path, path)
|
133
|
-
end
|
134
|
-
expect(stdout).to eq("No existing POT file, generating new\nPOT file #{path} has been generated\n")
|
121
|
+
end.to output("No existing POT file, generating new\nPOT file #{path} has been generated\n").to_stdout
|
135
122
|
contents = File.read(path)
|
136
123
|
expect(contents).to match(/Language-Team: LANGUAGE <LL@li.org>/)
|
137
124
|
expect(contents).not_to match(/some-spec-only-string/)
|
138
|
-
|
125
|
+
expect do
|
139
126
|
GettextSetup::Pot.update_pot(spec_locales_path, path)
|
140
|
-
end
|
127
|
+
end.to output("String changes detected, replacing with updated POT file\n").to_stdout
|
141
128
|
new_contents = File.read(path)
|
142
129
|
expect(new_contents).to match(/some-spec-only-string/)
|
143
|
-
expect(output).to eq("String changes detected, replacing with updated POT file\n")
|
144
130
|
end
|
145
131
|
it "doesn't update the POT when nothing changes", if: [msginit_present?, msgcmp_present?] do
|
146
132
|
_('unchanged-string')
|
147
133
|
path = File.join(Dir.mktmpdir, 'some-pot.pot')
|
148
|
-
|
134
|
+
expect do
|
149
135
|
GettextSetup::Pot.update_pot(spec_locales_path, path)
|
150
|
-
end
|
151
|
-
expect(stdout).to eq("No existing POT file, generating new\nPOT file #{path} has been generated\n")
|
136
|
+
end.to output("No existing POT file, generating new\nPOT file #{path} has been generated\n").to_stdout
|
152
137
|
contents = File.read(path)
|
153
138
|
expect(contents).to match(/unchanged-string/)
|
154
|
-
|
139
|
+
expect do
|
155
140
|
GettextSetup::Pot.update_pot(spec_locales_path, path)
|
156
|
-
end
|
141
|
+
end.to output("No string changes detected, keeping old POT file\n").to_stdout
|
157
142
|
new_contents = File.read(path)
|
158
143
|
expect(new_contents).to eq(contents)
|
159
|
-
expect(new_stdout).to eq("No string changes detected, keeping old POT file\n")
|
160
144
|
end
|
161
145
|
end
|
162
146
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'rspec/expectations'
|
2
|
+
require 'rake'
|
3
|
+
require_relative '../../spec_helper.rb'
|
4
|
+
|
5
|
+
load File.expand_path('../../../../lib/tasks/gettext.rake', __FILE__)
|
6
|
+
|
7
|
+
describe 'gettext.rake' do
|
8
|
+
locales = File.expand_path('../../fixtures/locales', File.dirname(__FILE__))
|
9
|
+
tmp_locales = File.expand_path('../../fixtures/tmp_locales', File.dirname(__FILE__))
|
10
|
+
fixture_locales = File.expand_path('../../fixtures/fixture_locales', File.dirname(__FILE__))
|
11
|
+
tmp_pot_path = File.expand_path('sinatra-i18n.pot', tmp_locales)
|
12
|
+
|
13
|
+
before :each do
|
14
|
+
FileUtils.rm_r(tmp_locales, force: true)
|
15
|
+
FileUtils.cp_r(locales, tmp_locales)
|
16
|
+
end
|
17
|
+
after :each do
|
18
|
+
GettextSetup.clear
|
19
|
+
Rake::Task.tasks.each(&:reenable)
|
20
|
+
end
|
21
|
+
around :each do |test|
|
22
|
+
# Since we have `exit 1` in these rake tasks, we need to explicitly tell
|
23
|
+
# rspec that any unexpected errors aren't expected. Otherwise, if a
|
24
|
+
# SystemExit error is thrown, it just doesn't finish running the rest of
|
25
|
+
# the tests and considers the suite passing...
|
26
|
+
expect { test.run }.not_to raise_error
|
27
|
+
end
|
28
|
+
context Rake::Task['gettext:pot'] do
|
29
|
+
it 'outputs correctly' do
|
30
|
+
expect do
|
31
|
+
GettextSetup.initialize(tmp_locales)
|
32
|
+
subject.invoke
|
33
|
+
end.to output(/POT file .+\/spec\/fixtures\/tmp_locales\/sinatra-i18n.pot has been generated/).to_stdout
|
34
|
+
end
|
35
|
+
it 'exits 1 on error' do
|
36
|
+
allow(GettextSetup::Pot).to receive(:generate_new_pot).and_return(false)
|
37
|
+
expect do
|
38
|
+
GettextSetup.initialize(tmp_locales)
|
39
|
+
subject.invoke
|
40
|
+
end.to raise_error(SystemExit)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
context Rake::Task['gettext:metadata_pot'] do
|
44
|
+
it 'outputs correctly' do
|
45
|
+
expect do
|
46
|
+
GettextSetup.initialize(tmp_locales)
|
47
|
+
subject.invoke
|
48
|
+
end.to output(/POT metadata file .+sinatra-i18n_metadata.pot has been generated/).to_stdout
|
49
|
+
end
|
50
|
+
it 'exits 1 on error' do
|
51
|
+
allow(GettextSetup::MetadataPot).to receive(:generate_metadata_pot).and_return(false)
|
52
|
+
expect do
|
53
|
+
GettextSetup.initialize(tmp_locales)
|
54
|
+
subject.invoke
|
55
|
+
end.to raise_error(SystemExit)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
context Rake::Task['gettext:po'] do
|
59
|
+
it 'outputs correctly' do
|
60
|
+
expect do
|
61
|
+
GettextSetup.initialize(tmp_locales)
|
62
|
+
subject.invoke('de')
|
63
|
+
end.to output(/PO file .+de\/sinatra-i18n.po merged/).to_stdout
|
64
|
+
end
|
65
|
+
it 'exits 1 on error' do
|
66
|
+
allow(GettextSetup::Pot).to receive(:generate_new_po).with('de').and_return(false)
|
67
|
+
expect do
|
68
|
+
GettextSetup.initialize(tmp_locales)
|
69
|
+
subject.invoke('de')
|
70
|
+
end.to raise_error(SystemExit)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
context Rake::Task['gettext:update_pot'] do
|
74
|
+
it 'does not update the POT when no changes are detected' do
|
75
|
+
expect do
|
76
|
+
GettextSetup.initialize(tmp_locales)
|
77
|
+
subject.invoke
|
78
|
+
end.to output(/No string changes detected, keeping old POT file/).to_stdout
|
79
|
+
end
|
80
|
+
it 'can create a new POT' do
|
81
|
+
FileUtils.rm(tmp_pot_path)
|
82
|
+
expect do
|
83
|
+
GettextSetup.initialize(tmp_locales)
|
84
|
+
subject.invoke
|
85
|
+
end.to output(/No existing POT file, generating new\nPOT file .+sinatra-i18n.pot has been generated/).to_stdout
|
86
|
+
end
|
87
|
+
it 'can update the POT' do
|
88
|
+
fixture_locales_pot = File.expand_path('fixture_locales.pot', fixture_locales)
|
89
|
+
FileUtils.cp(fixture_locales_pot, tmp_pot_path)
|
90
|
+
expect do
|
91
|
+
GettextSetup.initialize(tmp_locales)
|
92
|
+
subject.invoke
|
93
|
+
end.to output(/String changes detected, replacing with updated POT file/).to_stdout
|
94
|
+
end
|
95
|
+
it 'exits 1 upon error' do
|
96
|
+
allow(GettextSetup::Pot).to receive(:update_pot).and_return(false)
|
97
|
+
expect do
|
98
|
+
GettextSetup.initialize(tmp_locales)
|
99
|
+
subject.invoke
|
100
|
+
end.to raise_error(SystemExit)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: '0.24'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fast_gettext
|
@@ -223,9 +223,13 @@ files:
|
|
223
223
|
- spec/fixtures/string_changes/non_string_changes.pot
|
224
224
|
- spec/fixtures/string_changes/old.pot
|
225
225
|
- spec/fixtures/string_changes/remove.pot
|
226
|
-
- spec/
|
227
|
-
- spec/
|
228
|
-
- spec/
|
226
|
+
- spec/fixtures/tmp_locales/config.yaml
|
227
|
+
- spec/fixtures/tmp_locales/de/sinatra-i18n.po
|
228
|
+
- spec/fixtures/tmp_locales/sinatra-i18n.pot
|
229
|
+
- spec/lib/gettext-setup/gettext_setup_spec.rb
|
230
|
+
- spec/lib/gettext-setup/metadata_pot_spec.rb
|
231
|
+
- spec/lib/gettext-setup/pot_spec.rb
|
232
|
+
- spec/lib/tasks/gettext_rake_spec.rb
|
229
233
|
- spec/spec_helper.rb
|
230
234
|
homepage: https://github.com/puppetlabs/gettext-setup-gem
|
231
235
|
licenses:
|
@@ -266,8 +270,12 @@ test_files:
|
|
266
270
|
- spec/fixtures/string_changes/non_string_changes.pot
|
267
271
|
- spec/fixtures/string_changes/old.pot
|
268
272
|
- spec/fixtures/string_changes/remove.pot
|
269
|
-
- spec/
|
270
|
-
- spec/
|
271
|
-
- spec/
|
273
|
+
- spec/fixtures/tmp_locales/config.yaml
|
274
|
+
- spec/fixtures/tmp_locales/de/sinatra-i18n.po
|
275
|
+
- spec/fixtures/tmp_locales/sinatra-i18n.pot
|
276
|
+
- spec/lib/gettext-setup/gettext_setup_spec.rb
|
277
|
+
- spec/lib/gettext-setup/metadata_pot_spec.rb
|
278
|
+
- spec/lib/gettext-setup/pot_spec.rb
|
279
|
+
- spec/lib/tasks/gettext_rake_spec.rb
|
272
280
|
- spec/spec_helper.rb
|
273
281
|
has_rdoc:
|