i18n with Redwood
Warning
This post is more than a year old. Information may be outdated.
This is an opinionated guide of implementing Internationalization with Redwood.js
Initial Setup
i18n.js
Extract the allowed list for i18n.
Comments
This is an opinionated guide of implementing Internationalization with Redwood.js
i18n.jsExtract the allowed list for i18n.
import i18n from "i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import { initReactI18next } from "react-i18next";
import en from "./locales/en.json";
import fr from "./locales/fr.json";
import ko from "./locales/ko.json";
const languages = {
en: {
translation: en,
},
fr: {
translation: fr,
},
ko: {
translation: ko,
},
};
i18n
// learn more: https://github.com/i18next/i18next-browser-languageDetector
.use(LanguageDetector)
.use(initReactI18next)
.init({
interpolation: { escapeValue: false }, // React already does escaping
fallbackLng: "en",
resources: languages,
});
export const allowedLanguagesList = Object.keys(languages); // 🤟 Here!
export default i18n;
Each path must start with the lang parameter as follows.
Navigating must have lang.
Every page must have the following lang property
This will gently redirect if the lang property does not exist.
Below is hreflang to others, using allowedLanguageList
... Should be generated accordingly
Can we redirect by inserting the current navigator language?
For example, if we land on website.com/about,
website.com/en/about for English userswebsite.com/ko/about for Korean userswindow.location.pathnameNo comments yet. Be the first to share your thoughts.