Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use default messages from en as fallback if messages are missing in another locale #7054

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions apps/site/i18n.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import { importLocale } from '@node-core/website-i18n';
import deepmerge from 'deepmerge';
bmuenzenmeyer marked this conversation as resolved.
Show resolved Hide resolved
import { getRequestConfig } from 'next-intl/server';

import { availableLocaleCodes } from '@/next.locales.mjs';

// Loads the Application Locales/Translations Dynamically
const loadLocaleDictionary = async (locale: string) => {
// This enables HMR on the English Locale, so that instant refresh
// happens while we add/change texts on the source locale
const defaultMessages = await import(
'@node-core/website-i18n/locales/en.json'
).then(f => f.default);

if (locale === 'en') {
// This enables HMR on the English Locale, so that instant refresh
// happens while we add/change texts on the source locale
return import('@node-core/website-i18n/locales/en.json').then(
f => f.default
);
return defaultMessages;
}

if (availableLocaleCodes.includes(locale)) {
// Other languages don't really require HMR as they will never be development languages
// so we can load them dynamically
return importLocale(locale);
const messages = await importLocale(locale);

// Use default messages as fallback
return deepmerge(defaultMessages, messages);
}

throw new Error(`Unsupported locale: ${locale}`);
Expand Down
1 change: 1 addition & 0 deletions apps/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"classnames": "~2.5.1",
"cross-env": "7.0.3",
"dedent": "1.5.3",
"deepmerge": "^4.3.1",
"feed": "~4.2.2",
"github-slugger": "~2.0.0",
"glob": "~11.0.0",
Expand Down
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading