@@ -19,7 +19,7 @@ import { deserialize } from 'node:v8';
1919import { parseSync } from 'oxc-parser' ;
2020import { traversePostOrder } from '../oxc/traversal' ;
2121import { createSharedTranslationProxy } from './i18n-translation-reader' ;
22- import { loadLocaleData } from './locale-data' ;
22+ import { type LoadedLocaleData , loadLocaleData } from './locale-data' ;
2323
2424/**
2525 * The options passed to the inliner for each code request
@@ -51,6 +51,7 @@ export interface InlineCodeRequest {
5151 * How to handle missing translations.
5252 */
5353 missingTranslation ?: 'error' | 'warning' | 'ignore' ;
54+ workspaceRoot ?: string ;
5455}
5556
5657/**
@@ -89,6 +90,7 @@ export interface InlineFileBatchRequest {
8990 * How to handle missing translations.
9091 */
9192 missingTranslation ?: 'error' | 'warning' | 'ignore' ;
93+ workspaceRoot ?: string ;
9294
9395 /**
9496 * Whether the file data should be treated as ephemeral and not cached long-term in the Worker.
@@ -152,6 +154,8 @@ const fileDataCache = new Map<string, Promise<CachedFileData>>();
152154 */
153155const deserializedTranslations = new Map < string , Promise < Record < string , ɵParsedTranslation > > > ( ) ;
154156
157+ const localeDataCache = new Map < string , Promise < LoadedLocaleData > > ( ) ;
158+
155159/**
156160 * The current inlining generation for this worker.
157161 */
@@ -286,6 +290,7 @@ export async function inlineFileBatch(
286290 locale ,
287291 await loadTranslation ( locale , translation ) ,
288292 request . filename ,
293+ request . workspaceRoot ,
289294 request . missingTranslation ,
290295 ) ;
291296
@@ -319,6 +324,7 @@ export async function inlineCode(request: InlineCodeRequest): Promise<InlineCode
319324 request . locale ,
320325 await loadTranslation ( request . locale , request . translation ) ,
321326 request . filename ,
327+ request . workspaceRoot ,
322328 request . missingTranslation ,
323329 ) ;
324330
@@ -480,6 +486,7 @@ function escapeTemplatePart(part: string): string {
480486 * @param locale The target locale identifier.
481487 * @param translation The translation messages dictionary, or undefined for untranslated locale.
482488 * @param filename The name of the file being transformed.
489+ * @param workspaceRoot The workspace root used to resolve locale data.
483490 * @param missingTranslation How to handle missing translations.
484491 * @returns The transformed code, optional remapped source map, and diagnostics.
485492 */
@@ -490,6 +497,7 @@ async function inlineLocalize(
490497 locale : string ,
491498 translation : Record < string , ɵParsedTranslation > | undefined ,
492499 filename : string ,
500+ workspaceRoot = process . cwd ( ) ,
493501 missingTranslation : 'error' | 'warning' | 'ignore' = 'warning' ,
494502) {
495503 const magicString = new MagicString ( code ) ;
@@ -502,7 +510,13 @@ async function inlineLocalize(
502510 }
503511
504512 if ( metadata . localeInsertSites . length > 0 ) {
505- const localeData = await loadLocaleData ( locale ) ;
513+ const cacheKey = JSON . stringify ( [ workspaceRoot , locale ] ) ;
514+ let pendingLocaleData = localeDataCache . get ( cacheKey ) ;
515+ if ( ! pendingLocaleData ) {
516+ pendingLocaleData = loadLocaleData ( locale , workspaceRoot ) ;
517+ localeDataCache . set ( cacheKey , pendingLocaleData ) ;
518+ }
519+ const localeData = await pendingLocaleData ;
506520 if ( localeData . error ) {
507521 diagnostics . push ( { type : 'error' , message : localeData . error } ) ;
508522 } else if ( localeData . warning ) {
0 commit comments