next-i18next.config.js
const nextI18NextConfig = {
i18n: {
defaultLocale: "fr",
locales: ["en", "fr"],
reloadOnPrerender: process.env.NODE_ENV === "development",
},
}
module.exports = nextI18NextConfig
topics.json
{
"feedback-introduction": {
"fr": {
"name": "Introduction à la rétroaction"
},
"en": {
"name": "Introduction to feedback"
}
}
}
topics.tsx
…
import i18n from "./next-i18next.config.js"
import topics from "./topics.json"
export default () => {
const { locale } = useRouter()
const { t } = useTranslation("common")
var localizedTopics: string[] = []
for (const [slug, topic] of Object.entries(topics)) {
localizedTopics.push(topic[locale as "en" | "fr"].name)
}
…
}
Instead of using locale as "en" | "fr"
, I would like to infer "en" | "fr"
programatically from locales
in next-i18next.config.js
.
Is that possible?