Skip to content

Commit 9a3bc06

Browse files
committed
feat: make engine_id optional, use /process/localize endpoint
1 parent 2a3abab commit 9a3bc06

File tree

4 files changed

+47
-67
lines changed

4 files changed

+47
-67
lines changed

README.md

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ result = engine.localize_text(
6161
source_locale: 'en'
6262
)
6363
# => "Hola mundo"
64-
65-
# Fast mode for quicker results
66-
result = engine.localize_text(
67-
'Hello world',
68-
target_locale: 'de',
69-
source_locale: 'en',
70-
fast: true
71-
)
72-
# => "Hallo Welt"
7364
```
7465

7566
### Object localization
@@ -285,7 +276,7 @@ The SDK can be configured when creating an engine instance:
285276
```ruby
286277
engine = LingoDotDev::Engine.new(
287278
api_key: 'your-api-key', # Required: Your Lingo.dev API key
288-
engine_id: 'your-engine-id', # Required: Your engine ID
279+
engine_id: 'your-engine-id', # Optional: Your engine ID
289280
api_url: 'https://api.lingo.dev', # Optional: API endpoint URL
290281
batch_size: 25, # Optional: Max items per batch (1-250)
291282
ideal_batch_item_size: 250 # Optional: Target word count per batch (1-2500)
@@ -306,7 +297,7 @@ end
306297
| Option | Type | Default | Description |
307298
| ----------------------- | ------- | -------------------------- | ----------------------------------------- |
308299
| `api_key` | String | Required | Your Lingo.dev API key |
309-
| `engine_id` | String | Required | Your engine ID for localization processing|
300+
| `engine_id` | String | `nil` | Your engine ID for localization processing|
310301
| `api_url` | String | `https://api.lingo.dev` | API endpoint URL |
311302
| `batch_size` | Integer | `25` | Maximum items per batch (1-250) |
312303
| `ideal_batch_item_size` | Integer | `250` | Target word count per batch item (1-2500) |
@@ -315,51 +306,49 @@ end
315306

316307
### Instance methods
317308

318-
#### `localize_text(text, target_locale:, source_locale:, 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)`
319310

320311
Localizes a string to the target locale.
321312

322313
- **Parameters:**
323314
- `text` (String): Text to localize
324315
- `target_locale` (String): Target locale code (e.g., 'es', 'fr', 'ja')
325316
- `source_locale` (String): Source locale code (e.g., 'en')
326-
- `fast` (Boolean, optional): Enable fast mode
327317
- `reference` (Hash, optional): Additional context for translation
328318
- `on_progress` (Proc, optional): Progress callback
329319
- `concurrent` (Boolean): Enable concurrent processing
330320
- `&block`: Alternative progress callback
331321
- **Returns:** Localized string
332322

333-
#### `localize_object(obj, target_locale:, source_locale:, 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)`
334324

335325
Localizes all string values in a Hash.
336326

337327
- **Parameters:** Same as `localize_text`, with `obj` (Hash) instead of `text`
338328
- **Returns:** Localized Hash
339329

340-
#### `localize_chat(chat, target_locale:, source_locale:, 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)`
341331

342332
Localizes chat messages. Each message must have `:name` and `:text` keys.
343333

344334
- **Parameters:** Same as `localize_text`, with `chat` (Array) instead of `text`
345335
- **Returns:** Array of localized chat messages
346336

347-
#### `localize_html(html, target_locale:, source_locale:, 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)`
348338

349339
Localizes an HTML document while preserving structure and formatting. Handles both text content and localizable attributes (alt, title, placeholder, meta content).
350340

351341
- **Parameters:**
352342
- `html` (String): HTML document string to localize
353343
- `target_locale` (String): Target locale code (e.g., 'es', 'fr', 'ja')
354344
- `source_locale` (String): Source locale code (e.g., 'en')
355-
- `fast` (Boolean, optional): Enable fast mode
356345
- `reference` (Hash, optional): Additional context for translation
357346
- `on_progress` (Proc, optional): Progress callback
358347
- `concurrent` (Boolean): Enable concurrent processing
359348
- `&block`: Alternative progress callback
360349
- **Returns:** Localized HTML document string with updated `lang` attribute
361350

362-
#### `batch_localize_text(text, target_locales:, source_locale:, fast: nil, reference: nil, concurrent: false)`
351+
#### `batch_localize_text(text, target_locales:, source_locale:, reference: nil, concurrent: false)`
363352

364353
Localizes text to multiple target locales.
365354

@@ -369,7 +358,7 @@ Localizes text to multiple target locales.
369358
- Other parameters same as `localize_text`
370359
- **Returns:** Array of localized strings
371360

372-
#### `batch_localize_objects(objects, target_locale:, source_locale:, fast: nil, reference: nil, concurrent: false)`
361+
#### `batch_localize_objects(objects, target_locale:, source_locale:, reference: nil, concurrent: false)`
373362

374363
Localizes multiple objects to the same target locale.
375364

@@ -395,7 +384,7 @@ Returns information about the authenticated user.
395384

396385
### Class methods
397386

398-
#### `Engine.quick_translate(content, api_key:, engine_id:, target_locale:, source_locale:, fast: true, api_url: 'https://api.lingo.dev')`
387+
#### `Engine.quick_translate(content, api_key:, engine_id: nil, target_locale:, source_locale:, api_url: 'https://api.lingo.dev')`
399388

400389
One-off translation without managing engine lifecycle.
401390

@@ -404,7 +393,7 @@ One-off translation without managing engine lifecycle.
404393
- Other parameters as in instance methods
405394
- **Returns:** Translated String or Hash
406395

407-
#### `Engine.quick_batch_translate(content, api_key:, engine_id:, target_locales:, source_locale:, fast: true, api_url: 'https://api.lingo.dev')`
396+
#### `Engine.quick_batch_translate(content, api_key:, engine_id: nil, target_locales:, source_locale:, api_url: 'https://api.lingo.dev')`
408397

409398
One-off batch translation to multiple locales.
410399

@@ -420,7 +409,7 @@ The SDK defines custom exception classes for different error scenarios:
420409

421410
```ruby
422411
begin
423-
engine = LingoDotDev::Engine.new(api_key: 'your-api-key', engine_id: 'your-engine-id')
412+
engine = LingoDotDev::Engine.new(api_key: 'your-api-key')
424413
result = engine.localize_text('Hello', target_locale: 'es', source_locale: 'en')
425414
rescue LingoDotDev::ValidationError => e
426415
# Invalid input or configuration

lib/lingodotdev.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
# localization with batch operations, progress tracking, and concurrent processing.
5555
#
5656
# @example Basic usage
57-
# engine = LingoDotDev::Engine.new(api_key: 'your-api-key', engine_id: 'your-engine-id')
57+
# engine = LingoDotDev::Engine.new(api_key: 'your-api-key')
5858
# result = engine.localize_text('Hello world', target_locale: 'es', source_locale: 'en')
5959
# puts result # => "Hola mundo"
6060
#
@@ -88,7 +88,7 @@ class Configuration
8888
# @return [String] the API endpoint URL
8989
attr_accessor :api_url
9090

91-
# @return [String] the engine ID for localization processing
91+
# @return [String, nil] the engine ID for localization processing
9292
attr_accessor :engine_id
9393

9494
# @return [Integer] maximum number of items per batch (1-250)
@@ -100,13 +100,13 @@ class Configuration
100100
# Creates a new Configuration instance.
101101
#
102102
# @param api_key [String] your Lingo.dev API key (required)
103-
# @param engine_id [String] the engine ID for localization processing (required)
103+
# @param engine_id [String, nil] the engine ID for localization processing (optional)
104104
# @param api_url [String] the API endpoint URL (default: 'https://api.lingo.dev')
105105
# @param batch_size [Integer] maximum items per batch, 1-250 (default: 25)
106106
# @param ideal_batch_item_size [Integer] target word count per batch item, 1-2500 (default: 250)
107107
#
108108
# @raise [ValidationError] if any parameter is invalid
109-
def initialize(api_key:, engine_id:, api_url: 'https://api.lingo.dev', batch_size: 25, ideal_batch_item_size: 250)
109+
def initialize(api_key:, engine_id: nil, api_url: 'https://api.lingo.dev', batch_size: 25, ideal_batch_item_size: 250)
110110
@api_key = api_key
111111
@engine_id = engine_id
112112
@api_url = api_url
@@ -119,7 +119,6 @@ def initialize(api_key:, engine_id:, api_url: 'https://api.lingo.dev', batch_siz
119119

120120
def validate!
121121
raise ValidationError, 'API key is required' if api_key.nil? || api_key.empty?
122-
raise ValidationError, 'Engine ID is required' if engine_id.nil? || engine_id.empty?
123122
raise ValidationError, 'API URL must be a valid HTTP/HTTPS URL' unless api_url =~ /\Ahttps?:\/\/.+/
124123
raise ValidationError, 'Batch size must be between 1 and 250' unless batch_size.is_a?(Integer) && batch_size.between?(1, 250)
125124
raise ValidationError, 'Ideal batch item size must be between 1 and 2500' unless ideal_batch_item_size.is_a?(Integer) && ideal_batch_item_size.between?(1, 2500)
@@ -151,7 +150,7 @@ class Engine
151150
# Creates a new Engine instance.
152151
#
153152
# @param api_key [String] your Lingo.dev API key (required)
154-
# @param engine_id [String] the engine ID for localization processing (required)
153+
# @param engine_id [String, nil] the engine ID for localization processing (optional)
155154
# @param api_url [String] the API endpoint URL (default: 'https://api.lingo.dev')
156155
# @param batch_size [Integer] maximum items per batch, 1-250 (default: 25)
157156
# @param ideal_batch_item_size [Integer] target word count per batch item, 1-2500 (default: 250)
@@ -172,7 +171,7 @@ class Engine
172171
# config.batch_size = 50
173172
# config.ideal_batch_item_size = 500
174173
# end
175-
def initialize(api_key:, engine_id:, api_url: 'https://api.lingo.dev', batch_size: 25, ideal_batch_item_size: 250)
174+
def initialize(api_key:, engine_id: nil, api_url: 'https://api.lingo.dev', batch_size: 25, ideal_batch_item_size: 250)
176175
@config = Configuration.new(
177176
api_key: api_key,
178177
engine_id: engine_id,
@@ -685,7 +684,7 @@ def whoami
685684
#
686685
# @param content [String, Hash] the content to translate (String for text, Hash for object)
687686
# @param api_key [String] your Lingo.dev API key
688-
# @param engine_id [String] the engine ID for localization processing
687+
# @param engine_id [String, nil] the engine ID for localization processing (optional)
689688
# @param target_locale [String] the target locale code (e.g., 'es', 'fr', 'ja')
690689
# @param source_locale [String] the source locale code (e.g., 'en')
691690
# @param fast [Boolean] enable fast mode for quicker results (default: true)
@@ -709,7 +708,7 @@ def whoami
709708
# source_locale: 'en'
710709
# )
711710
# # => { greeting: "Bonjour", farewell: "Au revoir" }
712-
def self.quick_translate(content, api_key:, engine_id:, target_locale:, source_locale:, fast: true, api_url: 'https://api.lingo.dev')
711+
def self.quick_translate(content, api_key:, engine_id: nil, target_locale:, source_locale:, fast: true, api_url: 'https://api.lingo.dev')
713712
engine = new(api_key: api_key, engine_id: engine_id, api_url: api_url)
714713
case content
715714
when String
@@ -739,7 +738,7 @@ def self.quick_translate(content, api_key:, engine_id:, target_locale:, source_l
739738
#
740739
# @param content [String, Hash] the content to translate (String for text, Hash for object)
741740
# @param api_key [String] your Lingo.dev API key
742-
# @param engine_id [String] the engine ID for localization processing
741+
# @param engine_id [String, nil] the engine ID for localization processing (optional)
743742
# @param target_locales [Array<String>] array of target locale codes
744743
# @param source_locale [String] the source locale code (e.g., 'en')
745744
# @param fast [Boolean] enable fast mode for quicker results (default: true)
@@ -764,12 +763,11 @@ def self.quick_translate(content, api_key:, engine_id:, target_locale:, source_l
764763
# results = LingoDotDev::Engine.quick_batch_translate(
765764
# { greeting: 'Hello' },
766765
# api_key: 'your-api-key',
767-
# engine_id: 'your-engine-id',
768766
# target_locales: ['es', 'fr'],
769767
# source_locale: 'en'
770768
# )
771769
# # => [{ greeting: "Hola" }, { greeting: "Bonjour" }]
772-
def self.quick_batch_translate(content, api_key:, engine_id:, target_locales:, source_locale:, fast: true, api_url: 'https://api.lingo.dev')
770+
def self.quick_batch_translate(content, api_key:, engine_id: nil, target_locales:, source_locale:, fast: true, api_url: 'https://api.lingo.dev')
773771
engine = new(api_key: api_key, engine_id: engine_id, api_url: api_url)
774772
case content
775773
when String
@@ -865,6 +863,8 @@ def localize_chunk(chunk, target_locale:, source_locale:, fast:, reference:)
865863
sessionId: @session_id
866864
}
867865

866+
request_body[:engineId] = config.engine_id unless config.engine_id.nil?
867+
868868
if reference && !reference.empty?
869869
raise ValidationError, 'Reference must be a Hash' unless reference.is_a?(Hash)
870870
request_body[:reference] = reference
@@ -874,7 +874,7 @@ def localize_chunk(chunk, target_locale:, source_locale:, fast:, reference:)
874874

875875
begin
876876
response = make_request(
877-
"#{config.api_url}/process/#{config.engine_id}/localize",
877+
"#{config.api_url}/process/localize",
878878
json: request_body
879879
)
880880

0 commit comments

Comments
 (0)