Skip to content

Commit 8c2ee07

Browse files
committed
fix(i18n): bug loading the default locale correctly
fix #167
1 parent ffe23dd commit 8c2ee07

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/core/__tests__/i18n/i18n.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,19 @@ describe("i18n", () => {
100100
expect((x.i18n.value as any).hello).toBeUndefined();
101101
});
102102
});
103+
104+
it("should fallback if the locale is different than fallback locale", async () => {
105+
const x = buildI18n({
106+
locale: "jp",
107+
fallback: "en",
108+
messages: {
109+
en: { hello: "Hello" },
110+
jp: {}
111+
}
112+
});
113+
114+
await nextTick();
115+
116+
expect((x.i18n.value as any).hello).toBe("Hello");
117+
});
103118
});

packages/core/src/i18n/i18n.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ export function buildI18n<
134134

135135
let fallbackIsPromise = false;
136136
if (shouldFallback) {
137-
const fallbackI18n = loadLocale(locale.value as string, localeMessages);
137+
const fallbackI18n = loadLocale(
138+
definition.fallback! as string,
139+
localeMessages
140+
);
138141
if (isPromise(fallbackI18n)) {
139142
fallbackI18n.then(x => {
140143
fallback = x;
@@ -147,7 +150,7 @@ export function buildI18n<
147150
fallback.value = {};
148151
}
149152

150-
watch(
153+
watch(
151154
[locale, fallback],
152155
async ([l, fb]: [keyof TMessage, i18n | undefined]) => {
153156
if (l === definition.fallback && shouldFallback) {

0 commit comments

Comments
 (0)