lokalise_manager 2.1.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,113 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe LokaliseManager::TaskDefinitions::Base do
4
- let(:described_object) { described_class.new }
5
-
6
- describe '.new' do
7
- it 'allows to override config' do
8
- obj = described_class.new token: 'fake'
9
- expect(obj.config.token).to eq('fake')
10
- end
11
- end
12
-
13
- describe '#config' do
14
- it 'allows to update config after initialization' do
15
- obj = described_class.new token: 'fake', project_id: '123'
16
-
17
- obj.config.project_id = '345'
18
-
19
- expect(obj.config.project_id).to eq('345')
20
- expect(obj.config.token).to eq('fake')
21
- end
22
- end
23
-
24
- specify '.reset_client!' do
25
- expect(described_object.api_client).to be_an_instance_of(Lokalise::Client)
26
- described_object.reset_api_client!
27
- current_client = described_object.instance_variable_get :@api_client
28
- expect(current_client).to be_nil
29
- end
30
-
31
- specify '.project_id_with_branch!' do
32
- result = described_object.send :project_id_with_branch
33
- expect(result).to be_an_instance_of(String)
34
- expect(result).not_to include(':master')
35
-
36
- described_object.config.branch = 'develop'
37
- result = described_object.send :project_id_with_branch
38
- expect(result).to be_an_instance_of(String)
39
- expect(result).to include(':develop')
40
- end
41
-
42
- describe '.subdir_and_filename_for' do
43
- it 'works properly for longer paths' do
44
- path = 'my_path/is/here/file.yml'
45
- result = described_object.send(:subdir_and_filename_for, path)
46
- expect(result.length).to eq(2)
47
- expect(result[0]).to be_an_instance_of(Pathname)
48
- expect(result[0].to_s).to eq('my_path/is/here')
49
- expect(result[1].to_s).to eq('file.yml')
50
- end
51
-
52
- it 'works properly for shorter paths' do
53
- path = 'file.yml'
54
- result = described_object.send(:subdir_and_filename_for, path)
55
- expect(result.length).to eq(2)
56
- expect(result[1]).to be_an_instance_of(Pathname)
57
- expect(result[0].to_s).to eq('.')
58
- expect(result[1].to_s).to eq('file.yml')
59
- end
60
- end
61
-
62
- describe '.check_options_errors!' do
63
- it 'raises an error when the API key is not set' do
64
- allow(LokaliseManager::GlobalConfig).to receive(:api_token).and_return(nil)
65
-
66
- expect(-> { described_object.send(:check_options_errors!) }).to raise_error(LokaliseManager::Error, /API token is not set/i)
67
-
68
- expect(LokaliseManager::GlobalConfig).to have_received(:api_token)
69
- end
70
-
71
- it 'returns an error when the project_id is not set' do
72
- allow_project_id described_object, nil do
73
- expect(-> { described_object.send(:check_options_errors!) }).to raise_error(LokaliseManager::Error, /ID is not set/i)
74
- end
75
- end
76
- end
77
-
78
- describe '.proper_ext?' do
79
- it 'works properly with path represented as a string' do
80
- path = 'my_path/here/file.yml'
81
- expect(described_object.send(:proper_ext?, path)).to be true
82
- end
83
-
84
- it 'works properly with path represented as a pathname' do
85
- path = Pathname.new 'my_path/here/file.json'
86
- expect(described_object.send(:proper_ext?, path)).to be false
87
- end
88
- end
89
-
90
- describe '.api_client' do
91
- it 'is possible to set timeouts' do
92
- allow(described_object.config).to receive(:timeouts).and_return({
93
- open_timeout: 100,
94
- timeout: 500
95
- })
96
-
97
- client = described_object.api_client
98
- expect(client).to be_an_instance_of(Lokalise::Client)
99
- expect(client).not_to be_an_instance_of(Lokalise::OAuthClient)
100
- expect(client.open_timeout).to eq(100)
101
- expect(client.timeout).to eq(500)
102
- end
103
-
104
- it 'uses .oauth_client when the use_oauth2_token is true' do
105
- allow(described_object.config).to receive(:use_oauth2_token).and_return(true)
106
-
107
- client = described_object.api_client
108
-
109
- expect(client).to be_an_instance_of(Lokalise::OAuthClient)
110
- expect(client).not_to be_an_instance_of(Lokalise::Client)
111
- end
112
- end
113
- end
@@ -1,240 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'base64'
4
-
5
- describe LokaliseManager::TaskDefinitions::Exporter do
6
- let(:filename) { 'en.yml' }
7
- let(:path) { "#{Dir.getwd}/locales/nested/#{filename}" }
8
- let(:relative_name) { "nested/#{filename}" }
9
- let(:project_id) { ENV['LOKALISE_PROJECT_ID'] }
10
- let(:described_object) do
11
- described_class.new project_id: project_id,
12
- api_token: ENV['LOKALISE_API_TOKEN'],
13
- max_retries_export: 2
14
- end
15
-
16
- context 'with many translation files' do
17
- before :all do
18
- add_translation_files! with_ru: true, additional: 5
19
- end
20
-
21
- after :all do
22
- rm_translation_files
23
- end
24
-
25
- describe '.export!' do
26
- it 'sends a proper API request and handles rate limiting' do
27
- process = nil
28
-
29
- VCR.use_cassette('upload_files_multiple') do
30
- expect(-> { process = described_object.export!.first.process }).to output(/complete!/).to_stdout
31
- end
32
-
33
- expect(process.project_id).to eq(project_id)
34
- expect(process.status).to eq('queued')
35
- end
36
-
37
- it 'handles too many requests' do
38
- allow(described_object.config).to receive(:max_retries_export).and_return(1)
39
- allow(described_object).to receive(:sleep).and_return(0)
40
-
41
- fake_client = instance_double('Lokalise::Client')
42
- allow(fake_client).to receive(:token).with(any_args).and_return('fake_token')
43
- allow(fake_client).to receive(:upload_file).with(any_args).and_raise(Lokalise::Error::TooManyRequests)
44
- allow(described_object).to receive(:api_client).and_return(fake_client)
45
-
46
- expect(-> { described_object.export! }).to raise_error(Lokalise::Error::TooManyRequests, /Gave up after 1 retries/i)
47
-
48
- expect(described_object).to have_received(:sleep).exactly(6).times
49
- expect(described_object).to have_received(:api_client).at_least(12).times
50
- expect(fake_client).to have_received(:upload_file).exactly(12).times
51
- end
52
-
53
- it 'handles too many requests but does not re-raise anything when raise_on_export_fail is false' do
54
- allow(described_object.config).to receive(:max_retries_export).and_return(1)
55
- allow(described_object.config).to receive(:raise_on_export_fail).and_return(false)
56
- allow(described_object).to receive(:sleep).and_return(0)
57
-
58
- fake_client = instance_double('Lokalise::Client')
59
- allow(fake_client).to receive(:token).with(any_args).and_return('fake_token')
60
- allow(fake_client).to receive(:upload_file).with(any_args).and_raise(Lokalise::Error::TooManyRequests)
61
- allow(described_object).to receive(:api_client).and_return(fake_client)
62
- processes = []
63
- expect(-> { processes = described_object.export! }).not_to raise_error
64
-
65
- expect(processes[0].path.to_s).to include('en_0')
66
- expect(processes[0].success).to be false
67
- expect(processes[1].error.class).to eq(Lokalise::Error::TooManyRequests)
68
- expect(processes.count).to eq(7)
69
-
70
- expect(described_object).to have_received(:sleep).exactly(7).times
71
- expect(described_object).to have_received(:api_client).at_least(14).times
72
- expect(fake_client).to have_received(:upload_file).exactly(14).times
73
- end
74
- end
75
- end
76
-
77
- context 'with one translation file' do
78
- before :all do
79
- add_translation_files!
80
- end
81
-
82
- after :all do
83
- rm_translation_files
84
- end
85
-
86
- describe '.export!' do
87
- it 'sends a proper API request but does not output anything when silent_mode is enabled' do
88
- allow(described_object.config).to receive(:silent_mode).and_return(true)
89
-
90
- process = nil
91
-
92
- VCR.use_cassette('upload_files') do
93
- expect(-> { process = described_object.export!.first.process }).not_to output(/complete!/).to_stdout
94
- end
95
-
96
- expect(process.status).to eq('queued')
97
- expect(described_object.config).to have_received(:silent_mode).at_most(1).times
98
- end
99
-
100
- it 'sends a proper API request' do
101
- process = VCR.use_cassette('upload_files') do
102
- described_object.export!
103
- end.first.process
104
-
105
- expect(process.project_id).to eq(project_id)
106
- expect(process.status).to eq('queued')
107
- end
108
-
109
- it 'sends a proper API request when a different branch is provided' do
110
- allow(described_object.config).to receive(:branch).and_return('develop')
111
-
112
- process_data = VCR.use_cassette('upload_files_branch') do
113
- described_object.export!
114
- end.first
115
-
116
- expect(described_object.config).to have_received(:branch).at_most(2).times
117
- expect(process_data.success).to be true
118
- expect(process_data.path.to_s).to include('en.yml')
119
-
120
- process = process_data.process
121
- expect(process).to be_an_instance_of(Lokalise::Resources::QueuedProcess)
122
- expect(process.project_id).to eq(project_id)
123
- expect(process.status).to eq('queued')
124
- end
125
-
126
- it 'halts when the API key is not set' do
127
- allow(described_object.config).to receive(:api_token).and_return(nil)
128
-
129
- expect(-> { described_object.export! }).to raise_error(LokaliseManager::Error, /API token is not set/i)
130
- expect(described_object.config).to have_received(:api_token)
131
- end
132
-
133
- it 'halts when the project_id is not set' do
134
- allow_project_id described_object, nil do
135
- expect(-> { described_object.export! }).to raise_error(LokaliseManager::Error, /ID is not set/i)
136
- end
137
- end
138
- end
139
-
140
- describe '#all_files' do
141
- it 'yield proper arguments' do
142
- expect(described_object.send(:all_files).first).to include(
143
- Pathname.new(path),
144
- Pathname.new(relative_name)
145
- )
146
- end
147
- end
148
-
149
- describe '.opts' do
150
- let(:base64content) { Base64.strict_encode64(File.read(path).strip) }
151
-
152
- it 'generates proper options' do
153
- resulting_opts = described_object.send(:opts, path, relative_name)
154
-
155
- expect(resulting_opts[:data]).to eq(base64content)
156
- expect(resulting_opts[:filename]).to eq(relative_name)
157
- expect(resulting_opts[:lang_iso]).to eq('en')
158
- end
159
-
160
- it 'allows to redefine options' do
161
- allow(described_object.config).to receive(:export_opts).and_return({
162
- detect_icu_plurals: true,
163
- convert_placeholders: true
164
- })
165
-
166
- resulting_opts = described_object.send(:opts, path, relative_name)
167
-
168
- expect(described_object.config).to have_received(:export_opts)
169
- expect(resulting_opts[:data]).to eq(base64content)
170
- expect(resulting_opts[:filename]).to eq(relative_name)
171
- expect(resulting_opts[:lang_iso]).to eq('en')
172
- expect(resulting_opts[:detect_icu_plurals]).to be true
173
- expect(resulting_opts[:convert_placeholders]).to be true
174
- end
175
- end
176
- end
177
-
178
- context 'with two translation files' do
179
- let(:filename_ru) { 'ru.yml' }
180
- let(:path_ru) { "#{Dir.getwd}/locales/#{filename_ru}" }
181
-
182
- before :all do
183
- add_translation_files! with_ru: true
184
- end
185
-
186
- after :all do
187
- rm_translation_files
188
- end
189
-
190
- describe '.export!' do
191
- it 're-raises export errors' do
192
- allow_project_id described_object, '542886116159f798720dc4.94769464'
193
-
194
- VCR.use_cassette('upload_files_error') do
195
- expect { described_object.export! }.to raise_error(Lokalise::Error::BadRequest, /Unknown `lang_iso`/)
196
- end
197
- end
198
- end
199
-
200
- describe '.opts' do
201
- let(:base64content_ru) { Base64.strict_encode64(File.read(path_ru).strip) }
202
-
203
- it 'generates proper options' do
204
- resulting_opts = described_object.send(:opts, path_ru, filename_ru)
205
-
206
- expect(resulting_opts[:data]).to eq(base64content_ru)
207
- expect(resulting_opts[:filename]).to eq(filename_ru)
208
- expect(resulting_opts[:lang_iso]).to eq('ru_RU')
209
- end
210
- end
211
-
212
- describe '#each_file' do
213
- it 'returns all files' do
214
- files = described_object.send(:all_files)
215
- expect(files[0]).to include(
216
- Pathname.new(path),
217
- Pathname.new(relative_name)
218
- )
219
- expect(files[1]).to include(
220
- Pathname.new(path_ru),
221
- Pathname.new(filename_ru)
222
- )
223
- end
224
-
225
- it 'does not return files that have to be skipped' do
226
- allow(described_object.config).to receive(:skip_file_export).twice.and_return(
227
- ->(f) { f.split[1].to_s.include?('ru') }
228
- )
229
- files = described_object.send(:all_files)
230
- expect(files[0]).to include(
231
- Pathname.new(path),
232
- Pathname.new(relative_name)
233
- )
234
- expect(files.count).to eq(1)
235
-
236
- expect(described_object.config).to have_received(:skip_file_export).twice
237
- end
238
- end
239
- end
240
- end
@@ -1,200 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe LokaliseManager::TaskDefinitions::Importer do
4
- let(:described_object) do
5
- described_class.new project_id: project_id,
6
- api_token: ENV['LOKALISE_API_TOKEN'],
7
- max_retries_import: 2
8
- end
9
- let(:loc_path) { described_object.config.locales_path }
10
- let(:project_id) { ENV['LOKALISE_PROJECT_ID'] }
11
- let(:local_trans) { "#{Dir.getwd}/spec/fixtures/trans.zip" }
12
-
13
- describe '#open_and_process_zip' do
14
- it 're-raises errors during file processing' do
15
- entry = double
16
- allow(entry).to receive(:name).and_return('fail.yml')
17
- allow(described_object).to receive(:data_from).with(entry).and_raise(EncodingError)
18
- expect(-> { described_object.send(:process!, entry) }).
19
- to raise_error(EncodingError, /Error when trying to process fail\.yml/)
20
-
21
- expect(described_object).to have_received(:data_from)
22
- end
23
-
24
- it 're-raises errors during file opening' do
25
- expect(-> { described_object.send(:open_and_process_zip, 'http://fake.url/wrong/path.zip') }).
26
- to raise_error(SocketError, /Failed to open TCP connection/)
27
- end
28
- end
29
-
30
- describe '#download_files' do
31
- it 'returns a proper download URL' do
32
- response = VCR.use_cassette('download_files') do
33
- described_object.send :download_files
34
- end
35
-
36
- expect(response['project_id']).to eq('672198945b7d72fc048021.15940510')
37
- expect(response['bundle_url']).to include('s3-eu-west-1.amazonaws.com')
38
- expect(described_object.api_client.enable_compression).to eq(true)
39
- end
40
-
41
- it 're-raises errors during file download' do
42
- allow_project_id described_object, 'invalid'
43
-
44
- VCR.use_cassette('download_files_error') do
45
- expect(-> { described_object.send :download_files }).
46
- to raise_error(Lokalise::Error::BadRequest, /Invalid `project_id` parameter/)
47
- end
48
- end
49
- end
50
-
51
- describe '.import!' do
52
- context 'with errors' do
53
- it 'handles too many requests' do
54
- allow(described_object).to receive(:sleep).and_return(0)
55
-
56
- fake_client = instance_double('Lokalise::Client')
57
- allow(fake_client).to receive(:download_files).and_raise(Lokalise::Error::TooManyRequests)
58
- allow(described_object).to receive(:api_client).and_return(fake_client)
59
-
60
- expect(-> { described_object.import! }).to raise_error(Lokalise::Error::TooManyRequests, /Gave up after 2 retries/i)
61
-
62
- expect(described_object).to have_received(:sleep).exactly(2).times
63
- expect(described_object).to have_received(:api_client).exactly(3).times
64
- expect(fake_client).to have_received(:download_files).exactly(3).times
65
- end
66
-
67
- it 'halts when the API key is not set' do
68
- allow(described_object.config).to receive(:api_token).and_return(nil)
69
- expect(-> { described_object.import! }).to raise_error(LokaliseManager::Error, /API token is not set/i)
70
- expect(described_object.config).to have_received(:api_token)
71
- expect(count_translations).to eq(0)
72
- end
73
-
74
- it 'halts when the project_id is not set' do
75
- allow_project_id described_object, nil do
76
- expect(-> { described_object.import! }).to raise_error(LokaliseManager::Error, /ID is not set/i)
77
- expect(count_translations).to eq(0)
78
- end
79
- end
80
- end
81
-
82
- context 'when directory is empty' do
83
- before do
84
- mkdir_locales
85
- rm_translation_files
86
- end
87
-
88
- after :all do
89
- rm_translation_files
90
- end
91
-
92
- it 'runs import successfully for local files' do
93
- allow(described_object).to receive(:download_files).and_return(
94
- {
95
- 'project_id' => '123.abc',
96
- 'bundle_url' => local_trans
97
- }
98
- )
99
-
100
- expect(described_object.import!).to be true
101
-
102
- expect(count_translations).to eq(4)
103
- expect(described_object).to have_received(:download_files)
104
- expect_file_exist loc_path, 'en/nested/main_en.yml'
105
- expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml'
106
- expect_file_exist loc_path, 'ru/main_ru.yml'
107
- end
108
-
109
- it 'runs import successfully' do
110
- result = nil
111
-
112
- VCR.use_cassette('import') do
113
- expect(-> { result = described_object.import! }).to output(/complete!/).to_stdout
114
- end
115
-
116
- expect(result).to be true
117
-
118
- expect(count_translations).to eq(24)
119
- expect_file_exist loc_path, 'en_1.yml'
120
- expect_file_exist loc_path, 'ru_2.yml'
121
- end
122
-
123
- it 'runs import successfully but does not provide any output when silent_mode is enabled' do
124
- allow(described_object.config).to receive(:silent_mode).and_return(true)
125
- result = nil
126
-
127
- VCR.use_cassette('import') do
128
- expect(-> { result = described_object.import! }).not_to output(/complete!/).to_stdout
129
- end
130
-
131
- expect(result).to be true
132
- expect_file_exist loc_path, 'en_1.yml'
133
- expect_file_exist loc_path, 'ru_2.yml'
134
- expect(described_object.config).to have_received(:silent_mode).at_most(1).times
135
- end
136
- end
137
-
138
- context 'when directory is not empty and safe mode enabled' do
139
- let(:safe_mode_obj) do
140
- described_class.new project_id: project_id,
141
- api_token: ENV['LOKALISE_API_TOKEN'],
142
- import_safe_mode: true
143
- end
144
-
145
- before :all do
146
- mkdir_locales
147
- end
148
-
149
- before do
150
- rm_translation_files
151
- add_translation_files!
152
- end
153
-
154
- after :all do
155
- rm_translation_files
156
- end
157
-
158
- it 'import proceeds when the user agrees' do
159
- allow(safe_mode_obj).to receive(:download_files).and_return(
160
- {
161
- 'project_id' => '123.abc',
162
- 'bundle_url' => local_trans
163
- }
164
- )
165
-
166
- allow($stdin).to receive(:gets).and_return('Y')
167
- expect(-> { safe_mode_obj.import! }).to output(/is not empty/).to_stdout
168
-
169
- expect(count_translations).to eq(5)
170
- expect($stdin).to have_received(:gets)
171
- expect(safe_mode_obj).to have_received(:download_files)
172
- expect_file_exist loc_path, 'en/nested/main_en.yml'
173
- expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml'
174
- expect_file_exist loc_path, 'ru/main_ru.yml'
175
- end
176
-
177
- it 'import halts when a user chooses not to proceed' do
178
- allow(safe_mode_obj).to receive(:download_files).at_most(0).times
179
- allow($stdin).to receive(:gets).and_return('N')
180
- expect(-> { safe_mode_obj.import! }).to output(/cancelled/).to_stdout
181
-
182
- expect(safe_mode_obj).not_to have_received(:download_files)
183
- expect($stdin).to have_received(:gets)
184
- expect(count_translations).to eq(1)
185
- end
186
-
187
- it 'import halts when a user chooses not to proceed and debug info is not printed out when silent_mode is enabled' do
188
- allow(safe_mode_obj.config).to receive(:silent_mode).and_return(true)
189
- allow(safe_mode_obj).to receive(:download_files).at_most(0).times
190
- allow($stdin).to receive(:gets).and_return('N')
191
- expect(-> { safe_mode_obj.import! }).not_to output(/cancelled/).to_stdout
192
-
193
- expect(safe_mode_obj).not_to have_received(:download_files)
194
- expect(safe_mode_obj.config).to have_received(:silent_mode)
195
- expect($stdin).to have_received(:gets)
196
- expect(count_translations).to eq(1)
197
- end
198
- end
199
- end
200
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe LokaliseManager do
4
- it 'returns a proper version' do
5
- expect(described_class::VERSION).to be_a(String)
6
- end
7
-
8
- specify '.importer' do
9
- expect(described_class.importer).to be_a(LokaliseManager::TaskDefinitions::Importer)
10
- end
11
-
12
- specify '.exporter' do
13
- expect(described_class.exporter).to be_a(LokaliseManager::TaskDefinitions::Exporter)
14
- end
15
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe LokaliseManager::Utils::ArrayUtils do
4
- using described_class
5
- let(:arr) { (1..8).to_a }
6
-
7
- describe '#in_groups_of' do
8
- it 'raises an exception when the number is less than 1' do
9
- expect(-> { arr.in_groups_of(-1) }).to raise_error(ArgumentError)
10
- end
11
-
12
- it 'uses collection itself if fill_with is false' do
13
- enum = arr.in_groups_of(5, false)
14
- enum.next
15
- expect(enum.next.count).to eq(3)
16
- end
17
- end
18
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe LokaliseManager::Utils::HashUtils do
4
- using described_class
5
- let(:h1) { {a: 100, b: 200, c: {c1: 100}} }
6
- let(:h2) { {b: 250, c: {c1: 200}} }
7
-
8
- specify '#deep_merge' do
9
- result = h1.deep_merge(h2) { |_key, this_val, other_val| this_val + other_val }
10
- expect(result[:b]).to eq(450)
11
- expect(result[:c][:c1]).to eq(300)
12
- end
13
- end
data/spec/spec_helper.rb DELETED
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'dotenv/load'
4
- require 'simplecov'
5
-
6
- SimpleCov.start do
7
- add_filter 'spec/'
8
- add_filter '.github/'
9
- end
10
-
11
- if ENV['CI'] == 'true'
12
- require 'codecov'
13
- SimpleCov.formatter = SimpleCov::Formatter::Codecov
14
- end
15
-
16
- require 'lokalise_manager'
17
-
18
- # Support files
19
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
20
-
21
- RSpec.configure do |config|
22
- config.include FileManager
23
- config.include SpecAddons
24
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'fileutils'
4
-
5
- module FileManager
6
- def mkdir_locales
7
- FileUtils.mkdir_p(LokaliseManager::GlobalConfig.locales_path) unless File.directory?(LokaliseManager::GlobalConfig.locales_path)
8
- end
9
-
10
- def rm_translation_files
11
- FileUtils.rm_rf locales_dir
12
- end
13
-
14
- def locales_dir
15
- Dir["#{LokaliseManager::GlobalConfig.locales_path}/**/*"]
16
- end
17
-
18
- def count_translations
19
- locales_dir.count { |file| File.file?(file) }
20
- end
21
-
22
- def add_translation_files!(with_ru: false, additional: nil)
23
- FileUtils.mkdir_p "#{Dir.getwd}/locales/nested"
24
- open_and_write('locales/nested/en.yml') { |f| f.write en_data }
25
-
26
- return unless with_ru
27
-
28
- open_and_write('locales/ru.yml') { |f| f.write ru_data }
29
-
30
- return unless additional
31
-
32
- additional.times do |i|
33
- data = {'en' => {"key_#{i}" => "value #{i}"}}
34
-
35
- open_and_write("locales/en_#{i}.yml") { |f| f.write data.to_yaml }
36
- end
37
- end
38
-
39
- def open_and_write(rel_path, &block)
40
- return unless block
41
-
42
- File.open("#{Dir.getwd}/#{rel_path}", 'w+:UTF-8', &block)
43
- end
44
-
45
- private
46
-
47
- def en_data
48
- <<~DATA
49
- en:
50
- my_key: "My value"
51
- nested:
52
- key: "Value 2"
53
- DATA
54
- end
55
-
56
- def ru_data
57
- <<~DATA
58
- ru_RU:
59
- my_key: "Моё значение"
60
- nested:
61
- key: "Значение 2"
62
- DATA
63
- end
64
- end