Skip to content

Commit

Permalink
fix: correct language logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nshenderov committed Oct 4, 2024
1 parent 16a30ff commit 3c8f88a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
20 changes: 8 additions & 12 deletions admin/src/components/Input/config/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,22 @@ export const setLanguage = async (config) => {
const preferedLanguage = getPreferedLanguage();

const {
ui = preferedLanguage,
content,
ui = config.language && typeof config.language === 'string' ?
config.language
: preferedLanguage,
textPartLanguage,
ignorei18n,
} = config.language || {};

if (i18nLang) {
if (i18nLang && !ignorei18n) {
config.language = {
ui: typeof config.language === 'string' ? config.language : ui,
content: ignorei18n ? content : i18nLang,
ui: ui,
content: i18nLang,
textPartLanguage: textPartLanguage,
};
}

if (!config.language) {
config.language = preferedLanguage;
if (ui !== 'en') {
await importLang(config, ui);
}

await importLang(
config,
typeof config.language === 'string' ? config.language : ui
);
};
9 changes: 6 additions & 3 deletions admin/src/utils/localStorage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const STORAGE_KEYS = {
TOKEN: 'jwtToken',
PREFERED_LANGUAGE: 'strapi-admin-language',
PROFILE_THEME: 'STRAPI_THEME'
PROFILE_THEME: 'STRAPI_THEME',
};

export const getStoredToken = () => {
Expand All @@ -17,11 +17,14 @@ export const getStoredToken = () => {
};

export const getPreferedLanguage = () => {
const language = localStorage.getItem(STORAGE_KEYS.PREFERED_LANGUAGE) || 'en';
const language =
localStorage
.getItem(STORAGE_KEYS.PREFERED_LANGUAGE)
.replace(/^"|"$/g, '') || 'en';
return language;
};

export const getProfileTheme = () => {
const theme = localStorage.getItem(STORAGE_KEYS.PROFILE_THEME) || 'en';
const theme = localStorage.getItem(STORAGE_KEYS.PROFILE_THEME) || 'en';
return theme;
};

0 comments on commit 3c8f88a

Please sign in to comment.