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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 181b9ff8557660e02e6de8604fddd35d36d42686f0bb97c3fcc499ad0f9fdf07
|
|
4
|
+
data.tar.gz: d4f509c82cc4d151cdf42d8cf85f2185d1ae37128f364849c177f3b25a001945
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aed41259a2967a85e829bfeb2175bb705547fc28a7c5ea60c624df21cd09178e65dac28c6cebdffecb8a1bdfcac5431c81d936b003391a4bf305b4be27594ca0
|
|
7
|
+
data.tar.gz: feddedd0259ff5feb889dac5f83db5f03f942d03fcce641f4cf0c79d81cd70df7325f7a14e286001ffd7905ef49d98f8a76a379083895ebb589ad57a576375da
|
data/README.md
CHANGED
|
@@ -39,10 +39,10 @@ gem install lingodotdev
|
|
|
39
39
|
require 'lingodotdev'
|
|
40
40
|
|
|
41
41
|
# Create an engine instance
|
|
42
|
-
engine = LingoDotDev::Engine.new(api_key: 'your-api-key')
|
|
42
|
+
engine = LingoDotDev::Engine.new(api_key: 'your-api-key', engine_id: 'your-engine-id')
|
|
43
43
|
|
|
44
44
|
# Localize text
|
|
45
|
-
result = engine.localize_text('Hello world', target_locale: 'es')
|
|
45
|
+
result = engine.localize_text('Hello world', target_locale: 'es', source_locale: 'en')
|
|
46
46
|
puts result # => "Hola mundo"
|
|
47
47
|
```
|
|
48
48
|
|
|
@@ -53,29 +53,14 @@ puts result # => "Hola mundo"
|
|
|
53
53
|
Localize a simple string to a target locale:
|
|
54
54
|
|
|
55
55
|
```ruby
|
|
56
|
-
engine = LingoDotDev::Engine.new(api_key: 'your-api-key')
|
|
56
|
+
engine = LingoDotDev::Engine.new(api_key: 'your-api-key', engine_id: 'your-engine-id')
|
|
57
57
|
|
|
58
58
|
result = engine.localize_text(
|
|
59
59
|
'Hello world',
|
|
60
|
-
target_locale: 'es'
|
|
61
|
-
)
|
|
62
|
-
# => "Hola mundo"
|
|
63
|
-
|
|
64
|
-
# With source locale specified
|
|
65
|
-
result = engine.localize_text(
|
|
66
|
-
'Hello world',
|
|
67
|
-
target_locale: 'fr',
|
|
60
|
+
target_locale: 'es',
|
|
68
61
|
source_locale: 'en'
|
|
69
62
|
)
|
|
70
|
-
# => "
|
|
71
|
-
|
|
72
|
-
# Fast mode for quicker results
|
|
73
|
-
result = engine.localize_text(
|
|
74
|
-
'Hello world',
|
|
75
|
-
target_locale: 'de',
|
|
76
|
-
fast: true
|
|
77
|
-
)
|
|
78
|
-
# => "Hallo Welt"
|
|
63
|
+
# => "Hola mundo"
|
|
79
64
|
```
|
|
80
65
|
|
|
81
66
|
### Object localization
|
|
@@ -89,7 +74,7 @@ data = {
|
|
|
89
74
|
message: 'Welcome to our app'
|
|
90
75
|
}
|
|
91
76
|
|
|
92
|
-
result = engine.localize_object(data, target_locale: 'es')
|
|
77
|
+
result = engine.localize_object(data, target_locale: 'es', source_locale: 'en')
|
|
93
78
|
# => {
|
|
94
79
|
# greeting: "Hola",
|
|
95
80
|
# farewell: "Adiós",
|
|
@@ -108,7 +93,7 @@ chat = [
|
|
|
108
93
|
{ name: 'user', text: 'I need some information.' }
|
|
109
94
|
]
|
|
110
95
|
|
|
111
|
-
result = engine.localize_chat(chat, target_locale: 'ja')
|
|
96
|
+
result = engine.localize_chat(chat, target_locale: 'ja', source_locale: 'en')
|
|
112
97
|
# => [
|
|
113
98
|
# { name: 'user', text: 'こんにちは!' },
|
|
114
99
|
# { name: 'assistant', text: 'こんにちは!どのようにお手伝いできますか?' },
|
|
@@ -136,7 +121,7 @@ html = <<~HTML
|
|
|
136
121
|
</html>
|
|
137
122
|
HTML
|
|
138
123
|
|
|
139
|
-
result = engine.localize_html(html, target_locale: 'es')
|
|
124
|
+
result = engine.localize_html(html, target_locale: 'es', source_locale: 'en')
|
|
140
125
|
# => HTML with localized text content and attributes, lang="es" attribute updated
|
|
141
126
|
```
|
|
142
127
|
|
|
@@ -156,7 +141,8 @@ Localize the same content to multiple target locales:
|
|
|
156
141
|
# Batch localize text
|
|
157
142
|
results = engine.batch_localize_text(
|
|
158
143
|
'Hello world',
|
|
159
|
-
target_locales: ['es', 'fr', 'de']
|
|
144
|
+
target_locales: ['es', 'fr', 'de'],
|
|
145
|
+
source_locale: 'en'
|
|
160
146
|
)
|
|
161
147
|
# => ["Hola mundo", "Bonjour le monde", "Hallo Welt"]
|
|
162
148
|
|
|
@@ -164,6 +150,7 @@ results = engine.batch_localize_text(
|
|
|
164
150
|
results = engine.batch_localize_text(
|
|
165
151
|
'Hello world',
|
|
166
152
|
target_locales: ['es', 'fr', 'de', 'ja'],
|
|
153
|
+
source_locale: 'en',
|
|
167
154
|
concurrent: true
|
|
168
155
|
)
|
|
169
156
|
```
|
|
@@ -182,6 +169,7 @@ objects = [
|
|
|
182
169
|
results = engine.batch_localize_objects(
|
|
183
170
|
objects,
|
|
184
171
|
target_locale: 'es',
|
|
172
|
+
source_locale: 'en',
|
|
185
173
|
concurrent: true
|
|
186
174
|
)
|
|
187
175
|
# => [
|
|
@@ -198,9 +186,6 @@ Automatically detect the locale of a given text:
|
|
|
198
186
|
```ruby
|
|
199
187
|
locale = engine.recognize_locale('Bonjour le monde')
|
|
200
188
|
# => "fr"
|
|
201
|
-
|
|
202
|
-
locale = engine.recognize_locale('こんにちは世界')
|
|
203
|
-
# => "ja"
|
|
204
189
|
```
|
|
205
190
|
|
|
206
191
|
### Progress tracking
|
|
@@ -209,7 +194,7 @@ Monitor localization progress with callbacks:
|
|
|
209
194
|
|
|
210
195
|
```ruby
|
|
211
196
|
# Using a block
|
|
212
|
-
result = engine.localize_text('Hello world', target_locale: 'es') do |progress|
|
|
197
|
+
result = engine.localize_text('Hello world', target_locale: 'es', source_locale: 'en') do |progress|
|
|
213
198
|
puts "Progress: #{progress}%"
|
|
214
199
|
end
|
|
215
200
|
|
|
@@ -218,6 +203,7 @@ callback = proc { |progress| puts "Progress: #{progress}%" }
|
|
|
218
203
|
result = engine.localize_text(
|
|
219
204
|
'Hello world',
|
|
220
205
|
target_locale: 'es',
|
|
206
|
+
source_locale: 'en',
|
|
221
207
|
on_progress: callback
|
|
222
208
|
)
|
|
223
209
|
```
|
|
@@ -236,6 +222,7 @@ reference = {
|
|
|
236
222
|
result = engine.localize_text(
|
|
237
223
|
'Hello',
|
|
238
224
|
target_locale: 'ja',
|
|
225
|
+
source_locale: 'en',
|
|
239
226
|
reference: reference
|
|
240
227
|
)
|
|
241
228
|
```
|
|
@@ -249,21 +236,27 @@ For one-off translations without managing engine instances:
|
|
|
249
236
|
result = LingoDotDev::Engine.quick_translate(
|
|
250
237
|
'Hello world',
|
|
251
238
|
api_key: 'your-api-key',
|
|
252
|
-
|
|
239
|
+
engine_id: 'your-engine-id',
|
|
240
|
+
target_locale: 'es',
|
|
241
|
+
source_locale: 'en'
|
|
253
242
|
)
|
|
254
243
|
|
|
255
244
|
# Quick translate a hash
|
|
256
245
|
result = LingoDotDev::Engine.quick_translate(
|
|
257
246
|
{ greeting: 'Hello', farewell: 'Goodbye' },
|
|
258
247
|
api_key: 'your-api-key',
|
|
259
|
-
|
|
248
|
+
engine_id: 'your-engine-id',
|
|
249
|
+
target_locale: 'fr',
|
|
250
|
+
source_locale: 'en'
|
|
260
251
|
)
|
|
261
252
|
|
|
262
253
|
# Quick batch translate to multiple locales
|
|
263
254
|
results = LingoDotDev::Engine.quick_batch_translate(
|
|
264
255
|
'Hello',
|
|
265
256
|
api_key: 'your-api-key',
|
|
266
|
-
|
|
257
|
+
engine_id: 'your-engine-id',
|
|
258
|
+
target_locales: ['es', 'fr', 'de'],
|
|
259
|
+
source_locale: 'en'
|
|
267
260
|
)
|
|
268
261
|
```
|
|
269
262
|
|
|
@@ -283,7 +276,8 @@ The SDK can be configured when creating an engine instance:
|
|
|
283
276
|
```ruby
|
|
284
277
|
engine = LingoDotDev::Engine.new(
|
|
285
278
|
api_key: 'your-api-key', # Required: Your Lingo.dev API key
|
|
286
|
-
|
|
279
|
+
engine_id: 'your-engine-id', # Optional: Your engine ID
|
|
280
|
+
api_url: 'https://api.lingo.dev', # Optional: API endpoint URL
|
|
287
281
|
batch_size: 25, # Optional: Max items per batch (1-250)
|
|
288
282
|
ideal_batch_item_size: 250 # Optional: Target word count per batch (1-2500)
|
|
289
283
|
)
|
|
@@ -292,7 +286,7 @@ engine = LingoDotDev::Engine.new(
|
|
|
292
286
|
You can also configure using a block:
|
|
293
287
|
|
|
294
288
|
```ruby
|
|
295
|
-
engine = LingoDotDev::Engine.new(api_key: 'your-api-key') do |config|
|
|
289
|
+
engine = LingoDotDev::Engine.new(api_key: 'your-api-key', engine_id: 'your-engine-id') do |config|
|
|
296
290
|
config.batch_size = 50
|
|
297
291
|
config.ideal_batch_item_size = 500
|
|
298
292
|
end
|
|
@@ -303,7 +297,8 @@ end
|
|
|
303
297
|
| Option | Type | Default | Description |
|
|
304
298
|
| ----------------------- | ------- | -------------------------- | ----------------------------------------- |
|
|
305
299
|
| `api_key` | String | Required | Your Lingo.dev API key |
|
|
306
|
-
| `
|
|
300
|
+
| `engine_id` | String | `nil` | Your engine ID for localization processing|
|
|
301
|
+
| `api_url` | String | `https://api.lingo.dev` | API endpoint URL |
|
|
307
302
|
| `batch_size` | Integer | `25` | Maximum items per batch (1-250) |
|
|
308
303
|
| `ideal_batch_item_size` | Integer | `250` | Target word count per batch item (1-2500) |
|
|
309
304
|
|
|
@@ -311,51 +306,49 @@ end
|
|
|
311
306
|
|
|
312
307
|
### Instance methods
|
|
313
308
|
|
|
314
|
-
#### `localize_text(text, target_locale:, source_locale
|
|
309
|
+
#### `localize_text(text, target_locale:, source_locale:, reference: nil, on_progress: nil, concurrent: false, &block)`
|
|
315
310
|
|
|
316
311
|
Localizes a string to the target locale.
|
|
317
312
|
|
|
318
313
|
- **Parameters:**
|
|
319
314
|
- `text` (String): Text to localize
|
|
320
315
|
- `target_locale` (String): Target locale code (e.g., 'es', 'fr', 'ja')
|
|
321
|
-
- `source_locale` (String
|
|
322
|
-
- `fast` (Boolean, optional): Enable fast mode
|
|
316
|
+
- `source_locale` (String): Source locale code (e.g., 'en')
|
|
323
317
|
- `reference` (Hash, optional): Additional context for translation
|
|
324
318
|
- `on_progress` (Proc, optional): Progress callback
|
|
325
319
|
- `concurrent` (Boolean): Enable concurrent processing
|
|
326
320
|
- `&block`: Alternative progress callback
|
|
327
321
|
- **Returns:** Localized string
|
|
328
322
|
|
|
329
|
-
#### `localize_object(obj, target_locale:, source_locale
|
|
323
|
+
#### `localize_object(obj, target_locale:, source_locale:, reference: nil, on_progress: nil, concurrent: false, &block)`
|
|
330
324
|
|
|
331
325
|
Localizes all string values in a Hash.
|
|
332
326
|
|
|
333
327
|
- **Parameters:** Same as `localize_text`, with `obj` (Hash) instead of `text`
|
|
334
328
|
- **Returns:** Localized Hash
|
|
335
329
|
|
|
336
|
-
#### `localize_chat(chat, target_locale:, source_locale
|
|
330
|
+
#### `localize_chat(chat, target_locale:, source_locale:, reference: nil, on_progress: nil, concurrent: false, &block)`
|
|
337
331
|
|
|
338
332
|
Localizes chat messages. Each message must have `:name` and `:text` keys.
|
|
339
333
|
|
|
340
334
|
- **Parameters:** Same as `localize_text`, with `chat` (Array) instead of `text`
|
|
341
335
|
- **Returns:** Array of localized chat messages
|
|
342
336
|
|
|
343
|
-
#### `localize_html(html, target_locale:, source_locale
|
|
337
|
+
#### `localize_html(html, target_locale:, source_locale:, reference: nil, on_progress: nil, concurrent: false, &block)`
|
|
344
338
|
|
|
345
339
|
Localizes an HTML document while preserving structure and formatting. Handles both text content and localizable attributes (alt, title, placeholder, meta content).
|
|
346
340
|
|
|
347
341
|
- **Parameters:**
|
|
348
342
|
- `html` (String): HTML document string to localize
|
|
349
343
|
- `target_locale` (String): Target locale code (e.g., 'es', 'fr', 'ja')
|
|
350
|
-
- `source_locale` (String
|
|
351
|
-
- `fast` (Boolean, optional): Enable fast mode
|
|
344
|
+
- `source_locale` (String): Source locale code (e.g., 'en')
|
|
352
345
|
- `reference` (Hash, optional): Additional context for translation
|
|
353
346
|
- `on_progress` (Proc, optional): Progress callback
|
|
354
347
|
- `concurrent` (Boolean): Enable concurrent processing
|
|
355
348
|
- `&block`: Alternative progress callback
|
|
356
349
|
- **Returns:** Localized HTML document string with updated `lang` attribute
|
|
357
350
|
|
|
358
|
-
#### `batch_localize_text(text, target_locales:, source_locale
|
|
351
|
+
#### `batch_localize_text(text, target_locales:, source_locale:, reference: nil, concurrent: false)`
|
|
359
352
|
|
|
360
353
|
Localizes text to multiple target locales.
|
|
361
354
|
|
|
@@ -365,7 +358,7 @@ Localizes text to multiple target locales.
|
|
|
365
358
|
- Other parameters same as `localize_text`
|
|
366
359
|
- **Returns:** Array of localized strings
|
|
367
360
|
|
|
368
|
-
#### `batch_localize_objects(objects, target_locale:, source_locale
|
|
361
|
+
#### `batch_localize_objects(objects, target_locale:, source_locale:, reference: nil, concurrent: false)`
|
|
369
362
|
|
|
370
363
|
Localizes multiple objects to the same target locale.
|
|
371
364
|
|
|
@@ -391,7 +384,7 @@ Returns information about the authenticated user.
|
|
|
391
384
|
|
|
392
385
|
### Class methods
|
|
393
386
|
|
|
394
|
-
#### `Engine.quick_translate(content, api_key:,
|
|
387
|
+
#### `Engine.quick_translate(content, api_key:, engine_id: nil, target_locale:, source_locale:, api_url: 'https://api.lingo.dev')`
|
|
395
388
|
|
|
396
389
|
One-off translation without managing engine lifecycle.
|
|
397
390
|
|
|
@@ -400,7 +393,7 @@ One-off translation without managing engine lifecycle.
|
|
|
400
393
|
- Other parameters as in instance methods
|
|
401
394
|
- **Returns:** Translated String or Hash
|
|
402
395
|
|
|
403
|
-
#### `Engine.quick_batch_translate(content, api_key:,
|
|
396
|
+
#### `Engine.quick_batch_translate(content, api_key:, engine_id: nil, target_locales:, source_locale:, api_url: 'https://api.lingo.dev')`
|
|
404
397
|
|
|
405
398
|
One-off batch translation to multiple locales.
|
|
406
399
|
|
|
@@ -417,7 +410,7 @@ The SDK defines custom exception classes for different error scenarios:
|
|
|
417
410
|
```ruby
|
|
418
411
|
begin
|
|
419
412
|
engine = LingoDotDev::Engine.new(api_key: 'your-api-key')
|
|
420
|
-
result = engine.localize_text('Hello', target_locale: 'es')
|
|
413
|
+
result = engine.localize_text('Hello', target_locale: 'es', source_locale: 'en')
|
|
421
414
|
rescue LingoDotDev::ValidationError => e
|
|
422
415
|
# Invalid input or configuration
|
|
423
416
|
puts "Validation error: #{e.message}"
|