@@ -39,10 +39,10 @@ gem install lingodotdev
3939require ' lingodotdev'
4040
4141# 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 ' )
4343
4444# 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 ' )
4646puts result # => "Hola mundo"
4747```
4848
@@ -53,26 +53,20 @@ puts result # => "Hola mundo"
5353Localize a simple string to a target locale:
5454
5555``` 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 ' )
5757
5858result = engine.localize_text(
5959 ' 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' ,
6861 source_locale: ' en'
6962)
70- # => "Bonjour le monde "
63+ # => "Hola mundo "
7164
7265# Fast mode for quicker results
7366result = engine.localize_text(
7467 ' Hello world' ,
7568 target_locale: ' de' ,
69+ source_locale: ' en' ,
7670 fast: true
7771)
7872# => "Hallo Welt"
@@ -89,7 +83,7 @@ data = {
8983 message: ' Welcome to our app'
9084}
9185
92- result = engine.localize_object(data, target_locale: ' es' )
86+ result = engine.localize_object(data, target_locale: ' es' , source_locale: ' en ' )
9387# => {
9488# greeting: "Hola",
9589# farewell: "Adiós",
@@ -108,7 +102,7 @@ chat = [
108102 { name: ' user' , text: ' I need some information.' }
109103]
110104
111- result = engine.localize_chat(chat, target_locale: ' ja' )
105+ result = engine.localize_chat(chat, target_locale: ' ja' , source_locale: ' en ' )
112106# => [
113107# { name: 'user', text: 'こんにちは!' },
114108# { name: 'assistant', text: 'こんにちは!どのようにお手伝いできますか?' },
@@ -136,7 +130,7 @@ html = <<~HTML
136130 </html >
137131HTML
138132
139- result = engine.localize_html(html, target_locale: ' es' )
133+ result = engine.localize_html(html, target_locale: ' es' , source_locale: ' en ' )
140134# => HTML with localized text content and attributes, lang="es" attribute updated
141135```
142136
@@ -156,14 +150,16 @@ Localize the same content to multiple target locales:
156150# Batch localize text
157151results = engine.batch_localize_text(
158152 ' Hello world' ,
159- target_locales: [' es' , ' fr' , ' de' ]
153+ target_locales: [' es' , ' fr' , ' de' ],
154+ source_locale: ' en'
160155)
161156# => ["Hola mundo", "Bonjour le monde", "Hallo Welt"]
162157
163158# With concurrent processing for better performance
164159results = engine.batch_localize_text(
165160 ' Hello world' ,
166161 target_locales: [' es' , ' fr' , ' de' , ' ja' ],
162+ source_locale: ' en' ,
167163 concurrent: true
168164)
169165```
@@ -182,6 +178,7 @@ objects = [
182178results = engine.batch_localize_objects(
183179 objects,
184180 target_locale: ' es' ,
181+ source_locale: ' en' ,
185182 concurrent: true
186183)
187184# => [
@@ -198,9 +195,6 @@ Automatically detect the locale of a given text:
198195``` ruby
199196locale = engine.recognize_locale(' Bonjour le monde' )
200197# => "fr"
201-
202- locale = engine.recognize_locale(' こんにちは世界' )
203- # => "ja"
204198```
205199
206200### Progress tracking
@@ -209,7 +203,7 @@ Monitor localization progress with callbacks:
209203
210204``` ruby
211205# Using a block
212- result = engine.localize_text(' Hello world' , target_locale: ' es' ) do |progress |
206+ result = engine.localize_text(' Hello world' , target_locale: ' es' , source_locale: ' en ' ) do |progress |
213207 puts " Progress: #{ progress } %"
214208end
215209
@@ -218,6 +212,7 @@ callback = proc { |progress| puts "Progress: #{progress}%" }
218212result = engine.localize_text(
219213 ' Hello world' ,
220214 target_locale: ' es' ,
215+ source_locale: ' en' ,
221216 on_progress: callback
222217)
223218```
@@ -236,6 +231,7 @@ reference = {
236231result = engine.localize_text(
237232 ' Hello' ,
238233 target_locale: ' ja' ,
234+ source_locale: ' en' ,
239235 reference: reference
240236)
241237```
@@ -249,21 +245,27 @@ For one-off translations without managing engine instances:
249245result = LingoDotDev ::Engine .quick_translate(
250246 ' Hello world' ,
251247 api_key: ' your-api-key' ,
252- target_locale: ' es'
248+ engine_id: ' your-engine-id' ,
249+ target_locale: ' es' ,
250+ source_locale: ' en'
253251)
254252
255253# Quick translate a hash
256254result = LingoDotDev ::Engine .quick_translate(
257255 { greeting: ' Hello' , farewell: ' Goodbye' },
258256 api_key: ' your-api-key' ,
259- target_locale: ' fr'
257+ engine_id: ' your-engine-id' ,
258+ target_locale: ' fr' ,
259+ source_locale: ' en'
260260)
261261
262262# Quick batch translate to multiple locales
263263results = LingoDotDev ::Engine .quick_batch_translate(
264264 ' Hello' ,
265265 api_key: ' your-api-key' ,
266- target_locales: [' es' , ' fr' , ' de' ]
266+ engine_id: ' your-engine-id' ,
267+ target_locales: [' es' , ' fr' , ' de' ],
268+ source_locale: ' en'
267269)
268270```
269271
@@ -283,7 +285,8 @@ The SDK can be configured when creating an engine instance:
283285``` ruby
284286engine = LingoDotDev ::Engine .new (
285287 api_key: ' your-api-key' , # Required: Your Lingo.dev API key
286- api_url: ' https://engine.lingo.dev' , # Optional: API endpoint URL
288+ engine_id: ' your-engine-id' , # Required: Your engine ID
289+ api_url: ' https://api.lingo.dev' , # Optional: API endpoint URL
287290 batch_size: 25 , # Optional: Max items per batch (1-250)
288291 ideal_batch_item_size: 250 # Optional: Target word count per batch (1-2500)
289292)
@@ -292,7 +295,7 @@ engine = LingoDotDev::Engine.new(
292295You can also configure using a block:
293296
294297``` ruby
295- engine = LingoDotDev ::Engine .new (api_key: ' your-api-key' ) do |config |
298+ engine = LingoDotDev ::Engine .new (api_key: ' your-api-key' , engine_id: ' your-engine-id ' ) do |config |
296299 config.batch_size = 50
297300 config.ideal_batch_item_size = 500
298301end
@@ -303,59 +306,60 @@ end
303306| Option | Type | Default | Description |
304307| ----------------------- | ------- | -------------------------- | ----------------------------------------- |
305308| ` api_key ` | String | Required | Your Lingo.dev API key |
306- | ` api_url ` | String | ` https://engine.lingo.dev ` | API endpoint URL |
309+ | ` engine_id ` | String | Required | Your engine ID for localization processing|
310+ | ` api_url ` | String | ` https://api.lingo.dev ` | API endpoint URL |
307311| ` batch_size ` | Integer | ` 25 ` | Maximum items per batch (1-250) |
308312| ` ideal_batch_item_size ` | Integer | ` 250 ` | Target word count per batch item (1-2500) |
309313
310314## API reference
311315
312316### Instance methods
313317
314- #### ` localize_text(text, target_locale:, source_locale: nil , fast: nil, reference: nil, on_progress: nil, concurrent: false, &block) `
318+ #### ` localize_text(text, target_locale:, source_locale:, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block) `
315319
316320Localizes a string to the target locale.
317321
318322- ** Parameters:**
319323 - ` text ` (String): Text to localize
320324 - ` target_locale ` (String): Target locale code (e.g., 'es', 'fr', 'ja')
321- - ` source_locale ` (String, optional ): Source locale code
325+ - ` source_locale ` (String): Source locale code (e.g., 'en')
322326 - ` fast ` (Boolean, optional): Enable fast mode
323327 - ` reference ` (Hash, optional): Additional context for translation
324328 - ` on_progress ` (Proc, optional): Progress callback
325329 - ` concurrent ` (Boolean): Enable concurrent processing
326330 - ` &block ` : Alternative progress callback
327331- ** Returns:** Localized string
328332
329- #### ` localize_object(obj, target_locale:, source_locale: nil , fast: nil, reference: nil, on_progress: nil, concurrent: false, &block) `
333+ #### ` localize_object(obj, target_locale:, source_locale:, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block) `
330334
331335Localizes all string values in a Hash.
332336
333337- ** Parameters:** Same as ` localize_text ` , with ` obj ` (Hash) instead of ` text `
334338- ** Returns:** Localized Hash
335339
336- #### ` localize_chat(chat, target_locale:, source_locale: nil , fast: nil, reference: nil, on_progress: nil, concurrent: false, &block) `
340+ #### ` localize_chat(chat, target_locale:, source_locale:, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block) `
337341
338342Localizes chat messages. Each message must have ` :name ` and ` :text ` keys.
339343
340344- ** Parameters:** Same as ` localize_text ` , with ` chat ` (Array) instead of ` text `
341345- ** Returns:** Array of localized chat messages
342346
343- #### ` localize_html(html, target_locale:, source_locale: nil , fast: nil, reference: nil, on_progress: nil, concurrent: false, &block) `
347+ #### ` localize_html(html, target_locale:, source_locale:, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block) `
344348
345349Localizes an HTML document while preserving structure and formatting. Handles both text content and localizable attributes (alt, title, placeholder, meta content).
346350
347351- ** Parameters:**
348352 - ` html ` (String): HTML document string to localize
349353 - ` target_locale ` (String): Target locale code (e.g., 'es', 'fr', 'ja')
350- - ` source_locale ` (String, optional ): Source locale code
354+ - ` source_locale ` (String): Source locale code (e.g., 'en')
351355 - ` fast ` (Boolean, optional): Enable fast mode
352356 - ` reference ` (Hash, optional): Additional context for translation
353357 - ` on_progress ` (Proc, optional): Progress callback
354358 - ` concurrent ` (Boolean): Enable concurrent processing
355359 - ` &block ` : Alternative progress callback
356360- ** Returns:** Localized HTML document string with updated ` lang ` attribute
357361
358- #### ` batch_localize_text(text, target_locales:, source_locale: nil , fast: nil, reference: nil, concurrent: false) `
362+ #### ` batch_localize_text(text, target_locales:, source_locale:, fast: nil, reference: nil, concurrent: false) `
359363
360364Localizes text to multiple target locales.
361365
@@ -365,7 +369,7 @@ Localizes text to multiple target locales.
365369 - Other parameters same as ` localize_text `
366370- ** Returns:** Array of localized strings
367371
368- #### ` batch_localize_objects(objects, target_locale:, source_locale: nil , fast: nil, reference: nil, concurrent: false) `
372+ #### ` batch_localize_objects(objects, target_locale:, source_locale:, fast: nil, reference: nil, concurrent: false) `
369373
370374Localizes multiple objects to the same target locale.
371375
@@ -391,7 +395,7 @@ Returns information about the authenticated user.
391395
392396### Class methods
393397
394- #### ` Engine.quick_translate(content, api_key:, target_locale:, source_locale: nil , fast: true, api_url: 'https://engine .lingo.dev') `
398+ #### ` Engine.quick_translate(content, api_key:, engine_id:, target_locale:, source_locale:, fast: true, api_url: 'https://api .lingo.dev') `
395399
396400One-off translation without managing engine lifecycle.
397401
@@ -400,7 +404,7 @@ One-off translation without managing engine lifecycle.
400404 - Other parameters as in instance methods
401405- ** Returns:** Translated String or Hash
402406
403- #### ` Engine.quick_batch_translate(content, api_key:, target_locales:, source_locale: nil , fast: true, api_url: 'https://engine .lingo.dev') `
407+ #### ` Engine.quick_batch_translate(content, api_key:, engine_id:, target_locales:, source_locale:, fast: true, api_url: 'https://api .lingo.dev') `
404408
405409One-off batch translation to multiple locales.
406410
@@ -416,8 +420,8 @@ The SDK defines custom exception classes for different error scenarios:
416420
417421``` ruby
418422begin
419- engine = LingoDotDev ::Engine .new (api_key: ' your-api-key' )
420- result = engine.localize_text(' Hello' , target_locale: ' es' )
423+ engine = LingoDotDev ::Engine .new (api_key: ' your-api-key' , engine_id: ' your-engine-id ' )
424+ result = engine.localize_text(' Hello' , target_locale: ' es' , source_locale: ' en ' )
421425rescue LingoDotDev ::ValidationError => e
422426 # Invalid input or configuration
423427 puts " Validation error: #{ e.message } "
0 commit comments