From e12a0f42b5082cfacd659f7ca33aeb935ade0221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Zadina?= <34831565+zadinvit@users.noreply.github.com> Date: Fri, 22 Jul 2022 19:16:22 +0200 Subject: [PATCH] #15 language content implementation ready. (#16) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * #15 language content implementation ready. * #15 add language from i18n * improve language code Co-authored-by: Vít Zadina --- admin/src/components/CKEditor/index.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/admin/src/components/CKEditor/index.js b/admin/src/components/CKEditor/index.js index 869c976..d01dde3 100644 --- a/admin/src/components/CKEditor/index.js +++ b/admin/src/components/CKEditor/index.js @@ -73,12 +73,28 @@ const Editor = ({ onChange, name, value, disabled }) => { const plugin = await request(`/${pluginId}/config/plugin`, { method: "GET" }); const upload = await request(`/${pluginId}/config/uploadcfg`, { method: "GET" }); + //read i18n locale + const urlSearchParams = new URLSearchParams(window.location.search); + const params = Object.fromEntries(urlSearchParams.entries()); + const languageContent = params["plugins[i18n][locale]"]; + if (editor) { + //set locale language code to content + let language = editor.language; + if (languageContent) { + const countryCode = languageContent.split("-")[0] + if (countryCode && language) + language = { + content: language.content || countryCode, + ui: typeof language === "string" && language || language.ui || auth.getUserInfo().preferedLanguage, + textPartLanguage: language.textPartLanguage + } + } setConfig({ ...config, editor: { ...editor, - language: editor.language ? editor.language : auth.getUserInfo().preferedLanguage, + language: language ? language : auth.getUserInfo().preferedLanguage, strapiMediaLib: { onToggle: toggleMediaLib, label: "Media library", @@ -109,8 +125,7 @@ const Editor = ({ onChange, name, value, disabled }) => { } if (!editor.language) { import( - /* webpackMode: "eager" */ `./build/translations/${ - auth.getUserInfo().preferedLanguage + /* webpackMode: "eager" */ `./build/translations/${auth.getUserInfo().preferedLanguage }.js` ).catch(() => null); } @@ -132,7 +147,7 @@ const Editor = ({ onChange, name, value, disabled }) => { } })(); - return () => {}; + return () => { }; }, []); //###########################################################################################################