Skip to content

Commit

Permalink
fix(i18n): bug loading the default locale correctly
Browse files Browse the repository at this point in the history
fix #167
  • Loading branch information
pikax committed Mar 9, 2020
1 parent ffe23dd commit 8c2ee07
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/core/__tests__/i18n/i18n.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,19 @@ describe("i18n", () => {
expect((x.i18n.value as any).hello).toBeUndefined();
});
});

it("should fallback if the locale is different than fallback locale", async () => {
const x = buildI18n({
locale: "jp",
fallback: "en",
messages: {
en: { hello: "Hello" },
jp: {}
}
});

await nextTick();

expect((x.i18n.value as any).hello).toBe("Hello");
});
});
7 changes: 5 additions & 2 deletions packages/core/src/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ export function buildI18n<

let fallbackIsPromise = false;
if (shouldFallback) {
const fallbackI18n = loadLocale(locale.value as string, localeMessages);
const fallbackI18n = loadLocale(
definition.fallback! as string,
localeMessages
);
if (isPromise(fallbackI18n)) {
fallbackI18n.then(x => {
fallback = x;
Expand All @@ -147,7 +150,7 @@ export function buildI18n<
fallback.value = {};
}

watch(
watch(
[locale, fallback],
async ([l, fb]: [keyof TMessage, i18n | undefined]) => {
if (l === definition.fallback && shouldFallback) {
Expand Down

0 comments on commit 8c2ee07

Please sign in to comment.