-
I'm migrating from vue-i18n to next-intl.
messages/index.js import enUS from './en-US'
import de from "./de";
export default {
'en-US': enUS,
'de': de
}; messages/en/index.js excerpt export default {
profile: {
title: 'Profile Settings',
},
// ...
} But next-intl expects JSON. How do I accomplish that? I already did const enUS = {
profile: {
title: 'Profile Settings',
}
}
export default JSON.stringify(enUS) Can't I simply import all the translation files and return them conditionally? |
Beta Was this translation helpful? Give feedback.
Answered by
idc77
Nov 12, 2024
Replies: 2 comments
-
I now have import {getRequestConfig} from 'next-intl/server';
export default getRequestConfig(async () => {
// Provide a static locale, fetch a user setting,
// read from `cookies()`, `headers()`, etc.
const locale = 'en-US';
// console.log(messages[locale]);
const messages = (await import(`@/messages/${locale}/index.js`)).default
return {
locale,
messages: messages
};
}); But import {DarkThemeToggle} from "flowbite-react";
import {useTranslations} from 'next-intl';
export default function Home() {
const t = useTranslations();
return (
<main className="flex min-h-screen items-center justify-center gap-2 dark:bg-gray-800">
<h1 className="text-2xl dark:text-white">{t('index.welcome')}</h1>
<DarkThemeToggle/>
</main>
);
}
messages is populated though. |
Beta Was this translation helpful? Give feedback.
0 replies
-
So the solution was to just
in en-US/index.js |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
idc77
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So the solution was to just
in en-US/index.js