Skip to content

Commit 95528c6

Browse files
Merge pull request #859 from eintim/main
fix(i18n): support both string and object forms of i18n.sourceLocale
2 parents eeb59d8 + 9378d7b commit 95528c6

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
@@ -154,10 +154,15 @@ export async function* runBuilder(
154154

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

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

163168
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)