Skip to content

Commit

Permalink
updates intl formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
lcflight committed Oct 30, 2024
1 parent 3ff27f7 commit 2a8708e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
7 changes: 3 additions & 4 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@silvermine/videojs-chromecast": "^1.5.0",
"@tanstack/react-query": "^5.56.2",
"@tanstack/react-query-devtools": "^5.56.2",
"caniuse-lite": "^1.0.30001669",
"clsx": "^2.1.1",
"cookie": "^0.7.0",
"dayjs": "^1.11.13",
Expand Down
16 changes: 14 additions & 2 deletions src/lib/getIntlMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ResolvedIntlConfig } from 'react-intl';

import getLanguageByBaseUrl from '~lib/getLanguageByBaseUrl';

export default function getIntlMessages(
export default async function getIntlMessages(
languageRoute: string,
): Promise<ResolvedIntlConfig['messages']> {
const lang = getLanguageByBaseUrl(languageRoute, 'en');
Expand All @@ -11,5 +11,17 @@ export default function getIntlMessages(
throw new Error(`Language "${languageRoute}" not found`);
}

return import(`~public/compiled-lang/${lang.base_urls[0]}.json`);
// Import pre-compiled messages
const messages = await import(
`~public/compiled-lang/${lang.base_urls[0]}.json`
);

// Ensure messages are in the correct format for react-intl v6
return Object.entries(messages).reduce(
(acc, [key, value]) => {
acc[key] = Array.isArray(value) ? value : [{ type: 0, value }];
return acc;
},
{} as ResolvedIntlConfig['messages'],
);
}

0 comments on commit 2a8708e

Please sign in to comment.