Skip to content

Commit 9378d7b

Browse files
committed
fix(i18n): support both string and object forms of i18n.sourceLocale
1 parent d348e37 commit 9378d7b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

libs/native-federation/src/builders/build/builder.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,15 @@ export async function* runBuilder(
155155

156156
const localeFilter = getLocaleFilter(options, runServer);
157157

158+
const sourceLocaleSegment =
159+
typeof i18n?.sourceLocale === 'string'
160+
? i18n.sourceLocale
161+
: i18n?.sourceLocale?.subPath || i18n?.sourceLocale?.code || '';
162+
158163
const browserOutputPath = path.join(
159164
outputOptions.base,
160165
outputOptions.browser,
161-
options.localize ? i18n?.sourceLocale || '' : ''
166+
options.localize ? sourceLocaleSegment : ''
162167
);
163168

164169
const differentDevServerOutputPath =

libs/native-federation/src/utils/i18n.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ export type WorkspaceConfig = {
1010
};
1111

1212
export type I18nConfig = {
13-
sourceLocale: string;
13+
sourceLocale: string | SourceLocaleObject;
1414
locales: Record<string, string>;
1515
};
1616

17+
export type SourceLocaleObject = {
18+
code: string;
19+
baseHref?: string;
20+
subPath?: string;
21+
};
22+
1723
export async function getI18nConfig(
1824
context: BuilderContext
1925
): Promise<I18nConfig | undefined> {
@@ -52,7 +58,10 @@ export async function translateFederationArtefacts(
5258

5359
const targetLocales = locales.join(' ');
5460

55-
const sourceLocale = i18n.sourceLocale;
61+
const sourceLocale =
62+
typeof i18n.sourceLocale === 'string'
63+
? i18n.sourceLocale
64+
: i18n.sourceLocale.code;
5665

5766
const translationOutPath = path.join(outputPath, 'browser', '{{LOCALE}}');
5867

0 commit comments

Comments
 (0)