diff --git a/packages/client/src/helpers/language-helpers.js b/packages/client/src/helpers/language-helpers.js new file mode 100644 index 0000000000..d4a4e87a14 --- /dev/null +++ b/packages/client/src/helpers/language-helpers.js @@ -0,0 +1,27 @@ +import { getLanguage } from "@docspace/shared/utils"; +import { translations } from "./autoGeneratedTranslations"; + +export function loadLanguagePath(homepage, fixedNS = null) { + return (lng, ns) => { + const language = getLanguage(lng instanceof Array ? lng[0] : lng); + + const lngCollection = translations?.get(language); + + const data = lngCollection?.get(`${fixedNS || ns}`); + + if (!data) return `/locales/${language}/${fixedNS || ns}.json`; + + let path = data?.split("/"); + const length = path?.length; + + const isCommonPath = path[length - 1].indexOf("Common") > -1; + + path = `/${path[length - 3]}/${path[length - 2]}/${path[length - 1]}`; + + if (ns.length > 0 && ns[0] === "Common" && isCommonPath) { + return `/static${path}`; + } + + return path; + }; +} diff --git a/packages/client/src/helpers/utils.js b/packages/client/src/helpers/utils.js index 93f7091070..87c6356414 100644 --- a/packages/client/src/helpers/utils.js +++ b/packages/client/src/helpers/utils.js @@ -25,12 +25,10 @@ // International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode import { authStore } from "@docspace/shared/store"; -import { getLanguage } from "@docspace/shared/utils"; import { toCommunityHostname } from "@docspace/shared/utils/common"; - import { CategoryType } from "./constants"; -import { FolderType, ShareAccessRights } from "@docspace/shared/enums"; -import { translations } from "./autoGeneratedTranslations"; +import { FolderType } from "@docspace/shared/enums"; + // import router from "SRC_DIR/router"; import i18n from "../i18n"; @@ -54,31 +52,6 @@ export const setDocumentTitle = (subTitle = "") => { document.title = title; }; -export function loadLanguagePath(homepage, fixedNS = null) { - return (lng, ns) => { - const language = getLanguage(lng instanceof Array ? lng[0] : lng); - - const lngCollection = translations?.get(language); - - const data = lngCollection?.get(`${fixedNS || ns}`); - - if (!data) return `/locales/${language}/${fixedNS || ns}.json`; - - let path = data?.split("/"); - const length = path?.length; - - const isCommonPath = path[length - 1].indexOf("Common") > -1; - - path = `/${path[length - 3]}/${path[length - 2]}/${path[length - 1]}`; - - if (ns.length > 0 && ns[0] === "Common" && isCommonPath) { - return `/static${path}`; - } - - return path; - }; -} - export const checkIfModuleOld = (link) => { if ( !link || diff --git a/packages/client/src/i18n.js b/packages/client/src/i18n.js index 5c200fe821..cccd9e5643 100644 --- a/packages/client/src/i18n.js +++ b/packages/client/src/i18n.js @@ -31,7 +31,7 @@ import config from "PACKAGE_FILE"; import { LANGUAGE } from "@docspace/shared/constants"; import { getCookie } from "@docspace/shared/utils"; -import { loadLanguagePath } from "./helpers/utils"; +import { loadLanguagePath } from "./helpers/language-helpers"; const newInstance = i18n.createInstance();