@@ -370,12 +370,17 @@ export class TranslationsParent extends JSWindowActorParent {
370
370
* Notes: The 2.x WASM binary introduces segmentation changes that are necessary
371
371
* to translate CJK languages.
372
372
*
373
- * 3.x Wasm Major Versions
373
+ * 3.x WASM Major Versions
374
374
*
375
375
* - This update introduces memory savings that required a new bergamot-translator.js
376
376
* file due to ASM offsets, but makes no other changes.
377
+ *
378
+ * 4.X WASM Major Versions
379
+ *
380
+ * - This update changes the format of the WASM to be compressed with zstd.
381
+ * The WASM is decompressed only when loaded into the engine.
377
382
*/
378
- static BERGAMOT_MAJOR_VERSION = 3 ;
383
+ static BERGAMOT_MAJOR_VERSION = 4 ;
379
384
380
385
/**
381
386
* The BERGAMOT_MAJOR_VERSION defined above has only a single value, because there will
@@ -415,21 +420,29 @@ export class TranslationsParent extends JSWindowActorParent {
415
420
*
416
421
* - Compatible with 1.x Bergamot WASM binaries.
417
422
* - Compatible with 2.x Bergamot WASM binaries.
423
+ * - Compatible with 3.x Bergamot WASM binaries.
418
424
*
419
425
* Notes: 1.x models are referred to as "tiny" models, and are the models that were shipped with the original
420
426
* release of Translations in Firefox.
421
427
*
422
428
* 2.x Model Major Versions
423
429
*
424
430
* - Compatible with 2.x Bergamot WASM binaries.
431
+ * - Compatible with 3.x Bergamot WASM binaries.
425
432
*
426
433
* Notes: 2.x models are defined by any of two characteristics. The first characteristic is any CJK language model.
427
434
* Only the 2.x WASM binaries support the segmentation concerns needed to interop with CJK language models.
428
435
* The second characteristic is any "base" language model, which is larger than the "tiny" 1.x models.
429
436
* Compatibility for base models is dependent on the code changes in Bug 1926100.
437
+ *
438
+ * 3.X Model Major Versions
439
+ *
440
+ * - Compatible with 4.x Bergamot WASM binaries.
441
+ *
442
+ * Notes: 3.x models are compressed with zstd. They are decompressed only when they are loaded into the engine.
430
443
*/
431
- static LANGUAGE_MODEL_MAJOR_VERSION_MIN = 1 ;
432
- static LANGUAGE_MODEL_MAJOR_VERSION_MAX = 2 ;
444
+ static LANGUAGE_MODEL_MAJOR_VERSION_MIN = 3 ;
445
+ static LANGUAGE_MODEL_MAJOR_VERSION_MAX = 3 ;
433
446
434
447
/**
435
448
* Contains the state that would affect UI. Anytime this state is changed, a dispatch
@@ -1768,8 +1781,8 @@ export class TranslationsParent extends JSWindowActorParent {
1768
1781
const languagePairMap = new Map ( ) ;
1769
1782
1770
1783
for ( const {
1771
- fromLang : sourceLanguage ,
1772
- toLang : targetLanguage ,
1784
+ sourceLanguage,
1785
+ targetLanguage,
1773
1786
variant,
1774
1787
} of records . values ( ) ) {
1775
1788
const key = TranslationsParent . nonPivotKey (
@@ -2157,7 +2170,7 @@ export class TranslationsParent extends JSWindowActorParent {
2157
2170
}
2158
2171
2159
2172
/** @type {RemoteSettingsClient } */
2160
- const client = lazy . RemoteSettings ( "translations-models" ) ;
2173
+ const client = lazy . RemoteSettings ( "translations-models-v2 " ) ;
2161
2174
TranslationsParent . #translationModelsRemoteClient = client ;
2162
2175
client . on ( "sync" , TranslationsParent . #handleTranslationsModelsSync) ;
2163
2176
@@ -2175,8 +2188,8 @@ export class TranslationsParent extends JSWindowActorParent {
2175
2188
* @param {object } [options.filters={}]
2176
2189
* The filters to apply when retrieving the records from RemoteSettings.
2177
2190
* Filters should correspond to properties on the RemoteSettings records themselves.
2178
- * For example, A filter to retrieve only records with a `fromLang ` value of "en" and a `toLang ` value of "es":
2179
- * { filters: { fromLang : "en", toLang : "es" } }
2191
+ * For example, A filter to retrieve only records with a `sourceLanguage ` value of "en" and a `targetLanguage ` value of "es":
2192
+ * { filters: { sourceLanguage : "en", targetLanguage : "es" } }
2180
2193
* @param {number } options.minSupportedMajorVersion
2181
2194
* The minimum major record version that is supported in this build of Firefox.
2182
2195
* @param {number } options.maxSupportedMajorVersion
@@ -2321,8 +2334,8 @@ export class TranslationsParent extends JSWindowActorParent {
2321
2334
// to guarantee uniqueness.
2322
2335
lookupKey : record =>
2323
2336
`${ record . name } ${ TranslationsParent . nonPivotKey (
2324
- record . fromLang ,
2325
- record . toLang ,
2337
+ record . sourceLanguage ,
2338
+ record . targetLanguage ,
2326
2339
record . variant
2327
2340
) } `,
2328
2341
} ) ;
@@ -2384,65 +2397,65 @@ export class TranslationsParent extends JSWindowActorParent {
2384
2397
return records ;
2385
2398
}
2386
2399
// lang -> pivot
2387
- const hasToPivot = new Set ( ) ;
2400
+ const hasTargetPivot = new Set ( ) ;
2388
2401
// pivot -> en
2389
- const hasFromPivot = new Set ( ) ;
2402
+ const hasSourcePivot = new Set ( ) ;
2390
2403
2391
- const fromLangs = new Set ( ) ;
2392
- const toLangs = new Set ( ) ;
2404
+ const sourceLanguages = new Set ( ) ;
2405
+ const targetLanguages = new Set ( ) ;
2393
2406
2394
- for ( const { fromLang , toLang } of records ) {
2395
- fromLangs . add ( fromLang ) ;
2396
- toLangs . add ( toLang ) ;
2407
+ for ( const { sourceLanguage , targetLanguage } of records ) {
2408
+ sourceLanguages . add ( sourceLanguage ) ;
2409
+ targetLanguages . add ( targetLanguage ) ;
2397
2410
2398
- if ( toLang === PIVOT_LANGUAGE ) {
2411
+ if ( targetLanguage === PIVOT_LANGUAGE ) {
2399
2412
// lang -> pivot
2400
- hasToPivot . add ( fromLang ) ;
2413
+ hasTargetPivot . add ( sourceLanguage ) ;
2401
2414
}
2402
- if ( fromLang === PIVOT_LANGUAGE ) {
2415
+ if ( sourceLanguage === PIVOT_LANGUAGE ) {
2403
2416
// pivot -> en
2404
- hasFromPivot . add ( toLang ) ;
2417
+ hasSourcePivot . add ( targetLanguage ) ;
2405
2418
}
2406
2419
}
2407
2420
2408
- const fromLangsToRemove = new Set ( ) ;
2409
- const toLangsToRemove = new Set ( ) ;
2421
+ const sourceLanguagesToRemove = new Set ( ) ;
2422
+ const targetLanguagesToRemove = new Set ( ) ;
2410
2423
2411
- for ( const lang of fromLangs ) {
2412
- if ( lang === PIVOT_LANGUAGE ) {
2424
+ for ( const language of sourceLanguages ) {
2425
+ if ( language === PIVOT_LANGUAGE ) {
2413
2426
continue ;
2414
2427
}
2415
2428
// Check for "lang -> pivot"
2416
- if ( ! hasToPivot . has ( lang ) ) {
2429
+ if ( ! hasTargetPivot . has ( language ) ) {
2417
2430
TranslationsParent . reportError (
2418
2431
new Error (
2419
- `The "from" language model "${ lang } " is being discarded as it doesn't have a pivot language.`
2432
+ `The source language model "${ language } " is being discarded as it doesn't have a pivot language.`
2420
2433
)
2421
2434
) ;
2422
- fromLangsToRemove . add ( lang ) ;
2435
+ sourceLanguagesToRemove . add ( language ) ;
2423
2436
}
2424
2437
}
2425
2438
2426
- for ( const lang of toLangs ) {
2427
- if ( lang === PIVOT_LANGUAGE ) {
2439
+ for ( const language of targetLanguages ) {
2440
+ if ( language === PIVOT_LANGUAGE ) {
2428
2441
continue ;
2429
2442
}
2430
2443
// Check for "pivot -> lang"
2431
- if ( ! hasFromPivot . has ( lang ) ) {
2444
+ if ( ! hasSourcePivot . has ( language ) ) {
2432
2445
TranslationsParent . reportError (
2433
2446
new Error (
2434
- `The "to" language model "${ lang } " is being discarded as it doesn't have a pivot language.`
2447
+ `The target language model "${ language } " is being discarded as it doesn't have a pivot language.`
2435
2448
)
2436
2449
) ;
2437
- toLangsToRemove . add ( lang ) ;
2450
+ targetLanguagesToRemove . add ( language ) ;
2438
2451
}
2439
2452
}
2440
2453
2441
2454
const after = records . filter ( record => {
2442
- if ( fromLangsToRemove . has ( record . fromLang ) ) {
2455
+ if ( sourceLanguagesToRemove . has ( record . sourceLanguage ) ) {
2443
2456
return false ;
2444
2457
}
2445
- if ( toLangsToRemove . has ( record . toLang ) ) {
2458
+ if ( targetLanguagesToRemove . has ( record . targetLanguage ) ) {
2446
2459
return false ;
2447
2460
}
2448
2461
return true ;
@@ -2471,8 +2484,8 @@ export class TranslationsParent extends JSWindowActorParent {
2471
2484
const recordGroups = new Map ( ) ;
2472
2485
for ( const record of records ) {
2473
2486
const key = TranslationsParent . nonPivotKey (
2474
- record . fromLang ,
2475
- record . toLang ,
2487
+ record . sourceLanguage ,
2488
+ record . targetLanguage ,
2476
2489
record . variant
2477
2490
) ;
2478
2491
@@ -2516,7 +2529,7 @@ export class TranslationsParent extends JSWindowActorParent {
2516
2529
}
2517
2530
2518
2531
/** @type {RemoteSettingsClient } */
2519
- const client = lazy . RemoteSettings ( "translations-wasm" ) ;
2532
+ const client = lazy . RemoteSettings ( "translations-wasm-v2 " ) ;
2520
2533
TranslationsParent . #translationsWasmRemoteClient = client ;
2521
2534
client . on ( "sync" , TranslationsParent . #handleTranslationsWasmSync) ;
2522
2535
@@ -2852,16 +2865,16 @@ export class TranslationsParent extends JSWindowActorParent {
2852
2865
if ( isDownloaded ) {
2853
2866
downloadedPairs . add (
2854
2867
TranslationsParent . nonPivotKey (
2855
- record . fromLang ,
2856
- record . toLang ,
2868
+ record . sourceLanguage ,
2869
+ record . targetLanguage ,
2857
2870
record . variant
2858
2871
)
2859
2872
) ;
2860
2873
} else {
2861
2874
nonDownloadedPairs . add (
2862
2875
TranslationsParent . nonPivotKey (
2863
- record . fromLang ,
2864
- record . toLang ,
2876
+ record . sourceLanguage ,
2877
+ record . targetLanguage ,
2865
2878
record . variant
2866
2879
)
2867
2880
) ;
@@ -2926,10 +2939,13 @@ export class TranslationsParent extends JSWindowActorParent {
2926
2939
for ( const record of records . values ( ) ) {
2927
2940
if (
2928
2941
lazy . TranslationsUtils . langTagsMatch (
2929
- record . fromLang ,
2942
+ record . sourceLanguage ,
2930
2943
sourceLanguage
2931
2944
) &&
2932
- lazy . TranslationsUtils . langTagsMatch ( record . toLang , targetLanguage )
2945
+ lazy . TranslationsUtils . langTagsMatch (
2946
+ record . targetLanguage ,
2947
+ targetLanguage
2948
+ )
2933
2949
) {
2934
2950
matchedRecords . add ( record ) ;
2935
2951
matchFound = true ;
@@ -3035,11 +3051,11 @@ export class TranslationsParent extends JSWindowActorParent {
3035
3051
3036
3052
if (
3037
3053
! lazy . TranslationsUtils . langTagsMatch (
3038
- record . fromLang ,
3054
+ record . sourceLanguage ,
3039
3055
sourceLanguage
3040
3056
) ||
3041
3057
! lazy . TranslationsUtils . langTagsMatch (
3042
- record . toLang ,
3058
+ record . targetLanguage ,
3043
3059
targetLanguage
3044
3060
) ||
3045
3061
record . variant !== variant
@@ -3065,8 +3081,8 @@ export class TranslationsParent extends JSWindowActorParent {
3065
3081
const duration = Date . now ( ) - start ;
3066
3082
lazy . console . log (
3067
3083
`Translation model fetched in ${ duration / 1000 } seconds:` ,
3068
- record . fromLang ,
3069
- record . toLang ,
3084
+ record . sourceLanguage ,
3085
+ record . targetLanguage ,
3070
3086
record . variant ,
3071
3087
record . fileType ,
3072
3088
record . version
@@ -3124,8 +3140,11 @@ export class TranslationsParent extends JSWindowActorParent {
3124
3140
await Promise . all (
3125
3141
records . map ( async record => {
3126
3142
if (
3127
- ! lazy . TranslationsUtils . langTagsMatch ( record . fromLang , language ) &&
3128
- ! lazy . TranslationsUtils . langTagsMatch ( record . toLang , language )
3143
+ ! lazy . TranslationsUtils . langTagsMatch (
3144
+ record . sourceLanguage ,
3145
+ language
3146
+ ) &&
3147
+ ! lazy . TranslationsUtils . langTagsMatch ( record . targetLanguage , language )
3129
3148
) {
3130
3149
return ;
3131
3150
}
@@ -3204,10 +3223,13 @@ export class TranslationsParent extends JSWindowActorParent {
3204
3223
3205
3224
if (
3206
3225
! lazy . TranslationsUtils . langTagsMatch (
3207
- record . fromLang ,
3226
+ record . sourceLanguage ,
3208
3227
sourceLanguage
3209
3228
) ||
3210
- ! lazy . TranslationsUtils . langTagsMatch ( record . toLang , targetLanguage )
3229
+ ! lazy . TranslationsUtils . langTagsMatch (
3230
+ record . targetLanguage ,
3231
+ targetLanguage
3232
+ )
3211
3233
) {
3212
3234
return ;
3213
3235
}
0 commit comments