Skip to content

Commit

Permalink
i18next: support user defined overriden translations for react
Browse files Browse the repository at this point in the history
  • Loading branch information
zzacharo committed Mar 21, 2024
1 parent a6b6d78 commit 0a4ccff
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import LanguageDetector from "i18next-browser-languagedetector";
import { translations } from "./messages";
import { initReactI18next } from "react-i18next";

const { languages } = require("./package.json").config;

const options = {
fallbackLng: "en", // fallback keys
returnEmptyString: false,
Expand All @@ -34,4 +36,13 @@ const options = {
const i18next = i18n.createInstance();
i18next.use(LanguageDetector).use(initReactI18next).init(options);

languages.forEach((lng) => {
try {
const overridenTranslations = require(`@overriden_translations/${lng}/LC_MESSAGES/translations.json`);
i18next.addResourceBundle(lng, "translation", overridenTranslations);
} catch (e) {
console.log("No overridden translations found for language", lng);
}
});

export { i18next };

0 comments on commit 0a4ccff

Please sign in to comment.