Web: Doceditor: fixed load Common ns

This commit is contained in:
Artem Tarasov 2022-03-25 14:50:16 +03:00
parent c8d1a6dda2
commit 504aedc8cb
4 changed files with 17 additions and 47 deletions

View File

@ -127,7 +127,7 @@ function Editor({
const [isLoaded, setIsLoaded] = useState(false);
const [documentTitle, setNewDocumentTitle] = useState("Loading...");
const { t } = useTranslation();
const { t } = useTranslation(["Editor", "Common"]);
useEffect(() => {
if (error) {

View File

@ -3,7 +3,6 @@ import { hydrate } from "react-dom";
import { registerSW } from "@appserver/common/sw/helper";
import App from "../App.js";
import { useSSR } from "react-i18next";
import "../i18n";
import useMfScripts from "../helpers/useMfScripts";
const propsObj = window.__ASC_INITIAL_STATE__;

View File

@ -1,39 +0,0 @@
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import config from "../package.json";
import { LANGUAGE } from "@appserver/common/constants";
import { loadLanguagePath } from "@appserver/common/utils";
const newInstance = i18n.createInstance();
const lng = localStorage.getItem(LANGUAGE) || "en";
newInstance.use(initReactI18next).init({
lng: lng,
fallbackLng: "en",
load: "currentOnly",
//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: loadLanguagePath(config.homepage),
allowMultiLoading: true,
crossDomain: false,
},
ns: ["Editor", "Common"],
defaultNS: "Editor",
react: {
useSuspense: true,
},
});
export default newInstance;

View File

@ -1,19 +1,27 @@
import express from "express";
import path from "path";
import template from "./server/template";
import render from "./server/render";
import i18nextMiddleware from "i18next-express-middleware";
import i18next from "i18next";
import Backend from "i18next-node-fs-backend";
import Backend from "i18next-fs-backend";
import path, { join } from "path";
const loadPath = (lng, ns) => {
let resourcePath =
path.resolve(process.cwd(), "clientBuild") + `/locales/${lng}/${ns}.json`;
if (ns === "Common")
resourcePath = join(__dirname, `../../../public/locales/${lng}/${ns}.json`);
return resourcePath;
};
const app = express();
const port = process.env.PORT || 5013;
i18next.use(Backend).init({
backend: {
loadPath:
path.resolve(process.cwd(), "clientBuild") +
"/locales/{{lng}}/{{ns}}.json",
loadPath: loadPath,
allowMultiLoading: true,
crossDomain: false,
},
@ -45,9 +53,11 @@ app.get("/products/files/doceditor", async (req, res) => {
const { props, content, styleTags, scriptTags } = await render(req);
const userLng = props?.user?.cultureName || "en";
const initialI18nStore = {};
i18next.changeLanguage(userLng).then(() => {
const initialLanguage = userLng;
const initialI18nStore = {};
const usedNamespaces = req.i18n.reportNamespaces.getUsedNamespaces();
initialI18nStore[initialLanguage] = {};