@@ -10,25 +10,25 @@ const engineParamsSchema = Z.object({
1010} ) . passthrough ( ) ;
1111
1212const payloadSchema = Z . record ( Z . string ( ) , Z . any ( ) ) ;
13+ const referenceSchema = Z . record ( localeCodeSchema , payloadSchema ) ;
1314
1415const localizationParamsSchema = Z . object ( {
1516 sourceLocale : localeCodeSchema ,
1617 targetLocale : localeCodeSchema ,
1718 fast : Z . boolean ( ) . optional ( ) ,
19+ reference : referenceSchema . optional ( ) ,
1820} ) ;
1921
20- const referenceSchema = Z . record ( localeCodeSchema , payloadSchema ) ;
21-
2222/**
23- * ReplexicaEngine class for interacting with the Lingo.dev API
23+ * LingoDotDevEngine class for interacting with the LingoDotDev API
2424 * A powerful localization engine that supports various content types including
2525 * plain text, objects, chat sequences, and HTML documents.
2626 */
27- export class ReplexicaEngine {
28- private config : Z . infer < typeof engineParamsSchema > ;
27+ export class LingoDotDevEngine {
28+ protected config : Z . infer < typeof engineParamsSchema > ;
2929
3030 /**
31- * Create a new ReplexicaEngine instance
31+ * Create a new LingoDotDevEngine instance
3232 * @param config - Configuration options for the Engine
3333 */
3434 constructor ( config : Partial < Z . infer < typeof engineParamsSchema > > ) {
@@ -39,15 +39,13 @@ export class ReplexicaEngine {
3939 * Localize content using the Lingo.dev API
4040 * @param payload - The content to be localized
4141 * @param params - Localization parameters including source/target locales and fast mode option
42- * @param reference - Optional reference translations to maintain consistency
4342 * @param progressCallback - Optional callback function to report progress (0-100)
4443 * @returns Localized content
4544 * @internal
4645 */
4746 async _localizeRaw (
4847 payload : Z . infer < typeof payloadSchema > ,
4948 params : Z . infer < typeof localizationParamsSchema > ,
50- reference ?: Z . infer < typeof referenceSchema > ,
5149 progressCallback ?: (
5250 progress : number ,
5351 sourceChunk : Record < string , string > ,
@@ -68,7 +66,7 @@ export class ReplexicaEngine {
6866 const processedPayloadChunk = await this . localizeChunk (
6967 finalParams . sourceLocale ,
7068 finalParams . targetLocale ,
71- { data : chunk , reference } ,
69+ { data : chunk , reference : params . reference } ,
7270 workflowId ,
7371 params . fast || false ,
7472 ) ;
@@ -93,7 +91,10 @@ export class ReplexicaEngine {
9391 private async localizeChunk (
9492 sourceLocale : string ,
9593 targetLocale : string ,
96- payload : { data : any ; reference : any } ,
94+ payload : {
95+ data : Z . infer < typeof payloadSchema > ;
96+ reference ?: Z . infer < typeof referenceSchema > ;
97+ } ,
9798 workflowId : string ,
9899 fast : boolean ,
99100 ) : Promise < Record < string , string > > {
@@ -198,7 +199,7 @@ export class ReplexicaEngine {
198199 processedChunk : Record < string , string > ,
199200 ) => void ,
200201 ) : Promise < Record < string , any > > {
201- return this . _localizeRaw ( obj , params , undefined , progressCallback ) ;
202+ return this . _localizeRaw ( obj , params , progressCallback ) ;
202203 }
203204
204205 /**
@@ -216,7 +217,7 @@ export class ReplexicaEngine {
216217 params : Z . infer < typeof localizationParamsSchema > ,
217218 progressCallback ?: ( progress : number ) => void ,
218219 ) : Promise < string > {
219- const response = await this . _localizeRaw ( { text } , params , undefined , progressCallback ) ;
220+ const response = await this . _localizeRaw ( { text } , params , progressCallback ) ;
220221 return response . text || "" ;
221222 }
222223
@@ -265,7 +266,7 @@ export class ReplexicaEngine {
265266 params : Z . infer < typeof localizationParamsSchema > ,
266267 progressCallback ?: ( progress : number ) => void ,
267268 ) : Promise < Array < { name : string ; text : string } > > {
268- const localized = await this . _localizeRaw ( { chat } , params , undefined , progressCallback ) ;
269+ const localized = await this . _localizeRaw ( { chat } , params , progressCallback ) ;
269270
270271 return Object . entries ( localized ) . map ( ( [ key , value ] ) => ( {
271272 name : chat [ parseInt ( key . split ( "_" ) [ 1 ] ) ] . name ,
@@ -371,7 +372,7 @@ export class ReplexicaEngine {
371372 . filter ( ( n ) => n . nodeType === 1 || ( n . nodeType === 3 && n . textContent ?. trim ( ) ) )
372373 . forEach ( processNode ) ;
373374
374- const localizedContent = await this . _localizeRaw ( extractedContent , params , undefined , progressCallback ) ;
375+ const localizedContent = await this . _localizeRaw ( extractedContent , params , progressCallback ) ;
375376
376377 // Update the DOM with localized content
377378 document . documentElement . setAttribute ( "lang" , params . targetLocale ) ;
@@ -428,3 +429,23 @@ export class ReplexicaEngine {
428429 return jsonResponse . locale ;
429430 }
430431}
432+
433+ /**
434+ * @deprecated Use LingoDotDevEngine instead. This class is maintained for backwards compatibility.
435+ */
436+ export class ReplexicaEngine extends LingoDotDevEngine {
437+ constructor ( config : Partial < Z . infer < typeof engineParamsSchema > > ) {
438+ super ( config ) ;
439+ console . warn ( "ReplexicaEngine is deprecated. Please use LingoDotDevEngine instead." ) ;
440+ }
441+ }
442+
443+ /**
444+ * @deprecated Use LingoDotDevEngine instead. This class is maintained for backwards compatibility.
445+ */
446+ export class LingoEngine extends LingoDotDevEngine {
447+ constructor ( config : Partial < Z . infer < typeof engineParamsSchema > > ) {
448+ super ( config ) ;
449+ console . warn ( "LingoEngine is deprecated. Please use LingoDotDevEngine instead." ) ;
450+ }
451+ }
0 commit comments