mirror of https://gitee.com/answerdev/answer.git
fix: install select langs need change i18n
This commit is contained in:
parent
3f04532003
commit
9dd41b6248
|
@ -1,5 +1,5 @@
|
||||||
export const DEFAULT_LANG = 'en_US';
|
export const DEFAULT_LANG = 'en_US';
|
||||||
export const CURRENT_LANG_STORAGE_KEY = '_a_lang__';
|
export const CURRENT_LANG_STORAGE_KEY = '_a_lang_';
|
||||||
export const LOGGED_USER_STORAGE_KEY = '_a_lui_';
|
export const LOGGED_USER_STORAGE_KEY = '_a_lui_';
|
||||||
export const LOGGED_TOKEN_STORAGE_KEY = '_a_ltk_';
|
export const LOGGED_TOKEN_STORAGE_KEY = '_a_ltk_';
|
||||||
export const REDIRECT_PATH_STORAGE_KEY = '_a_rp_';
|
export const REDIRECT_PATH_STORAGE_KEY = '_a_rp_';
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import type { LangsType, FormValue, FormDataType } from '@/common/interface';
|
import type { LangsType, FormValue, FormDataType } from '@/common/interface';
|
||||||
import Progress from '../Progress';
|
import Progress from '../Progress';
|
||||||
import { getInstallLangOptions } from '@/services';
|
import { getLanguageOptions } from '@/services';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
data: FormValue;
|
data: FormValue;
|
||||||
|
@ -18,7 +18,7 @@ const Index: FC<Props> = ({ visible, data, changeCallback, nextCallback }) => {
|
||||||
const [langs, setLangs] = useState<LangsType[]>();
|
const [langs, setLangs] = useState<LangsType[]>();
|
||||||
|
|
||||||
const getLangs = async () => {
|
const getLangs = async () => {
|
||||||
const res: LangsType[] = await getInstallLangOptions();
|
const res: LangsType[] = await getLanguageOptions();
|
||||||
setLangs(res);
|
setLangs(res);
|
||||||
changeCallback({
|
changeCallback({
|
||||||
lang: {
|
lang: {
|
||||||
|
|
|
@ -10,6 +10,8 @@ import {
|
||||||
installBaseInfo,
|
installBaseInfo,
|
||||||
checkConfigFileExists,
|
checkConfigFileExists,
|
||||||
} from '@/services';
|
} from '@/services';
|
||||||
|
import { Storage } from '@/utils';
|
||||||
|
import { CURRENT_LANG_STORAGE_KEY } from '@/common/constants';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
FirstStep,
|
FirstStep,
|
||||||
|
@ -170,13 +172,20 @@ const Index: FC = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleStep = () => {
|
const handleStep = () => {
|
||||||
|
if (step === 1) {
|
||||||
|
Storage.set(CURRENT_LANG_STORAGE_KEY, formData.lang.value);
|
||||||
|
handleNext();
|
||||||
|
}
|
||||||
if (step === 2) {
|
if (step === 2) {
|
||||||
submitDatabaseForm();
|
submitDatabaseForm();
|
||||||
} else if (step === 3) {
|
}
|
||||||
|
if (step === 3) {
|
||||||
checkInstall();
|
checkInstall();
|
||||||
} else if (step === 4) {
|
}
|
||||||
|
if (step === 4) {
|
||||||
submitSiteConfig();
|
submitSiteConfig();
|
||||||
} else {
|
}
|
||||||
|
if (step > 4) {
|
||||||
handleNext();
|
handleNext();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,8 @@ import dayjs from 'dayjs';
|
||||||
import i18next from 'i18next';
|
import i18next from 'i18next';
|
||||||
|
|
||||||
import { interfaceStore, loggedUserInfoStore } from '@/stores';
|
import { interfaceStore, loggedUserInfoStore } from '@/stores';
|
||||||
import { DEFAULT_LANG } from '@/common/constants';
|
import { DEFAULT_LANG, CURRENT_LANG_STORAGE_KEY } from '@/common/constants';
|
||||||
|
import { Storage } from '@/utils';
|
||||||
|
|
||||||
const localDayjs = (langName) => {
|
const localDayjs = (langName) => {
|
||||||
langName = langName.replace('_', '-').toLowerCase();
|
langName = langName.replace('_', '-').toLowerCase();
|
||||||
|
@ -12,12 +13,13 @@ const localDayjs = (langName) => {
|
||||||
export const getCurrentLang = () => {
|
export const getCurrentLang = () => {
|
||||||
const loggedUser = loggedUserInfoStore.getState().user;
|
const loggedUser = loggedUserInfoStore.getState().user;
|
||||||
const adminInterface = interfaceStore.getState().interface;
|
const adminInterface = interfaceStore.getState().interface;
|
||||||
|
const storageLang = Storage.get(CURRENT_LANG_STORAGE_KEY);
|
||||||
let currentLang = loggedUser.language;
|
let currentLang = loggedUser.language;
|
||||||
// `default` mean use language value from admin interface
|
// `default` mean use language value from admin interface
|
||||||
if (/default/i.test(currentLang) && adminInterface.language) {
|
if (/default/i.test(currentLang) && adminInterface.language) {
|
||||||
currentLang = adminInterface.language;
|
currentLang = adminInterface.language;
|
||||||
}
|
}
|
||||||
currentLang ||= DEFAULT_LANG;
|
currentLang ||= storageLang || DEFAULT_LANG;
|
||||||
return currentLang;
|
return currentLang;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue