@@ -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,29 +53,14 @@ 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"
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"
7964```
8065
8166### Object localization
@@ -89,7 +74,7 @@ data = {
8974 message: ' Welcome to our app'
9075}
9176
92- result = engine.localize_object(data, target_locale: ' es' )
77+ result = engine.localize_object(data, target_locale: ' es' , source_locale: ' en ' )
9378# => {
9479# greeting: "Hola",
9580# farewell: "Adiós",
@@ -108,7 +93,7 @@ chat = [
10893 { name: ' user' , text: ' I need some information.' }
10994]
11095
111- result = engine.localize_chat(chat, target_locale: ' ja' )
96+ result = engine.localize_chat(chat, target_locale: ' ja' , source_locale: ' en ' )
11297# => [
11398# { name: 'user', text: 'こんにちは!' },
11499# { name: 'assistant', text: 'こんにちは!どのようにお手伝いできますか?' },
@@ -136,7 +121,7 @@ html = <<~HTML
136121 </html >
137122HTML
138123
139- result = engine.localize_html(html, target_locale: ' es' )
124+ result = engine.localize_html(html, target_locale: ' es' , source_locale: ' en ' )
140125# => HTML with localized text content and attributes, lang="es" attribute updated
141126```
142127
@@ -156,14 +141,16 @@ Localize the same content to multiple target locales:
156141# Batch localize text
157142results = engine.batch_localize_text(
158143 ' Hello world' ,
159- target_locales: [' es' , ' fr' , ' de' ]
144+ target_locales: [' es' , ' fr' , ' de' ],
145+ source_locale: ' en'
160146)
161147# => ["Hola mundo", "Bonjour le monde", "Hallo Welt"]
162148
163149# With concurrent processing for better performance
164150results = engine.batch_localize_text(
165151 ' Hello world' ,
166152 target_locales: [' es' , ' fr' , ' de' , ' ja' ],
153+ source_locale: ' en' ,
167154 concurrent: true
168155)
169156```
@@ -182,6 +169,7 @@ objects = [
182169results = engine.batch_localize_objects(
183170 objects,
184171 target_locale: ' es' ,
172+ source_locale: ' en' ,
185173 concurrent: true
186174)
187175# => [
@@ -198,9 +186,6 @@ Automatically detect the locale of a given text:
198186``` ruby
199187locale = engine.recognize_locale(' Bonjour le monde' )
200188# => "fr"
201-
202- locale = engine.recognize_locale(' こんにちは世界' )
203- # => "ja"
204189```
205190
206191### Progress tracking
@@ -209,7 +194,7 @@ Monitor localization progress with callbacks:
209194
210195``` ruby
211196# 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 |
213198 puts " Progress: #{ progress } %"
214199end
215200
@@ -218,6 +203,7 @@ callback = proc { |progress| puts "Progress: #{progress}%" }
218203result = engine.localize_text(
219204 ' Hello world' ,
220205 target_locale: ' es' ,
206+ source_locale: ' en' ,
221207 on_progress: callback
222208)
223209```
@@ -236,6 +222,7 @@ reference = {
236222result = engine.localize_text(
237223 ' Hello' ,
238224 target_locale: ' ja' ,
225+ source_locale: ' en' ,
239226 reference: reference
240227)
241228```
@@ -249,21 +236,27 @@ For one-off translations without managing engine instances:
249236result = LingoDotDev ::Engine .quick_translate(
250237 ' Hello world' ,
251238 api_key: ' your-api-key' ,
252- target_locale: ' es'
239+ engine_id: ' your-engine-id' ,
240+ target_locale: ' es' ,
241+ source_locale: ' en'
253242)
254243
255244# Quick translate a hash
256245result = LingoDotDev ::Engine .quick_translate(
257246 { greeting: ' Hello' , farewell: ' Goodbye' },
258247 api_key: ' your-api-key' ,
259- target_locale: ' fr'
248+ engine_id: ' your-engine-id' ,
249+ target_locale: ' fr' ,
250+ source_locale: ' en'
260251)
261252
262253# Quick batch translate to multiple locales
263254results = LingoDotDev ::Engine .quick_batch_translate(
264255 ' Hello' ,
265256 api_key: ' your-api-key' ,
266- target_locales: [' es' , ' fr' , ' de' ]
257+ engine_id: ' your-engine-id' ,
258+ target_locales: [' es' , ' fr' , ' de' ],
259+ source_locale: ' en'
267260)
268261```
269262
@@ -283,7 +276,8 @@ The SDK can be configured when creating an engine instance:
283276``` ruby
284277engine = LingoDotDev ::Engine .new (
285278 api_key: ' your-api-key' , # Required: Your Lingo.dev API key
286- api_url: ' https://engine.lingo.dev' , # Optional: API endpoint URL
279+ engine_id: ' your-engine-id' , # Optional: Your engine ID
280+ api_url: ' https://api.lingo.dev' , # Optional: API endpoint URL
287281 batch_size: 25 , # Optional: Max items per batch (1-250)
288282 ideal_batch_item_size: 250 # Optional: Target word count per batch (1-2500)
289283)
@@ -292,7 +286,7 @@ engine = LingoDotDev::Engine.new(
292286You can also configure using a block:
293287
294288``` 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 |
296290 config.batch_size = 50
297291 config.ideal_batch_item_size = 500
298292end
@@ -303,59 +297,58 @@ end
303297| Option | Type | Default | Description |
304298| ----------------------- | ------- | -------------------------- | ----------------------------------------- |
305299| ` api_key ` | String | Required | Your Lingo.dev API key |
306- | ` api_url ` | String | ` https://engine.lingo.dev ` | API endpoint URL |
300+ | ` engine_id ` | String | ` nil ` | Your engine ID for localization processing|
301+ | ` api_url ` | String | ` https://api.lingo.dev ` | API endpoint URL |
307302| ` batch_size ` | Integer | ` 25 ` | Maximum items per batch (1-250) |
308303| ` ideal_batch_item_size ` | Integer | ` 250 ` | Target word count per batch item (1-2500) |
309304
310305## API reference
311306
312307### Instance methods
313308
314- #### ` localize_text(text, target_locale:, source_locale: nil, fast: nil , reference: nil, on_progress: nil, concurrent: false, &block) `
309+ #### ` localize_text(text, target_locale:, source_locale:, reference: nil, on_progress: nil, concurrent: false, &block) `
315310
316311Localizes a string to the target locale.
317312
318313- ** Parameters:**
319314 - ` text ` (String): Text to localize
320315 - ` 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
316+ - ` source_locale ` (String): Source locale code (e.g., 'en')
323317 - ` reference ` (Hash, optional): Additional context for translation
324318 - ` on_progress ` (Proc, optional): Progress callback
325319 - ` concurrent ` (Boolean): Enable concurrent processing
326320 - ` &block ` : Alternative progress callback
327321- ** Returns:** Localized string
328322
329- #### ` localize_object(obj, target_locale:, source_locale: nil, fast: nil , reference: nil, on_progress: nil, concurrent: false, &block) `
323+ #### ` localize_object(obj, target_locale:, source_locale:, reference: nil, on_progress: nil, concurrent: false, &block) `
330324
331325Localizes all string values in a Hash.
332326
333327- ** Parameters:** Same as ` localize_text ` , with ` obj ` (Hash) instead of ` text `
334328- ** Returns:** Localized Hash
335329
336- #### ` localize_chat(chat, target_locale:, source_locale: nil, fast: nil , reference: nil, on_progress: nil, concurrent: false, &block) `
330+ #### ` localize_chat(chat, target_locale:, source_locale:, reference: nil, on_progress: nil, concurrent: false, &block) `
337331
338332Localizes chat messages. Each message must have ` :name ` and ` :text ` keys.
339333
340334- ** Parameters:** Same as ` localize_text ` , with ` chat ` (Array) instead of ` text `
341335- ** Returns:** Array of localized chat messages
342336
343- #### ` localize_html(html, target_locale:, source_locale: nil, fast: nil , reference: nil, on_progress: nil, concurrent: false, &block) `
337+ #### ` localize_html(html, target_locale:, source_locale:, reference: nil, on_progress: nil, concurrent: false, &block) `
344338
345339Localizes an HTML document while preserving structure and formatting. Handles both text content and localizable attributes (alt, title, placeholder, meta content).
346340
347341- ** Parameters:**
348342 - ` html ` (String): HTML document string to localize
349343 - ` 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
344+ - ` source_locale ` (String): Source locale code (e.g., 'en')
352345 - ` reference ` (Hash, optional): Additional context for translation
353346 - ` on_progress ` (Proc, optional): Progress callback
354347 - ` concurrent ` (Boolean): Enable concurrent processing
355348 - ` &block ` : Alternative progress callback
356349- ** Returns:** Localized HTML document string with updated ` lang ` attribute
357350
358- #### ` batch_localize_text(text, target_locales:, source_locale: nil, fast: nil , reference: nil, concurrent: false) `
351+ #### ` batch_localize_text(text, target_locales:, source_locale:, reference: nil, concurrent: false) `
359352
360353Localizes text to multiple target locales.
361354
@@ -365,7 +358,7 @@ Localizes text to multiple target locales.
365358 - Other parameters same as ` localize_text `
366359- ** Returns:** Array of localized strings
367360
368- #### ` batch_localize_objects(objects, target_locale:, source_locale: nil, fast: nil , reference: nil, concurrent: false) `
361+ #### ` batch_localize_objects(objects, target_locale:, source_locale:, reference: nil, concurrent: false) `
369362
370363Localizes multiple objects to the same target locale.
371364
@@ -391,7 +384,7 @@ Returns information about the authenticated user.
391384
392385### Class methods
393386
394- #### ` Engine.quick_translate(content, api_key:, target_locale:, source_locale: nil, fast: true , api_url: 'https://engine .lingo.dev') `
387+ #### ` Engine.quick_translate(content, api_key:, engine_id: nil, target_locale:, source_locale: , api_url: 'https://api .lingo.dev') `
395388
396389One-off translation without managing engine lifecycle.
397390
@@ -400,7 +393,7 @@ One-off translation without managing engine lifecycle.
400393 - Other parameters as in instance methods
401394- ** Returns:** Translated String or Hash
402395
403- #### ` Engine.quick_batch_translate(content, api_key:, target_locales:, source_locale: nil, fast: true , api_url: 'https://engine .lingo.dev') `
396+ #### ` Engine.quick_batch_translate(content, api_key:, engine_id: nil, target_locales:, source_locale: , api_url: 'https://api .lingo.dev') `
404397
405398One-off batch translation to multiple locales.
406399
@@ -417,7 +410,7 @@ The SDK defines custom exception classes for different error scenarios:
417410``` ruby
418411begin
419412 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 ' )
421414rescue LingoDotDev ::ValidationError => e
422415 # Invalid input or configuration
423416 puts " Validation error: #{ e.message } "
0 commit comments