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.
data/lib/lingodotdev.rb CHANGED
@@ -55,7 +55,7 @@ end
55
55
  #
56
56
  # @example Basic usage
57
57
  # engine = LingoDotDev::Engine.new(api_key: 'your-api-key')
58
- # result = engine.localize_text('Hello world', target_locale: 'es')
58
+ # result = engine.localize_text('Hello world', target_locale: 'es', source_locale: 'en')
59
59
  # puts result # => "Hola mundo"
60
60
  #
61
61
  # @see Engine
@@ -88,6 +88,9 @@ module LingoDotDev
88
88
  # @return [String] the API endpoint URL
89
89
  attr_accessor :api_url
90
90
 
91
+ # @return [String, nil] the engine ID for localization processing
92
+ attr_accessor :engine_id
93
+
91
94
  # @return [Integer] maximum number of items per batch (1-250)
92
95
  attr_accessor :batch_size
93
96
 
@@ -97,13 +100,15 @@ module LingoDotDev
97
100
  # Creates a new Configuration instance.
98
101
  #
99
102
  # @param api_key [String] your Lingo.dev API key (required)
100
- # @param api_url [String] the API endpoint URL (default: 'https://engine.lingo.dev')
103
+ # @param engine_id [String, nil] the engine ID for localization processing (optional)
104
+ # @param api_url [String] the API endpoint URL (default: 'https://api.lingo.dev')
101
105
  # @param batch_size [Integer] maximum items per batch, 1-250 (default: 25)
102
106
  # @param ideal_batch_item_size [Integer] target word count per batch item, 1-2500 (default: 250)
103
107
  #
104
108
  # @raise [ValidationError] if any parameter is invalid
105
- def initialize(api_key:, api_url: 'https://engine.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)
106
110
  @api_key = api_key
111
+ @engine_id = engine_id
107
112
  @api_url = api_url
108
113
  @batch_size = batch_size
109
114
  @ideal_batch_item_size = ideal_batch_item_size
@@ -126,17 +131,17 @@ module LingoDotDev
126
131
  # with support for batch operations, progress tracking, and concurrent processing.
127
132
  #
128
133
  # @example Basic text localization
129
- # engine = LingoDotDev::Engine.new(api_key: 'your-api-key')
130
- # result = engine.localize_text('Hello', target_locale: 'es')
134
+ # engine = LingoDotDev::Engine.new(api_key: 'your-api-key', engine_id: 'your-engine-id')
135
+ # result = engine.localize_text('Hello', target_locale: 'es', source_locale: 'en')
131
136
  # # => "Hola"
132
137
  #
133
138
  # @example Object localization
134
139
  # data = { greeting: 'Hello', farewell: 'Goodbye' }
135
- # result = engine.localize_object(data, target_locale: 'fr')
140
+ # result = engine.localize_object(data, target_locale: 'fr', source_locale: 'en')
136
141
  # # => { greeting: "Bonjour", farewell: "Au revoir" }
137
142
  #
138
143
  # @example Batch localization
139
- # results = engine.batch_localize_text('Hello', target_locales: ['es', 'fr', 'de'])
144
+ # results = engine.batch_localize_text('Hello', target_locales: ['es', 'fr', 'de'], source_locale: 'en')
140
145
  # # => ["Hola", "Bonjour", "Hallo"]
141
146
  class Engine
142
147
  # @return [Configuration] the engine's configuration
@@ -145,7 +150,8 @@ module LingoDotDev
145
150
  # Creates a new Engine instance.
146
151
  #
147
152
  # @param api_key [String] your Lingo.dev API key (required)
148
- # @param api_url [String] the API endpoint URL (default: 'https://engine.lingo.dev')
153
+ # @param engine_id [String, nil] the engine ID for localization processing (optional)
154
+ # @param api_url [String] the API endpoint URL (default: 'https://api.lingo.dev')
149
155
  # @param batch_size [Integer] maximum items per batch, 1-250 (default: 25)
150
156
  # @param ideal_batch_item_size [Integer] target word count per batch item, 1-2500 (default: 250)
151
157
  #
@@ -155,23 +161,25 @@ module LingoDotDev
155
161
  # @raise [ValidationError] if any parameter is invalid
156
162
  #
157
163
  # @example Basic initialization
158
- # engine = LingoDotDev::Engine.new(api_key: 'your-api-key')
164
+ # engine = LingoDotDev::Engine.new(api_key: 'your-api-key', engine_id: 'your-engine-id')
159
165
  #
160
166
  # @example With custom configuration
161
- # engine = LingoDotDev::Engine.new(api_key: 'your-api-key', batch_size: 50)
167
+ # engine = LingoDotDev::Engine.new(api_key: 'your-api-key', engine_id: 'your-engine-id', batch_size: 50)
162
168
  #
163
169
  # @example With block configuration
164
- # engine = LingoDotDev::Engine.new(api_key: 'your-api-key') do |config|
170
+ # engine = LingoDotDev::Engine.new(api_key: 'your-api-key', engine_id: 'your-engine-id') do |config|
165
171
  # config.batch_size = 50
166
172
  # config.ideal_batch_item_size = 500
167
173
  # end
168
- def initialize(api_key:, api_url: 'https://engine.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)
169
175
  @config = Configuration.new(
170
176
  api_key: api_key,
177
+ engine_id: engine_id,
171
178
  api_url: api_url,
172
179
  batch_size: batch_size,
173
180
  ideal_batch_item_size: ideal_batch_item_size
174
181
  )
182
+ @session_id = SecureRandom.hex(16)
175
183
  yield @config if block_given?
176
184
  @config.send(:validate!)
177
185
  end
@@ -180,7 +188,7 @@ module LingoDotDev
180
188
  #
181
189
  # @param text [String] the text to localize
182
190
  # @param target_locale [String] the target locale code (e.g., 'es', 'fr', 'ja')
183
- # @param source_locale [String, nil] the source locale code (optional, auto-detected if not provided)
191
+ # @param source_locale [String] the source locale code (e.g., 'en')
184
192
  # @param fast [Boolean, nil] enable fast mode for quicker results (optional)
185
193
  # @param reference [Hash, nil] additional context for translation (optional)
186
194
  # @param on_progress [Proc, nil] callback for progress updates (optional)
@@ -195,18 +203,14 @@ module LingoDotDev
195
203
  # @raise [APIError] if the API request fails
196
204
  #
197
205
  # @example Basic usage
198
- # result = engine.localize_text('Hello', target_locale: 'es')
206
+ # result = engine.localize_text('Hello', target_locale: 'es', source_locale: 'en')
199
207
  # # => "Hola"
200
208
  #
201
- # @example With source locale
202
- # result = engine.localize_text('Hello', target_locale: 'fr', source_locale: 'en')
203
- # # => "Bonjour"
204
- #
205
209
  # @example With progress tracking
206
- # result = engine.localize_text('Hello', target_locale: 'de') do |progress|
210
+ # result = engine.localize_text('Hello', target_locale: 'de', source_locale: 'en') do |progress|
207
211
  # puts "Progress: #{progress}%"
208
212
  # end
209
- def localize_text(text, target_locale:, source_locale: nil, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)
213
+ def localize_text(text, target_locale:, source_locale:, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)
210
214
  raise ValidationError, 'Target locale is required' if target_locale.nil? || target_locale.empty?
211
215
  raise ValidationError, 'Text cannot be nil' if text.nil?
212
216
 
@@ -231,7 +235,7 @@ module LingoDotDev
231
235
  #
232
236
  # @param obj [Hash] the Hash object to localize
233
237
  # @param target_locale [String] the target locale code (e.g., 'es', 'fr', 'ja')
234
- # @param source_locale [String, nil] the source locale code (optional, auto-detected if not provided)
238
+ # @param source_locale [String] the source locale code (e.g., 'en')
235
239
  # @param fast [Boolean, nil] enable fast mode for quicker results (optional)
236
240
  # @param reference [Hash, nil] additional context for translation (optional)
237
241
  # @param on_progress [Proc, nil] callback for progress updates (optional)
@@ -247,9 +251,9 @@ module LingoDotDev
247
251
  #
248
252
  # @example Basic usage
249
253
  # data = { greeting: 'Hello', farewell: 'Goodbye' }
250
- # result = engine.localize_object(data, target_locale: 'es')
254
+ # result = engine.localize_object(data, target_locale: 'es', source_locale: 'en')
251
255
  # # => { greeting: "Hola", farewell: "Adiós" }
252
- def localize_object(obj, target_locale:, source_locale: nil, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)
256
+ def localize_object(obj, target_locale:, source_locale:, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)
253
257
  raise ValidationError, 'Target locale is required' if target_locale.nil? || target_locale.empty?
254
258
  raise ValidationError, 'Object cannot be nil' if obj.nil?
255
259
  raise ValidationError, 'Object must be a Hash' unless obj.is_a?(Hash)
@@ -277,7 +281,7 @@ module LingoDotDev
277
281
  #
278
282
  # @param chat [Array<Hash>] array of chat messages, each with :name and :text keys
279
283
  # @param target_locale [String] the target locale code (e.g., 'es', 'fr', 'ja')
280
- # @param source_locale [String, nil] the source locale code (optional, auto-detected if not provided)
284
+ # @param source_locale [String] the source locale code (e.g., 'en')
281
285
  # @param fast [Boolean, nil] enable fast mode for quicker results (optional)
282
286
  # @param reference [Hash, nil] additional context for translation (optional)
283
287
  # @param on_progress [Proc, nil] callback for progress updates (optional)
@@ -296,12 +300,12 @@ module LingoDotDev
296
300
  # { name: 'user', text: 'Hello!' },
297
301
  # { name: 'assistant', text: 'Hi there!' }
298
302
  # ]
299
- # result = engine.localize_chat(chat, target_locale: 'ja')
303
+ # result = engine.localize_chat(chat, target_locale: 'ja', source_locale: 'en')
300
304
  # # => [
301
305
  # # { name: 'user', text: 'こんにちは!' },
302
306
  # # { name: 'assistant', text: 'こんにちは!' }
303
307
  # # ]
304
- def localize_chat(chat, target_locale:, source_locale: nil, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)
308
+ def localize_chat(chat, target_locale:, source_locale:, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)
305
309
  raise ValidationError, 'Target locale is required' if target_locale.nil? || target_locale.empty?
306
310
  raise ValidationError, 'Chat cannot be nil' if chat.nil?
307
311
  raise ValidationError, 'Chat must be an Array' unless chat.is_a?(Array)
@@ -335,7 +339,7 @@ module LingoDotDev
335
339
  #
336
340
  # @param html [String] the HTML document string to be localized
337
341
  # @param target_locale [String] the target locale code (e.g., 'es', 'fr', 'ja')
338
- # @param source_locale [String, nil] the source locale code (optional, auto-detected if not provided)
342
+ # @param source_locale [String] the source locale code (e.g., 'en')
339
343
  # @param fast [Boolean, nil] enable fast mode for quicker results (optional)
340
344
  # @param reference [Hash, nil] additional context for translation (optional)
341
345
  # @param on_progress [Proc, nil] callback for progress updates (optional)
@@ -351,9 +355,9 @@ module LingoDotDev
351
355
  #
352
356
  # @example Basic usage
353
357
  # html = '<html><head><title>Hello</title></head><body><p>World</p></body></html>'
354
- # result = engine.localize_html(html, target_locale: 'es')
358
+ # result = engine.localize_html(html, target_locale: 'es', source_locale: 'en')
355
359
  # # => "<html lang=\"es\">..."
356
- def localize_html(html, target_locale:, source_locale: nil, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)
360
+ def localize_html(html, target_locale:, source_locale:, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)
357
361
  raise ValidationError, 'Target locale is required' if target_locale.nil? || target_locale.empty?
358
362
  raise ValidationError, 'HTML cannot be nil' if html.nil?
359
363
 
@@ -508,7 +512,7 @@ module LingoDotDev
508
512
  #
509
513
  # @param text [String] the text to localize
510
514
  # @param target_locales [Array<String>] array of target locale codes
511
- # @param source_locale [String, nil] the source locale code (optional, auto-detected if not provided)
515
+ # @param source_locale [String] the source locale code (e.g., 'en')
512
516
  # @param fast [Boolean, nil] enable fast mode for quicker results (optional)
513
517
  # @param reference [Hash, nil] additional context for translation (optional)
514
518
  # @param concurrent [Boolean] enable concurrent processing (default: false)
@@ -519,12 +523,12 @@ module LingoDotDev
519
523
  # @raise [APIError] if any API request fails
520
524
  #
521
525
  # @example Basic usage
522
- # results = engine.batch_localize_text('Hello', target_locales: ['es', 'fr', 'de'])
526
+ # results = engine.batch_localize_text('Hello', target_locales: ['es', 'fr', 'de'], source_locale: 'en')
523
527
  # # => ["Hola", "Bonjour", "Hallo"]
524
528
  #
525
529
  # @example With concurrent processing
526
- # results = engine.batch_localize_text('Hello', target_locales: ['es', 'fr', 'de', 'ja'], concurrent: true)
527
- def batch_localize_text(text, target_locales:, source_locale: nil, fast: nil, reference: nil, concurrent: false)
530
+ # results = engine.batch_localize_text('Hello', target_locales: ['es', 'fr', 'de', 'ja'], source_locale: 'en', concurrent: true)
531
+ def batch_localize_text(text, target_locales:, source_locale:, fast: nil, reference: nil, concurrent: false)
528
532
  raise ValidationError, 'Text cannot be nil' if text.nil?
529
533
  raise ValidationError, 'Target locales must be an Array' unless target_locales.is_a?(Array)
530
534
  raise ValidationError, 'Target locales cannot be empty' if target_locales.empty?
@@ -559,7 +563,7 @@ module LingoDotDev
559
563
  #
560
564
  # @param objects [Array<Hash>] array of Hash objects to localize
561
565
  # @param target_locale [String] the target locale code (e.g., 'es', 'fr', 'ja')
562
- # @param source_locale [String, nil] the source locale code (optional, auto-detected if not provided)
566
+ # @param source_locale [String] the source locale code (e.g., 'en')
563
567
  # @param fast [Boolean, nil] enable fast mode for quicker results (optional)
564
568
  # @param reference [Hash, nil] additional context for translation (optional)
565
569
  # @param concurrent [Boolean] enable concurrent processing (default: false)
@@ -574,12 +578,12 @@ module LingoDotDev
574
578
  # { title: 'Welcome', body: 'Hello there' },
575
579
  # { title: 'About', body: 'Learn more' }
576
580
  # ]
577
- # results = engine.batch_localize_objects(objects, target_locale: 'es')
581
+ # results = engine.batch_localize_objects(objects, target_locale: 'es', source_locale: 'en')
578
582
  # # => [
579
583
  # # { title: "Bienvenido", body: "Hola" },
580
584
  # # { title: "Acerca de", body: "Aprende más" }
581
585
  # # ]
582
- def batch_localize_objects(objects, target_locale:, source_locale: nil, fast: nil, reference: nil, concurrent: false)
586
+ def batch_localize_objects(objects, target_locale:, source_locale:, fast: nil, reference: nil, concurrent: false)
583
587
  raise ValidationError, 'Objects must be an Array' unless objects.is_a?(Array)
584
588
  raise ValidationError, 'Objects cannot be empty' if objects.empty?
585
589
  raise ValidationError, 'Target locale is required' if target_locale.nil? || target_locale.empty?
@@ -637,7 +641,7 @@ module LingoDotDev
637
641
 
638
642
  begin
639
643
  response = make_request(
640
- "#{config.api_url}/recognize",
644
+ "#{config.api_url}/process/recognize",
641
645
  json: { text: text }
642
646
  )
643
647
 
@@ -658,7 +662,7 @@ module LingoDotDev
658
662
  # # => { email: "user@example.com", id: "user-id" }
659
663
  def whoami
660
664
  begin
661
- response = make_request("#{config.api_url}/whoami")
665
+ response = make_request("#{config.api_url}/users/me", method: :get)
662
666
 
663
667
  status_code = response.code.to_i
664
668
  return nil unless status_code >= 200 && status_code < 300
@@ -680,10 +684,11 @@ module LingoDotDev
680
684
  #
681
685
  # @param content [String, Hash] the content to translate (String for text, Hash for object)
682
686
  # @param api_key [String] your Lingo.dev API key
687
+ # @param engine_id [String, nil] the engine ID for localization processing (optional)
683
688
  # @param target_locale [String] the target locale code (e.g., 'es', 'fr', 'ja')
684
- # @param source_locale [String, nil] the source locale code (optional, auto-detected if not provided)
689
+ # @param source_locale [String] the source locale code (e.g., 'en')
685
690
  # @param fast [Boolean] enable fast mode for quicker results (default: true)
686
- # @param api_url [String] the API endpoint URL (default: 'https://engine.lingo.dev')
691
+ # @param api_url [String] the API endpoint URL (default: 'https://api.lingo.dev')
687
692
  #
688
693
  # @return [String, Hash] localized content (String if input was String, Hash if input was Hash)
689
694
  #
@@ -691,18 +696,20 @@ module LingoDotDev
691
696
  # @raise [APIError] if the API request fails
692
697
  #
693
698
  # @example Translate text
694
- # result = LingoDotDev::Engine.quick_translate('Hello', api_key: 'your-api-key', target_locale: 'es')
699
+ # result = LingoDotDev::Engine.quick_translate('Hello', api_key: 'your-api-key', engine_id: 'your-engine-id', target_locale: 'es', source_locale: 'en')
695
700
  # # => "Hola"
696
701
  #
697
702
  # @example Translate object
698
703
  # result = LingoDotDev::Engine.quick_translate(
699
704
  # { greeting: 'Hello', farewell: 'Goodbye' },
700
705
  # api_key: 'your-api-key',
701
- # target_locale: 'fr'
706
+ # engine_id: 'your-engine-id',
707
+ # target_locale: 'fr',
708
+ # source_locale: 'en'
702
709
  # )
703
710
  # # => { greeting: "Bonjour", farewell: "Au revoir" }
704
- def self.quick_translate(content, api_key:, target_locale:, source_locale: nil, fast: true, api_url: 'https://engine.lingo.dev')
705
- engine = new(api_key: api_key, api_url: api_url)
711
+ def self.quick_translate(content, api_key:, engine_id: nil, target_locale:, source_locale:, fast: true, api_url: 'https://api.lingo.dev')
712
+ engine = new(api_key: api_key, engine_id: engine_id, api_url: api_url)
706
713
  case content
707
714
  when String
708
715
  engine.localize_text(
@@ -731,10 +738,11 @@ module LingoDotDev
731
738
  #
732
739
  # @param content [String, Hash] the content to translate (String for text, Hash for object)
733
740
  # @param api_key [String] your Lingo.dev API key
741
+ # @param engine_id [String, nil] the engine ID for localization processing (optional)
734
742
  # @param target_locales [Array<String>] array of target locale codes
735
- # @param source_locale [String, nil] the source locale code (optional, auto-detected if not provided)
743
+ # @param source_locale [String] the source locale code (e.g., 'en')
736
744
  # @param fast [Boolean] enable fast mode for quicker results (default: true)
737
- # @param api_url [String] the API endpoint URL (default: 'https://engine.lingo.dev')
745
+ # @param api_url [String] the API endpoint URL (default: 'https://api.lingo.dev')
738
746
  #
739
747
  # @return [Array<String>, Array<Hash>] array of localized results (Strings if input was String, Hashes if input was Hash)
740
748
  #
@@ -745,7 +753,9 @@ module LingoDotDev
745
753
  # results = LingoDotDev::Engine.quick_batch_translate(
746
754
  # 'Hello',
747
755
  # api_key: 'your-api-key',
748
- # target_locales: ['es', 'fr', 'de']
756
+ # engine_id: 'your-engine-id',
757
+ # target_locales: ['es', 'fr', 'de'],
758
+ # source_locale: 'en'
749
759
  # )
750
760
  # # => ["Hola", "Bonjour", "Hallo"]
751
761
  #
@@ -753,11 +763,12 @@ module LingoDotDev
753
763
  # results = LingoDotDev::Engine.quick_batch_translate(
754
764
  # { greeting: 'Hello' },
755
765
  # api_key: 'your-api-key',
756
- # target_locales: ['es', 'fr']
766
+ # target_locales: ['es', 'fr'],
767
+ # source_locale: 'en'
757
768
  # )
758
769
  # # => [{ greeting: "Hola" }, { greeting: "Bonjour" }]
759
- def self.quick_batch_translate(content, api_key:, target_locales:, source_locale: nil, fast: true, api_url: 'https://engine.lingo.dev')
760
- engine = new(api_key: api_key, api_url: api_url)
770
+ def self.quick_batch_translate(content, api_key:, engine_id: nil, target_locales:, source_locale:, fast: true, api_url: 'https://api.lingo.dev')
771
+ engine = new(api_key: api_key, engine_id: engine_id, api_url: api_url)
761
772
  case content
762
773
  when String
763
774
  engine.batch_localize_text(
@@ -784,24 +795,28 @@ module LingoDotDev
784
795
 
785
796
  private
786
797
 
787
- def make_request(url, json: nil)
798
+ def make_request(url, json: nil, method: :post)
788
799
  uri = URI(url)
789
800
  http = Net::HTTP.new(uri.host, uri.port)
790
801
  http.use_ssl = true
791
802
  http.read_timeout = 60
792
803
  http.open_timeout = 60
793
804
 
794
- request = Net::HTTP::Post.new(uri.path)
795
- request['Authorization'] = "Bearer #{config.api_key}"
805
+ request = if method == :get
806
+ Net::HTTP::Get.new(uri.path)
807
+ else
808
+ Net::HTTP::Post.new(uri.path)
809
+ end
810
+ request['X-API-Key'] = config.api_key
796
811
  request['Content-Type'] = 'application/json; charset=utf-8'
797
812
  request.body = JSON.generate(json) if json
798
813
 
799
814
  http.request(request)
800
815
  end
801
816
 
802
- def localize_raw(payload, target_locale:, source_locale: nil, fast: nil, reference: nil, concurrent: false, &progress_callback)
817
+ def localize_raw(payload, target_locale:, source_locale:, fast: nil, reference: nil, concurrent: false, &progress_callback)
818
+ raise ValidationError, 'Source locale is required' if source_locale.nil? || (source_locale.is_a?(String) && source_locale.empty?)
803
819
  chunked_payload = extract_payload_chunks(payload)
804
- workflow_id = SecureRandom.hex(8)
805
820
 
806
821
  processed_chunks = if concurrent && !progress_callback
807
822
  threads = chunked_payload.map do |chunk|
@@ -811,8 +826,7 @@ module LingoDotDev
811
826
  target_locale: target_locale,
812
827
  source_locale: source_locale,
813
828
  fast: fast,
814
- reference: reference,
815
- workflow_id: workflow_id
829
+ reference: reference
816
830
  )
817
831
  end
818
832
  end
@@ -826,8 +840,7 @@ module LingoDotDev
826
840
  target_locale: target_locale,
827
841
  source_locale: source_locale,
828
842
  fast: fast,
829
- reference: reference,
830
- workflow_id: workflow_id
843
+ reference: reference
831
844
  )
832
845
 
833
846
  progress_callback&.call(percentage_completed, chunk, processed_chunk)
@@ -841,19 +854,17 @@ module LingoDotDev
841
854
  result
842
855
  end
843
856
 
844
- def localize_chunk(chunk, target_locale:, source_locale:, fast:, reference:, workflow_id:)
857
+ def localize_chunk(chunk, target_locale:, source_locale:, fast:, reference:)
845
858
  request_body = {
846
- params: {
847
- workflowId: workflow_id,
848
- fast: fast || false
849
- },
850
- locale: {
851
- source: source_locale,
852
- target: target_locale
853
- },
854
- data: chunk
859
+ params: { fast: fast || false },
860
+ sourceLocale: source_locale,
861
+ targetLocale: target_locale,
862
+ data: chunk,
863
+ sessionId: @session_id
855
864
  }
856
865
 
866
+ request_body[:engineId] = config.engine_id unless config.engine_id.nil?
867
+
857
868
  if reference && !reference.empty?
858
869
  raise ValidationError, 'Reference must be a Hash' unless reference.is_a?(Hash)
859
870
  request_body[:reference] = reference
@@ -863,7 +874,7 @@ module LingoDotDev
863
874
 
864
875
  begin
865
876
  response = make_request(
866
- "#{config.api_url}/i18n",
877
+ "#{config.api_url}/process/localize",
867
878
  json: request_body
868
879
  )
869
880
 
@@ -926,7 +937,7 @@ module LingoDotDev
926
937
  if status_code >= 500
927
938
  raise ServerError, "Server error (#{status_code}): #{response.message}. #{response.body}. This may be due to temporary service issues."
928
939
  elsif status_code == 400
929
- raise ValidationError, "Invalid request (#{status_code}): #{response.message}"
940
+ raise ValidationError, "Invalid request (#{status_code}): #{response.message}. #{response.body}"
930
941
  elsif status_code == 401
931
942
  raise AuthenticationError, "Authentication failed (#{status_code}): #{response.message}"
932
943
  else
@@ -7,11 +7,18 @@ RSpec.describe LingoDotDev::Configuration do
7
7
  it 'creates a configuration with valid api_key' do
8
8
  config = described_class.new(api_key: 'test-key')
9
9
  expect(config.api_key).to eq('test-key')
10
+ expect(config.engine_id).to be_nil
11
+ end
12
+
13
+ it 'creates a configuration with api_key and engine_id' do
14
+ config = described_class.new(api_key: 'test-key', engine_id: 'test-engine')
15
+ expect(config.api_key).to eq('test-key')
16
+ expect(config.engine_id).to eq('test-engine')
10
17
  end
11
18
 
12
19
  it 'uses default api_url' do
13
20
  config = described_class.new(api_key: 'test-key')
14
- expect(config.api_url).to eq('https://engine.lingo.dev')
21
+ expect(config.api_url).to eq('https://api.lingo.dev')
15
22
  end
16
23
 
17
24
  it 'uses default batch_size' do
@@ -131,6 +138,12 @@ RSpec.describe LingoDotDev::Configuration do
131
138
  expect(config.api_url).to eq('https://new-url.com')
132
139
  end
133
140
 
141
+ it 'allows setting engine_id after initialization' do
142
+ config = described_class.new(api_key: 'test-key')
143
+ config.engine_id = 'new-engine'
144
+ expect(config.engine_id).to eq('new-engine')
145
+ end
146
+
134
147
  it 'allows setting batch_size after initialization' do
135
148
  config = described_class.new(api_key: 'test-key')
136
149
  config.batch_size = 100