lingodotdev 0.1.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14034dfe2c60a19185f6097951589bcf8e34791d10bb4ac8cc2ed120702d061b
4
- data.tar.gz: 1405a8002ff6688494158e9da901bf58c7f1c60f144a1c5c287631a8cb4fc87e
3
+ metadata.gz: 28c83f0fada39ed4eec6b9d0b67917fac54a45fc6d8d11b50389f282f49a322c
4
+ data.tar.gz: bdca77419544b1253dd3aecc752f07a92c3acab361f8693d7069f3d74d247160
5
5
  SHA512:
6
- metadata.gz: b4e21ba8cb795eaf703440583d42370ea6750b43a215a5dba2a4a908e19e4ef21b0afec9bc6b45b4ca382b32e13f0ab8dc1c33ab102dda6274f4fac95a5bab9d
7
- data.tar.gz: 8b9efcb6a126f0c38f146c5b2125debd4fa14e2ab5a30baefec6703aefd7166330fdc1bc4f8b171b9a6b41697fad47c62e42bcb12e5d4b9e9734510080b30ad4
6
+ metadata.gz: 458753b774866b16fd4d960ba5e52bcff42b8c322ea3bab294943590ba0a04a09206182fbffcbf9c0fdd51269c542214a689da47893c9519efc7ee8961b2b730
7
+ data.tar.gz: e002510b545296b9b358713113e86d8f1a6aa08d233c2770b04e89730ad291fa6a77e85f2167cf32d3e3c574da048b6d48a3f08264287f1ce42657ed45a5c728
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
- # => "Bonjour le monde"
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,24 +203,25 @@ 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
  ```
224
210
 
225
211
  ### Reference context
226
212
 
227
- Provide additional context to improve translation accuracy:
213
+ Provide existing translations as reference to improve translation accuracy. The `reference` hash maps locale codes to key-value content objects:
228
214
 
229
215
  ```ruby
230
216
  reference = {
231
- context: 'greeting',
232
- tone: 'formal',
233
- domain: 'business'
217
+ 'es' => { 'greeting' => 'Hola', 'farewell' => 'Adiós' },
218
+ 'fr' => { 'greeting' => 'Bonjour', 'farewell' => 'Au revoir' }
234
219
  }
235
220
 
236
221
  result = engine.localize_text(
237
222
  'Hello',
238
223
  target_locale: 'ja',
224
+ source_locale: 'en',
239
225
  reference: reference
240
226
  )
241
227
  ```
@@ -249,21 +235,27 @@ For one-off translations without managing engine instances:
249
235
  result = LingoDotDev::Engine.quick_translate(
250
236
  'Hello world',
251
237
  api_key: 'your-api-key',
252
- target_locale: 'es'
238
+ engine_id: 'your-engine-id',
239
+ target_locale: 'es',
240
+ source_locale: 'en'
253
241
  )
254
242
 
255
243
  # Quick translate a hash
256
244
  result = LingoDotDev::Engine.quick_translate(
257
245
  { greeting: 'Hello', farewell: 'Goodbye' },
258
246
  api_key: 'your-api-key',
259
- target_locale: 'fr'
247
+ engine_id: 'your-engine-id',
248
+ target_locale: 'fr',
249
+ source_locale: 'en'
260
250
  )
261
251
 
262
252
  # Quick batch translate to multiple locales
263
253
  results = LingoDotDev::Engine.quick_batch_translate(
264
254
  'Hello',
265
255
  api_key: 'your-api-key',
266
- target_locales: ['es', 'fr', 'de']
256
+ engine_id: 'your-engine-id',
257
+ target_locales: ['es', 'fr', 'de'],
258
+ source_locale: 'en'
267
259
  )
268
260
  ```
269
261
 
@@ -283,7 +275,8 @@ The SDK can be configured when creating an engine instance:
283
275
  ```ruby
284
276
  engine = LingoDotDev::Engine.new(
285
277
  api_key: 'your-api-key', # Required: Your Lingo.dev API key
286
- api_url: 'https://engine.lingo.dev', # Optional: API endpoint URL
278
+ engine_id: 'your-engine-id', # Optional: Your engine ID
279
+ api_url: 'https://api.lingo.dev', # Optional: API endpoint URL
287
280
  batch_size: 25, # Optional: Max items per batch (1-250)
288
281
  ideal_batch_item_size: 250 # Optional: Target word count per batch (1-2500)
289
282
  )
@@ -292,7 +285,7 @@ engine = LingoDotDev::Engine.new(
292
285
  You can also configure using a block:
293
286
 
294
287
  ```ruby
295
- engine = LingoDotDev::Engine.new(api_key: 'your-api-key') do |config|
288
+ engine = LingoDotDev::Engine.new(api_key: 'your-api-key', engine_id: 'your-engine-id') do |config|
296
289
  config.batch_size = 50
297
290
  config.ideal_batch_item_size = 500
298
291
  end
@@ -303,7 +296,8 @@ end
303
296
  | Option | Type | Default | Description |
304
297
  | ----------------------- | ------- | -------------------------- | ----------------------------------------- |
305
298
  | `api_key` | String | Required | Your Lingo.dev API key |
306
- | `api_url` | String | `https://engine.lingo.dev` | API endpoint URL |
299
+ | `engine_id` | String | `nil` | Your engine ID for localization processing|
300
+ | `api_url` | String | `https://api.lingo.dev` | API endpoint URL |
307
301
  | `batch_size` | Integer | `25` | Maximum items per batch (1-250) |
308
302
  | `ideal_batch_item_size` | Integer | `250` | Target word count per batch item (1-2500) |
309
303
 
@@ -311,51 +305,49 @@ end
311
305
 
312
306
  ### Instance methods
313
307
 
314
- #### `localize_text(text, target_locale:, source_locale: nil, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)`
308
+ #### `localize_text(text, target_locale:, source_locale:, reference: nil, on_progress: nil, concurrent: false, &block)`
315
309
 
316
310
  Localizes a string to the target locale.
317
311
 
318
312
  - **Parameters:**
319
313
  - `text` (String): Text to localize
320
314
  - `target_locale` (String): Target locale code (e.g., 'es', 'fr', 'ja')
321
- - `source_locale` (String, optional): Source locale code
322
- - `fast` (Boolean, optional): Enable fast mode
323
- - `reference` (Hash, optional): Additional context for translation
315
+ - `source_locale` (String): Source locale code (e.g., 'en')
316
+ - `reference` (Hash, optional): Existing translations keyed by locale code, e.g. `{ 'es' => { 'key' => 'valor' } }`
324
317
  - `on_progress` (Proc, optional): Progress callback
325
318
  - `concurrent` (Boolean): Enable concurrent processing
326
319
  - `&block`: Alternative progress callback
327
320
  - **Returns:** Localized string
328
321
 
329
- #### `localize_object(obj, target_locale:, source_locale: nil, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)`
322
+ #### `localize_object(obj, target_locale:, source_locale:, reference: nil, on_progress: nil, concurrent: false, &block)`
330
323
 
331
324
  Localizes all string values in a Hash.
332
325
 
333
326
  - **Parameters:** Same as `localize_text`, with `obj` (Hash) instead of `text`
334
327
  - **Returns:** Localized Hash
335
328
 
336
- #### `localize_chat(chat, target_locale:, source_locale: nil, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)`
329
+ #### `localize_chat(chat, target_locale:, source_locale:, reference: nil, on_progress: nil, concurrent: false, &block)`
337
330
 
338
331
  Localizes chat messages. Each message must have `:name` and `:text` keys.
339
332
 
340
333
  - **Parameters:** Same as `localize_text`, with `chat` (Array) instead of `text`
341
334
  - **Returns:** Array of localized chat messages
342
335
 
343
- #### `localize_html(html, target_locale:, source_locale: nil, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)`
336
+ #### `localize_html(html, target_locale:, source_locale:, reference: nil, on_progress: nil, concurrent: false, &block)`
344
337
 
345
338
  Localizes an HTML document while preserving structure and formatting. Handles both text content and localizable attributes (alt, title, placeholder, meta content).
346
339
 
347
340
  - **Parameters:**
348
341
  - `html` (String): HTML document string to localize
349
342
  - `target_locale` (String): Target locale code (e.g., 'es', 'fr', 'ja')
350
- - `source_locale` (String, optional): Source locale code
351
- - `fast` (Boolean, optional): Enable fast mode
352
- - `reference` (Hash, optional): Additional context for translation
343
+ - `source_locale` (String): Source locale code (e.g., 'en')
344
+ - `reference` (Hash, optional): Existing translations keyed by locale code, e.g. `{ 'es' => { 'key' => 'valor' } }`
353
345
  - `on_progress` (Proc, optional): Progress callback
354
346
  - `concurrent` (Boolean): Enable concurrent processing
355
347
  - `&block`: Alternative progress callback
356
348
  - **Returns:** Localized HTML document string with updated `lang` attribute
357
349
 
358
- #### `batch_localize_text(text, target_locales:, source_locale: nil, fast: nil, reference: nil, concurrent: false)`
350
+ #### `batch_localize_text(text, target_locales:, source_locale:, reference: nil, concurrent: false)`
359
351
 
360
352
  Localizes text to multiple target locales.
361
353
 
@@ -365,7 +357,7 @@ Localizes text to multiple target locales.
365
357
  - Other parameters same as `localize_text`
366
358
  - **Returns:** Array of localized strings
367
359
 
368
- #### `batch_localize_objects(objects, target_locale:, source_locale: nil, fast: nil, reference: nil, concurrent: false)`
360
+ #### `batch_localize_objects(objects, target_locale:, source_locale:, reference: nil, concurrent: false)`
369
361
 
370
362
  Localizes multiple objects to the same target locale.
371
363
 
@@ -391,7 +383,7 @@ Returns information about the authenticated user.
391
383
 
392
384
  ### Class methods
393
385
 
394
- #### `Engine.quick_translate(content, api_key:, target_locale:, source_locale: nil, fast: true, api_url: 'https://engine.lingo.dev')`
386
+ #### `Engine.quick_translate(content, api_key:, engine_id: nil, target_locale:, source_locale:, api_url: 'https://api.lingo.dev')`
395
387
 
396
388
  One-off translation without managing engine lifecycle.
397
389
 
@@ -400,7 +392,7 @@ One-off translation without managing engine lifecycle.
400
392
  - Other parameters as in instance methods
401
393
  - **Returns:** Translated String or Hash
402
394
 
403
- #### `Engine.quick_batch_translate(content, api_key:, target_locales:, source_locale: nil, fast: true, api_url: 'https://engine.lingo.dev')`
395
+ #### `Engine.quick_batch_translate(content, api_key:, engine_id: nil, target_locales:, source_locale:, api_url: 'https://api.lingo.dev')`
404
396
 
405
397
  One-off batch translation to multiple locales.
406
398
 
@@ -417,7 +409,7 @@ The SDK defines custom exception classes for different error scenarios:
417
409
  ```ruby
418
410
  begin
419
411
  engine = LingoDotDev::Engine.new(api_key: 'your-api-key')
420
- result = engine.localize_text('Hello', target_locale: 'es')
412
+ result = engine.localize_text('Hello', target_locale: 'es', source_locale: 'en')
421
413
  rescue LingoDotDev::ValidationError => e
422
414
  # Invalid input or configuration
423
415
  puts "Validation error: #{e.message}"
@@ -3,6 +3,6 @@
3
3
  # Ruby SDK for Lingo.dev localization and translation API.
4
4
  module LingoDotDev
5
5
  # Current version of the LingoDotDev SDK.
6
- VERSION = "0.1.0"
6
+ VERSION = "0.2.1"
7
7
  end
8
8