Skip to content

Commit

Permalink
#15 language content implementation ready. (#16)
Browse files Browse the repository at this point in the history
* #15 language content implementation ready.

* #15 add language from i18n

* improve language code

Co-authored-by: Vít Zadina <[email protected]>
  • Loading branch information
zadinvit and zadinaQ authored Jul 22, 2022
1 parent 53ee54e commit e12a0f4
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions admin/src/components/CKEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
}
Expand All @@ -132,7 +147,7 @@ const Editor = ({ onChange, name, value, disabled }) => {
}
})();

return () => {};
return () => { };
}, []);

//###########################################################################################################
Expand Down

0 comments on commit e12a0f4

Please sign in to comment.