@@ -56,7 +56,7 @@ export class ReplexicaEngine {
5656 * @param progressCallback - Optional callback function to report progress
5757 * @returns Localized content
5858 */
59- async localize (
59+ async _localizeRaw (
6060 payload : Z . infer < typeof payloadSchema > ,
6161 params : Z . infer < typeof localizationParamsSchema > ,
6262 reference ?: Z . infer < typeof referenceSchema > ,
@@ -178,4 +178,56 @@ export class ReplexicaEngine {
178178 return 0 ;
179179 }
180180 }
181+
182+ /**
183+ * Localize a typical JavaScript object
184+ * @param obj - The object to be localized
185+ * @param params - Localization parameters
186+ * @param progressCallback - Optional callback function to report progress
187+ * @returns Localized object
188+ */
189+ async localizeObject (
190+ obj : Record < string , any > ,
191+ params : Z . infer < typeof localizationParamsSchema > ,
192+ progressCallback ?: ( progress : number ) => void
193+ ) : Promise < Record < string , any > > {
194+ return this . _localizeRaw ( obj , params , undefined , progressCallback ) ;
195+ }
196+
197+ /**
198+ * Localize a text document
199+ * @param textDocument - The text to be localized
200+ * @param params - Localization parameters
201+ * @param progressCallback - Optional callback function to report progress
202+ * @returns Localized text
203+ */
204+ async localizeDocument (
205+ textDocument : string ,
206+ params : Z . infer < typeof localizationParamsSchema > ,
207+ progressCallback ?: ( progress : number ) => void
208+ ) : Promise < string > {
209+ const localized = await this . _localizeRaw ( { text : textDocument } , params , undefined , progressCallback ) ;
210+ return localized . text || '' ;
211+ }
212+
213+ /**
214+ * Localize a chat sequence
215+ * @param chat - The chat sequence to be localized
216+ * @param params - Localization parameters
217+ * @param progressCallback - Optional callback function to report progress
218+ * @returns Localized chat sequence
219+ */
220+ async localizeChat (
221+ chat : Array < { name : string ; text : string } > ,
222+ params : Z . infer < typeof localizationParamsSchema > ,
223+ progressCallback ?: ( progress : number ) => void
224+ ) : Promise < Array < { name : string ; text : string } > > {
225+
226+ const localized = await this . _localizeRaw ( { chat } , params , undefined , progressCallback ) ;
227+
228+ return Object . entries ( localized ) . map ( ( [ key , value ] ) => ( {
229+ name : chat [ parseInt ( key . split ( '_' ) [ 1 ] ) ] . name ,
230+ text : value ,
231+ } ) ) ;
232+ }
181233}
0 commit comments