lingodotdev 0.1.0 → 0.2.0
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/README.md +40 -47
- data/lib/lingodotdev/version.rb +1 -1
- data/lib/lingodotdev.rb +82 -71
- data/spec/lingo_dot_dev/configuration_spec.rb +14 -1
- data/spec/lingo_dot_dev/engine_spec.rb +126 -138
- metadata +2 -2
|
@@ -4,19 +4,28 @@ require 'spec_helper'
|
|
|
4
4
|
|
|
5
5
|
RSpec.describe LingoDotDev::Engine do
|
|
6
6
|
let(:api_key) { ENV['LINGODOTDEV_API_KEY'] }
|
|
7
|
-
let(:
|
|
7
|
+
let(:engine_id) { ENV['LINGODOTDEV_ENGINE_ID'] }
|
|
8
|
+
let(:api_url) { 'https://api.lingo.dev' }
|
|
8
9
|
let(:target_locale) { 'es' }
|
|
9
10
|
let(:source_locale) { 'en' }
|
|
10
11
|
|
|
11
12
|
describe 'initialization' do
|
|
12
|
-
it 'creates an engine with valid api_key' do
|
|
13
|
+
it 'creates an engine with valid api_key and engine_id' do
|
|
14
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
15
|
+
expect(engine.config.api_key).to eq(api_key)
|
|
16
|
+
expect(engine.config.engine_id).to eq(engine_id)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'creates an engine without engine_id' do
|
|
13
20
|
engine = described_class.new(api_key: api_key)
|
|
14
21
|
expect(engine.config.api_key).to eq(api_key)
|
|
22
|
+
expect(engine.config.engine_id).to be_nil
|
|
15
23
|
end
|
|
16
24
|
|
|
17
25
|
it 'creates engine with custom configuration' do
|
|
18
26
|
engine = described_class.new(
|
|
19
27
|
api_key: api_key,
|
|
28
|
+
engine_id: engine_id,
|
|
20
29
|
api_url: 'https://custom.example.com',
|
|
21
30
|
batch_size: 50,
|
|
22
31
|
ideal_batch_item_size: 500
|
|
@@ -27,7 +36,7 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
27
36
|
end
|
|
28
37
|
|
|
29
38
|
it 'allows block-based configuration' do
|
|
30
|
-
engine = described_class.new(api_key: api_key) do |config|
|
|
39
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id) do |config|
|
|
31
40
|
config.batch_size = 75
|
|
32
41
|
end
|
|
33
42
|
expect(engine.config.batch_size).to eq(75)
|
|
@@ -36,17 +45,7 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
36
45
|
|
|
37
46
|
describe '#localize_text' do
|
|
38
47
|
it 'localizes text to target locale' do
|
|
39
|
-
engine = described_class.new(api_key: api_key)
|
|
40
|
-
result = engine.localize_text(
|
|
41
|
-
'Hello world',
|
|
42
|
-
target_locale: target_locale
|
|
43
|
-
)
|
|
44
|
-
expect(result).to be_a(String)
|
|
45
|
-
expect(result.length).to be > 0
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'localizes text with source locale specified' do
|
|
49
|
-
engine = described_class.new(api_key: api_key)
|
|
48
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
50
49
|
result = engine.localize_text(
|
|
51
50
|
'Hello world',
|
|
52
51
|
target_locale: target_locale,
|
|
@@ -57,10 +56,11 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
57
56
|
end
|
|
58
57
|
|
|
59
58
|
it 'localizes text with fast flag' do
|
|
60
|
-
engine = described_class.new(api_key: api_key)
|
|
59
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
61
60
|
result = engine.localize_text(
|
|
62
61
|
'Hello world',
|
|
63
62
|
target_locale: target_locale,
|
|
63
|
+
source_locale: source_locale,
|
|
64
64
|
fast: true
|
|
65
65
|
)
|
|
66
66
|
expect(result).to be_a(String)
|
|
@@ -68,11 +68,12 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
it 'localizes text with reference context' do
|
|
71
|
-
engine = described_class.new(api_key: api_key)
|
|
71
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
72
72
|
reference = { context: 'greeting' }
|
|
73
73
|
result = engine.localize_text(
|
|
74
74
|
'Hello',
|
|
75
75
|
target_locale: target_locale,
|
|
76
|
+
source_locale: source_locale,
|
|
76
77
|
reference: reference
|
|
77
78
|
)
|
|
78
79
|
expect(result).to be_a(String)
|
|
@@ -80,201 +81,189 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
80
81
|
end
|
|
81
82
|
|
|
82
83
|
it 'supports progress callback block' do
|
|
83
|
-
engine = described_class.new(api_key: api_key)
|
|
84
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
84
85
|
progress_updates = []
|
|
85
86
|
result = engine.localize_text(
|
|
86
87
|
'Hello world',
|
|
87
|
-
target_locale: target_locale
|
|
88
|
+
target_locale: target_locale,
|
|
89
|
+
source_locale: source_locale
|
|
88
90
|
) { |progress| progress_updates << progress }
|
|
89
91
|
expect(result).to be_a(String)
|
|
90
92
|
expect(progress_updates).not_to be_empty if result.length > 0
|
|
91
93
|
end
|
|
92
94
|
|
|
93
95
|
it 'supports on_progress callback parameter' do
|
|
94
|
-
engine = described_class.new(api_key: api_key)
|
|
96
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
95
97
|
progress_updates = []
|
|
96
98
|
result = engine.localize_text(
|
|
97
99
|
'Hello world',
|
|
98
100
|
target_locale: target_locale,
|
|
101
|
+
source_locale: source_locale,
|
|
99
102
|
on_progress: proc { |progress| progress_updates << progress }
|
|
100
103
|
)
|
|
101
104
|
expect(result).to be_a(String)
|
|
102
105
|
end
|
|
103
106
|
|
|
104
107
|
it 'raises ValidationError when target_locale is nil' do
|
|
105
|
-
engine = described_class.new(api_key: api_key)
|
|
108
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
106
109
|
expect {
|
|
107
|
-
engine.localize_text('Hello', target_locale: nil)
|
|
110
|
+
engine.localize_text('Hello', target_locale: nil, source_locale: source_locale)
|
|
108
111
|
}.to raise_error(LingoDotDev::ValidationError, /Target locale is required/)
|
|
109
112
|
end
|
|
110
113
|
|
|
111
114
|
it 'raises ValidationError when target_locale is empty' do
|
|
112
|
-
engine = described_class.new(api_key: api_key)
|
|
115
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
113
116
|
expect {
|
|
114
|
-
engine.localize_text('Hello', target_locale: '')
|
|
117
|
+
engine.localize_text('Hello', target_locale: '', source_locale: source_locale)
|
|
115
118
|
}.to raise_error(LingoDotDev::ValidationError, /Target locale is required/)
|
|
116
119
|
end
|
|
117
120
|
|
|
118
121
|
it 'raises ValidationError when text is nil' do
|
|
119
|
-
engine = described_class.new(api_key: api_key)
|
|
122
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
120
123
|
expect {
|
|
121
|
-
engine.localize_text(nil, target_locale: target_locale)
|
|
124
|
+
engine.localize_text(nil, target_locale: target_locale, source_locale: source_locale)
|
|
122
125
|
}.to raise_error(LingoDotDev::ValidationError, /Text cannot be nil/)
|
|
123
126
|
end
|
|
124
127
|
end
|
|
125
128
|
|
|
126
129
|
describe '#localize_object' do
|
|
127
130
|
it 'localizes a hash object to target locale' do
|
|
128
|
-
engine = described_class.new(api_key: api_key)
|
|
131
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
129
132
|
obj = { greeting: 'Hello', farewell: 'Goodbye' }
|
|
130
|
-
result = engine.localize_object(
|
|
131
|
-
obj,
|
|
132
|
-
target_locale: target_locale
|
|
133
|
-
)
|
|
134
|
-
expect(result).to be_a(Hash)
|
|
135
|
-
expect(result.keys).to include('greeting', 'farewell')
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
it 'localizes object with source locale' do
|
|
139
|
-
engine = described_class.new(api_key: api_key)
|
|
140
|
-
obj = { message: 'Hello world' }
|
|
141
133
|
result = engine.localize_object(
|
|
142
134
|
obj,
|
|
143
135
|
target_locale: target_locale,
|
|
144
136
|
source_locale: source_locale
|
|
145
137
|
)
|
|
146
138
|
expect(result).to be_a(Hash)
|
|
139
|
+
expect(result.keys).to include('greeting', 'farewell')
|
|
147
140
|
end
|
|
148
141
|
|
|
149
142
|
it 'localizes object with fast flag' do
|
|
150
|
-
engine = described_class.new(api_key: api_key)
|
|
143
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
151
144
|
obj = { greeting: 'Hi' }
|
|
152
145
|
result = engine.localize_object(
|
|
153
146
|
obj,
|
|
154
147
|
target_locale: target_locale,
|
|
148
|
+
source_locale: source_locale,
|
|
155
149
|
fast: true
|
|
156
150
|
)
|
|
157
151
|
expect(result).to be_a(Hash)
|
|
158
152
|
end
|
|
159
153
|
|
|
160
154
|
it 'supports progress callback for objects' do
|
|
161
|
-
engine = described_class.new(api_key: api_key)
|
|
155
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
162
156
|
obj = { text: 'Hello' }
|
|
163
157
|
progress_updates = []
|
|
164
158
|
result = engine.localize_object(
|
|
165
159
|
obj,
|
|
166
|
-
target_locale: target_locale
|
|
160
|
+
target_locale: target_locale,
|
|
161
|
+
source_locale: source_locale
|
|
167
162
|
) { |progress| progress_updates << progress }
|
|
168
163
|
expect(result).to be_a(Hash)
|
|
169
164
|
end
|
|
170
165
|
|
|
171
166
|
it 'raises ValidationError when target_locale is nil' do
|
|
172
|
-
engine = described_class.new(api_key: api_key)
|
|
167
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
173
168
|
expect {
|
|
174
|
-
engine.localize_object({ text: 'Hello' }, target_locale: nil)
|
|
169
|
+
engine.localize_object({ text: 'Hello' }, target_locale: nil, source_locale: source_locale)
|
|
175
170
|
}.to raise_error(LingoDotDev::ValidationError, /Target locale is required/)
|
|
176
171
|
end
|
|
177
172
|
|
|
178
173
|
it 'raises ValidationError when object is nil' do
|
|
179
|
-
engine = described_class.new(api_key: api_key)
|
|
174
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
180
175
|
expect {
|
|
181
|
-
engine.localize_object(nil, target_locale: target_locale)
|
|
176
|
+
engine.localize_object(nil, target_locale: target_locale, source_locale: source_locale)
|
|
182
177
|
}.to raise_error(LingoDotDev::ValidationError, /Object cannot be nil/)
|
|
183
178
|
end
|
|
184
179
|
|
|
185
180
|
it 'raises ValidationError when object is not a Hash' do
|
|
186
|
-
engine = described_class.new(api_key: api_key)
|
|
181
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
187
182
|
expect {
|
|
188
|
-
engine.localize_object('not a hash', target_locale: target_locale)
|
|
183
|
+
engine.localize_object('not a hash', target_locale: target_locale, source_locale: source_locale)
|
|
189
184
|
}.to raise_error(LingoDotDev::ValidationError, /Object must be a Hash/)
|
|
190
185
|
end
|
|
191
186
|
end
|
|
192
187
|
|
|
193
188
|
describe '#localize_chat' do
|
|
194
189
|
it 'localizes chat messages to target locale' do
|
|
195
|
-
engine = described_class.new(api_key: api_key)
|
|
190
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
196
191
|
chat = [
|
|
197
192
|
{ name: 'user', text: 'Hello!' },
|
|
198
193
|
{ name: 'assistant', text: 'Hi there!' }
|
|
199
194
|
]
|
|
200
|
-
result = engine.localize_chat(
|
|
201
|
-
chat,
|
|
202
|
-
target_locale: target_locale
|
|
203
|
-
)
|
|
204
|
-
expect(result).to be_an(Array)
|
|
205
|
-
expect(result.length).to eq(2)
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
it 'localizes chat with source locale' do
|
|
209
|
-
engine = described_class.new(api_key: api_key)
|
|
210
|
-
chat = [{ name: 'user', text: 'Hello' }]
|
|
211
195
|
result = engine.localize_chat(
|
|
212
196
|
chat,
|
|
213
197
|
target_locale: target_locale,
|
|
214
198
|
source_locale: source_locale
|
|
215
199
|
)
|
|
216
200
|
expect(result).to be_an(Array)
|
|
201
|
+
expect(result.length).to eq(2)
|
|
217
202
|
end
|
|
218
203
|
|
|
219
204
|
it 'localizes chat with fast flag' do
|
|
220
|
-
engine = described_class.new(api_key: api_key)
|
|
205
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
221
206
|
chat = [{ name: 'user', text: 'Hi' }]
|
|
222
207
|
result = engine.localize_chat(
|
|
223
208
|
chat,
|
|
224
209
|
target_locale: target_locale,
|
|
210
|
+
source_locale: source_locale,
|
|
225
211
|
fast: true
|
|
226
212
|
)
|
|
227
213
|
expect(result).to be_an(Array)
|
|
228
214
|
end
|
|
229
215
|
|
|
230
216
|
it 'supports progress callback for chat' do
|
|
231
|
-
engine = described_class.new(api_key: api_key)
|
|
217
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
232
218
|
chat = [{ name: 'user', text: 'Hello' }]
|
|
233
219
|
progress_updates = []
|
|
234
220
|
result = engine.localize_chat(
|
|
235
221
|
chat,
|
|
236
|
-
target_locale: target_locale
|
|
222
|
+
target_locale: target_locale,
|
|
223
|
+
source_locale: source_locale
|
|
237
224
|
) { |progress| progress_updates << progress }
|
|
238
225
|
expect(result).to be_an(Array)
|
|
239
226
|
end
|
|
240
227
|
|
|
241
228
|
it 'raises ValidationError when target_locale is nil' do
|
|
242
|
-
engine = described_class.new(api_key: api_key)
|
|
229
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
243
230
|
expect {
|
|
244
|
-
engine.localize_chat([], target_locale: nil)
|
|
231
|
+
engine.localize_chat([], target_locale: nil, source_locale: source_locale)
|
|
245
232
|
}.to raise_error(LingoDotDev::ValidationError, /Target locale is required/)
|
|
246
233
|
end
|
|
247
234
|
|
|
248
235
|
it 'raises ValidationError when chat is nil' do
|
|
249
|
-
engine = described_class.new(api_key: api_key)
|
|
236
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
250
237
|
expect {
|
|
251
|
-
engine.localize_chat(nil, target_locale: target_locale)
|
|
238
|
+
engine.localize_chat(nil, target_locale: target_locale, source_locale: source_locale)
|
|
252
239
|
}.to raise_error(LingoDotDev::ValidationError, /Chat cannot be nil/)
|
|
253
240
|
end
|
|
254
241
|
|
|
255
242
|
it 'raises ValidationError when chat is not an Array' do
|
|
256
|
-
engine = described_class.new(api_key: api_key)
|
|
243
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
257
244
|
expect {
|
|
258
|
-
engine.localize_chat({}, target_locale: target_locale)
|
|
245
|
+
engine.localize_chat({}, target_locale: target_locale, source_locale: source_locale)
|
|
259
246
|
}.to raise_error(LingoDotDev::ValidationError, /Chat must be an Array/)
|
|
260
247
|
end
|
|
261
248
|
|
|
262
249
|
it 'raises ValidationError when chat messages lack name' do
|
|
263
|
-
engine = described_class.new(api_key: api_key)
|
|
250
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
264
251
|
expect {
|
|
265
252
|
engine.localize_chat(
|
|
266
253
|
[{ text: 'Hello' }],
|
|
267
|
-
target_locale: target_locale
|
|
254
|
+
target_locale: target_locale,
|
|
255
|
+
source_locale: source_locale
|
|
268
256
|
)
|
|
269
257
|
}.to raise_error(LingoDotDev::ValidationError, /:name and :text keys/)
|
|
270
258
|
end
|
|
271
259
|
|
|
272
260
|
it 'raises ValidationError when chat messages lack text' do
|
|
273
|
-
engine = described_class.new(api_key: api_key)
|
|
261
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
274
262
|
expect {
|
|
275
263
|
engine.localize_chat(
|
|
276
264
|
[{ name: 'user' }],
|
|
277
|
-
target_locale: target_locale
|
|
265
|
+
target_locale: target_locale,
|
|
266
|
+
source_locale: source_locale
|
|
278
267
|
)
|
|
279
268
|
}.to raise_error(LingoDotDev::ValidationError, /:name and :text keys/)
|
|
280
269
|
end
|
|
@@ -309,7 +298,7 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
309
298
|
</html>
|
|
310
299
|
HTML
|
|
311
300
|
|
|
312
|
-
engine = described_class.new(api_key: api_key)
|
|
301
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
313
302
|
extracted_content = nil
|
|
314
303
|
call_params = nil
|
|
315
304
|
|
|
@@ -357,7 +346,7 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
357
346
|
|
|
358
347
|
it 'localizes HTML with source locale' do
|
|
359
348
|
html = '<html><head><title>Hello</title></head><body><p>World</p></body></html>'
|
|
360
|
-
engine = described_class.new(api_key: api_key)
|
|
349
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
361
350
|
call_params = nil
|
|
362
351
|
allow(engine).to receive(:localize_raw) do |content, params, &block|
|
|
363
352
|
call_params = params
|
|
@@ -373,82 +362,73 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
373
362
|
|
|
374
363
|
it 'localizes HTML with fast flag' do
|
|
375
364
|
html = '<html><head><title>Hello</title></head><body><p>World</p></body></html>'
|
|
376
|
-
engine = described_class.new(api_key: api_key)
|
|
365
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
377
366
|
call_params = nil
|
|
378
367
|
allow(engine).to receive(:localize_raw) do |content, params, &block|
|
|
379
368
|
call_params = params
|
|
380
369
|
{ 'head/0/0' => 'Hola', 'body/0/0' => 'Mundo' }
|
|
381
370
|
end
|
|
382
371
|
|
|
383
|
-
result = engine.localize_html(html, target_locale: 'es', fast: true)
|
|
372
|
+
result = engine.localize_html(html, target_locale: 'es', source_locale: 'en', fast: true)
|
|
384
373
|
|
|
385
374
|
expect(call_params[:fast]).to eq(true)
|
|
386
375
|
end
|
|
387
376
|
|
|
388
377
|
it 'supports progress callback for HTML' do
|
|
389
378
|
html = '<html><head><title>Hello</title></head><body><p>World</p></body></html>'
|
|
390
|
-
engine = described_class.new(api_key: api_key)
|
|
379
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
391
380
|
progress_updates = []
|
|
392
381
|
allow(engine).to receive(:localize_raw) do |content, params, &block|
|
|
393
382
|
block&.call(100, {}, {})
|
|
394
383
|
{ 'head/0/0' => 'Hola', 'body/0/0' => 'Mundo' }
|
|
395
384
|
end
|
|
396
385
|
|
|
397
|
-
result = engine.localize_html(html, target_locale: 'es') { |progress| progress_updates << progress }
|
|
386
|
+
result = engine.localize_html(html, target_locale: 'es', source_locale: 'en') { |progress| progress_updates << progress }
|
|
398
387
|
|
|
399
388
|
expect(progress_updates).not_to be_empty
|
|
400
389
|
end
|
|
401
390
|
|
|
402
391
|
it 'raises ValidationError when target_locale is nil' do
|
|
403
|
-
engine = described_class.new(api_key: api_key)
|
|
392
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
404
393
|
expect {
|
|
405
|
-
engine.localize_html('<html></html>', target_locale: nil)
|
|
394
|
+
engine.localize_html('<html></html>', target_locale: nil, source_locale: source_locale)
|
|
406
395
|
}.to raise_error(LingoDotDev::ValidationError, /Target locale is required/)
|
|
407
396
|
end
|
|
408
397
|
|
|
409
398
|
it 'raises ValidationError when target_locale is empty' do
|
|
410
|
-
engine = described_class.new(api_key: api_key)
|
|
399
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
411
400
|
expect {
|
|
412
|
-
engine.localize_html('<html></html>', target_locale: '')
|
|
401
|
+
engine.localize_html('<html></html>', target_locale: '', source_locale: source_locale)
|
|
413
402
|
}.to raise_error(LingoDotDev::ValidationError, /Target locale is required/)
|
|
414
403
|
end
|
|
415
404
|
|
|
416
405
|
it 'raises ValidationError when html is nil' do
|
|
417
|
-
engine = described_class.new(api_key: api_key)
|
|
406
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
418
407
|
expect {
|
|
419
|
-
engine.localize_html(nil, target_locale: 'es')
|
|
408
|
+
engine.localize_html(nil, target_locale: 'es', source_locale: source_locale)
|
|
420
409
|
}.to raise_error(LingoDotDev::ValidationError, /HTML cannot be nil/)
|
|
421
410
|
end
|
|
422
411
|
end
|
|
423
412
|
|
|
424
413
|
describe '#batch_localize_text' do
|
|
425
414
|
it 'batch localizes text to multiple locales' do
|
|
426
|
-
engine = described_class.new(api_key: api_key)
|
|
415
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
427
416
|
results = engine.batch_localize_text(
|
|
428
417
|
'Hello world',
|
|
429
|
-
target_locales: ['es', 'fr']
|
|
430
|
-
)
|
|
431
|
-
expect(results).to be_an(Array)
|
|
432
|
-
expect(results.length).to eq(2)
|
|
433
|
-
expect(results.all? { |r| r.is_a?(String) }).to be true
|
|
434
|
-
end
|
|
435
|
-
|
|
436
|
-
it 'batch localizes with source locale' do
|
|
437
|
-
engine = described_class.new(api_key: api_key)
|
|
438
|
-
results = engine.batch_localize_text(
|
|
439
|
-
'Hello',
|
|
440
|
-
target_locales: ['es', 'de'],
|
|
418
|
+
target_locales: ['es', 'fr'],
|
|
441
419
|
source_locale: source_locale
|
|
442
420
|
)
|
|
443
421
|
expect(results).to be_an(Array)
|
|
444
422
|
expect(results.length).to eq(2)
|
|
423
|
+
expect(results.all? { |r| r.is_a?(String) }).to be true
|
|
445
424
|
end
|
|
446
425
|
|
|
447
426
|
it 'batch localizes with fast flag' do
|
|
448
|
-
engine = described_class.new(api_key: api_key)
|
|
427
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
449
428
|
results = engine.batch_localize_text(
|
|
450
429
|
'Hi',
|
|
451
430
|
target_locales: ['es', 'fr'],
|
|
431
|
+
source_locale: source_locale,
|
|
452
432
|
fast: true
|
|
453
433
|
)
|
|
454
434
|
expect(results).to be_an(Array)
|
|
@@ -456,10 +436,11 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
456
436
|
end
|
|
457
437
|
|
|
458
438
|
it 'batch localizes concurrently' do
|
|
459
|
-
engine = described_class.new(api_key: api_key)
|
|
439
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
460
440
|
results = engine.batch_localize_text(
|
|
461
441
|
'Hello world',
|
|
462
442
|
target_locales: ['es', 'fr', 'de'],
|
|
443
|
+
source_locale: source_locale,
|
|
463
444
|
concurrent: true
|
|
464
445
|
)
|
|
465
446
|
expect(results).to be_an(Array)
|
|
@@ -467,67 +448,58 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
467
448
|
end
|
|
468
449
|
|
|
469
450
|
it 'raises ValidationError when text is nil' do
|
|
470
|
-
engine = described_class.new(api_key: api_key)
|
|
451
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
471
452
|
expect {
|
|
472
|
-
engine.batch_localize_text(nil, target_locales: ['es'])
|
|
453
|
+
engine.batch_localize_text(nil, target_locales: ['es'], source_locale: source_locale)
|
|
473
454
|
}.to raise_error(LingoDotDev::ValidationError, /Text cannot be nil/)
|
|
474
455
|
end
|
|
475
456
|
|
|
476
457
|
it 'raises ValidationError when target_locales is not an Array' do
|
|
477
|
-
engine = described_class.new(api_key: api_key)
|
|
458
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
478
459
|
expect {
|
|
479
|
-
engine.batch_localize_text('Hello', target_locales: 'es')
|
|
460
|
+
engine.batch_localize_text('Hello', target_locales: 'es', source_locale: source_locale)
|
|
480
461
|
}.to raise_error(LingoDotDev::ValidationError, /Target locales must be an Array/)
|
|
481
462
|
end
|
|
482
463
|
|
|
483
464
|
it 'raises ValidationError when target_locales is empty' do
|
|
484
|
-
engine = described_class.new(api_key: api_key)
|
|
465
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
485
466
|
expect {
|
|
486
|
-
engine.batch_localize_text('Hello', target_locales: [])
|
|
467
|
+
engine.batch_localize_text('Hello', target_locales: [], source_locale: source_locale)
|
|
487
468
|
}.to raise_error(LingoDotDev::ValidationError, /Target locales cannot be empty/)
|
|
488
469
|
end
|
|
489
470
|
end
|
|
490
471
|
|
|
491
472
|
describe '#batch_localize_objects' do
|
|
492
473
|
it 'batch localizes multiple objects to same locale' do
|
|
493
|
-
engine = described_class.new(api_key: api_key)
|
|
474
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
494
475
|
objects = [
|
|
495
476
|
{ greeting: 'Hello' },
|
|
496
477
|
{ farewell: 'Goodbye' }
|
|
497
478
|
]
|
|
498
|
-
results = engine.batch_localize_objects(
|
|
499
|
-
objects,
|
|
500
|
-
target_locale: target_locale
|
|
501
|
-
)
|
|
502
|
-
expect(results).to be_an(Array)
|
|
503
|
-
expect(results.length).to eq(2)
|
|
504
|
-
expect(results.all? { |r| r.is_a?(Hash) }).to be true
|
|
505
|
-
end
|
|
506
|
-
|
|
507
|
-
it 'batch localizes objects with source locale' do
|
|
508
|
-
engine = described_class.new(api_key: api_key)
|
|
509
|
-
objects = [{ text: 'Hello' }]
|
|
510
479
|
results = engine.batch_localize_objects(
|
|
511
480
|
objects,
|
|
512
481
|
target_locale: target_locale,
|
|
513
482
|
source_locale: source_locale
|
|
514
483
|
)
|
|
515
484
|
expect(results).to be_an(Array)
|
|
485
|
+
expect(results.length).to eq(2)
|
|
486
|
+
expect(results.all? { |r| r.is_a?(Hash) }).to be true
|
|
516
487
|
end
|
|
517
488
|
|
|
518
489
|
it 'batch localizes objects with fast flag' do
|
|
519
|
-
engine = described_class.new(api_key: api_key)
|
|
490
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
520
491
|
objects = [{ text: 'Hi' }]
|
|
521
492
|
results = engine.batch_localize_objects(
|
|
522
493
|
objects,
|
|
523
494
|
target_locale: target_locale,
|
|
495
|
+
source_locale: source_locale,
|
|
524
496
|
fast: true
|
|
525
497
|
)
|
|
526
498
|
expect(results).to be_an(Array)
|
|
527
499
|
end
|
|
528
500
|
|
|
529
501
|
it 'batch localizes objects concurrently' do
|
|
530
|
-
engine = described_class.new(api_key: api_key)
|
|
502
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
531
503
|
objects = [
|
|
532
504
|
{ text: 'Hello' },
|
|
533
505
|
{ text: 'Hi' },
|
|
@@ -536,6 +508,7 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
536
508
|
results = engine.batch_localize_objects(
|
|
537
509
|
objects,
|
|
538
510
|
target_locale: target_locale,
|
|
511
|
+
source_locale: source_locale,
|
|
539
512
|
concurrent: true
|
|
540
513
|
)
|
|
541
514
|
expect(results).to be_an(Array)
|
|
@@ -543,38 +516,41 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
543
516
|
end
|
|
544
517
|
|
|
545
518
|
it 'raises ValidationError when objects is not an Array' do
|
|
546
|
-
engine = described_class.new(api_key: api_key)
|
|
519
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
547
520
|
expect {
|
|
548
521
|
engine.batch_localize_objects(
|
|
549
522
|
{ text: 'Hello' },
|
|
550
|
-
target_locale: target_locale
|
|
523
|
+
target_locale: target_locale,
|
|
524
|
+
source_locale: source_locale
|
|
551
525
|
)
|
|
552
526
|
}.to raise_error(LingoDotDev::ValidationError, /Objects must be an Array/)
|
|
553
527
|
end
|
|
554
528
|
|
|
555
529
|
it 'raises ValidationError when objects is empty' do
|
|
556
|
-
engine = described_class.new(api_key: api_key)
|
|
530
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
557
531
|
expect {
|
|
558
|
-
engine.batch_localize_objects([], target_locale: target_locale)
|
|
532
|
+
engine.batch_localize_objects([], target_locale: target_locale, source_locale: source_locale)
|
|
559
533
|
}.to raise_error(LingoDotDev::ValidationError, /Objects cannot be empty/)
|
|
560
534
|
end
|
|
561
535
|
|
|
562
536
|
it 'raises ValidationError when target_locale is nil' do
|
|
563
|
-
engine = described_class.new(api_key: api_key)
|
|
537
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
564
538
|
expect {
|
|
565
539
|
engine.batch_localize_objects(
|
|
566
540
|
[{ text: 'Hello' }],
|
|
567
|
-
target_locale: nil
|
|
541
|
+
target_locale: nil,
|
|
542
|
+
source_locale: source_locale
|
|
568
543
|
)
|
|
569
544
|
}.to raise_error(LingoDotDev::ValidationError, /Target locale is required/)
|
|
570
545
|
end
|
|
571
546
|
|
|
572
547
|
it 'raises ValidationError when object is not a Hash' do
|
|
573
|
-
engine = described_class.new(api_key: api_key)
|
|
548
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
574
549
|
expect {
|
|
575
550
|
engine.batch_localize_objects(
|
|
576
551
|
['not a hash'],
|
|
577
|
-
target_locale: target_locale
|
|
552
|
+
target_locale: target_locale,
|
|
553
|
+
source_locale: source_locale
|
|
578
554
|
)
|
|
579
555
|
}.to raise_error(LingoDotDev::ValidationError, /Each object must be a Hash/)
|
|
580
556
|
end
|
|
@@ -582,28 +558,28 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
582
558
|
|
|
583
559
|
describe '#recognize_locale' do
|
|
584
560
|
it 'recognizes locale of given text' do
|
|
585
|
-
engine = described_class.new(api_key: api_key)
|
|
561
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
586
562
|
locale = engine.recognize_locale('Hello world')
|
|
587
563
|
expect(locale).to be_a(String)
|
|
588
564
|
expect(locale.length).to be > 0
|
|
589
565
|
end
|
|
590
566
|
|
|
591
567
|
it 'raises ValidationError when text is nil' do
|
|
592
|
-
engine = described_class.new(api_key: api_key)
|
|
568
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
593
569
|
expect {
|
|
594
570
|
engine.recognize_locale(nil)
|
|
595
571
|
}.to raise_error(LingoDotDev::ValidationError, /Text cannot be empty/)
|
|
596
572
|
end
|
|
597
573
|
|
|
598
574
|
it 'raises ValidationError when text is empty' do
|
|
599
|
-
engine = described_class.new(api_key: api_key)
|
|
575
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
600
576
|
expect {
|
|
601
577
|
engine.recognize_locale('')
|
|
602
578
|
}.to raise_error(LingoDotDev::ValidationError, /Text cannot be empty/)
|
|
603
579
|
end
|
|
604
580
|
|
|
605
581
|
it 'raises ValidationError when text is only whitespace' do
|
|
606
|
-
engine = described_class.new(api_key: api_key)
|
|
582
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
607
583
|
expect {
|
|
608
584
|
engine.recognize_locale(' ')
|
|
609
585
|
}.to raise_error(LingoDotDev::ValidationError, /Text cannot be empty/)
|
|
@@ -612,7 +588,7 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
612
588
|
|
|
613
589
|
describe '#whoami' do
|
|
614
590
|
it 'returns user information' do
|
|
615
|
-
engine = described_class.new(api_key: api_key)
|
|
591
|
+
engine = described_class.new(api_key: api_key, engine_id: engine_id)
|
|
616
592
|
result = engine.whoami
|
|
617
593
|
if result
|
|
618
594
|
expect(result).to be_a(Hash)
|
|
@@ -626,7 +602,9 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
626
602
|
result = described_class.quick_translate(
|
|
627
603
|
'Hello world',
|
|
628
604
|
api_key: api_key,
|
|
629
|
-
|
|
605
|
+
engine_id: engine_id,
|
|
606
|
+
target_locale: target_locale,
|
|
607
|
+
source_locale: source_locale
|
|
630
608
|
)
|
|
631
609
|
expect(result).to be_a(String)
|
|
632
610
|
expect(result.length).to be > 0
|
|
@@ -636,7 +614,9 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
636
614
|
result = described_class.quick_translate(
|
|
637
615
|
{ greeting: 'Hello', farewell: 'Goodbye' },
|
|
638
616
|
api_key: api_key,
|
|
639
|
-
|
|
617
|
+
engine_id: engine_id,
|
|
618
|
+
target_locale: target_locale,
|
|
619
|
+
source_locale: source_locale
|
|
640
620
|
)
|
|
641
621
|
expect(result).to be_a(Hash)
|
|
642
622
|
end
|
|
@@ -646,7 +626,9 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
646
626
|
described_class.quick_translate(
|
|
647
627
|
123,
|
|
648
628
|
api_key: api_key,
|
|
649
|
-
|
|
629
|
+
engine_id: engine_id,
|
|
630
|
+
target_locale: target_locale,
|
|
631
|
+
source_locale: source_locale
|
|
650
632
|
)
|
|
651
633
|
}.to raise_error(LingoDotDev::ValidationError, /Content must be a String or Hash/)
|
|
652
634
|
end
|
|
@@ -657,7 +639,9 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
657
639
|
results = described_class.quick_batch_translate(
|
|
658
640
|
'Hello',
|
|
659
641
|
api_key: api_key,
|
|
660
|
-
|
|
642
|
+
engine_id: engine_id,
|
|
643
|
+
target_locales: ['es', 'fr'],
|
|
644
|
+
source_locale: source_locale
|
|
661
645
|
)
|
|
662
646
|
expect(results).to be_an(Array)
|
|
663
647
|
expect(results.length).to eq(2)
|
|
@@ -668,7 +652,9 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
668
652
|
results = described_class.quick_batch_translate(
|
|
669
653
|
{ greeting: 'Hello' },
|
|
670
654
|
api_key: api_key,
|
|
671
|
-
|
|
655
|
+
engine_id: engine_id,
|
|
656
|
+
target_locales: ['es', 'fr'],
|
|
657
|
+
source_locale: source_locale
|
|
672
658
|
)
|
|
673
659
|
expect(results).to be_an(Array)
|
|
674
660
|
expect(results.length).to eq(2)
|
|
@@ -680,7 +666,9 @@ RSpec.describe LingoDotDev::Engine do
|
|
|
680
666
|
described_class.quick_batch_translate(
|
|
681
667
|
123,
|
|
682
668
|
api_key: api_key,
|
|
683
|
-
|
|
669
|
+
engine_id: engine_id,
|
|
670
|
+
target_locales: ['es'],
|
|
671
|
+
source_locale: source_locale
|
|
684
672
|
)
|
|
685
673
|
}.to raise_error(LingoDotDev::ValidationError, /Content must be a String or Hash/)
|
|
686
674
|
end
|