DocSpace-client/products/ASC.Files/Client/src/i18n.js

41 lines
948 B
JavaScript

import i18n from "i18next";
import Backend from "i18next-http-backend";
import config from "../package.json";
import { LANGUAGE } from "@appserver/common/constants";
const newInstance = i18n.createInstance();
const lng = localStorage.getItem(LANGUAGE) || "en";
newInstance.use(Backend).init({
lng: lng,
fallbackLng: "en",
load: "languageOnly",
debug: true,
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
format: function (value, format) {
if (format === "lowercase") return value.toLowerCase();
return value;
},
},
backend: {
loadPath: (lng, ns) => {
if (ns.length > 0 && ns[0] === "Common") {
return `/static/locales/${lng}/Common.json`;
}
return `${config.homepage}/locales/${lng}/${ns}.json`;
},
allowMultiLoading: false,
crossDomain: false,
},
react: {
useSuspense: false,
},
});
export default newInstance;