Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use system language by default #394

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions map/src/manager/AccountManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { apiGet, apiPost } from '../util/HttpApi';
import i18n from '../i18n';

export const LOGIN_LOGOUT_URL = '/map/loginForm#logout'; // lose window.location.search/window.location.hash

Expand Down Expand Up @@ -40,6 +41,7 @@ async function userLogin({ ctx, username, pwd, setEmailError, handleClose, lang
body: JSON.stringify({ username: username.toLowerCase(), password: pwd, lang }),
});
if (await isRequestOk(response, setEmailError)) {
await resetLanguage();
setEmailError('');
ctx.setLoginUser(username);
ctx.setEmailCookie(username, { days: 30, SameSite: 'Strict' }); // for next login
Expand All @@ -54,6 +56,7 @@ async function userLogout({ ctx, username, setEmailError, handleClose, setState,
body: JSON.stringify({ username: username.toLowerCase(), lang }),
});
if (await isRequestOk(response, setEmailError)) {
await resetLanguage();
setState('login');
ctx.setLoginUser('');
setEmailError('');
Expand Down Expand Up @@ -167,6 +170,11 @@ async function changeEmail({ email, token, setEmailError, lang = DEFAULT_AUTH_AP
}
}

async function resetLanguage() {
localStorage.removeItem('i18nextLng');
await i18n.changeLanguage(navigator.language);
}

const AccountManager = {
deleteAccount,
userRegister,
Expand Down
18 changes: 18 additions & 0 deletions map/src/menu/settings/SettingsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ export default function SettingsMenu({ setCloudSettings }) {
const transB = getTransLanguage(b);
return collator.compare(transA, transB);
});
res.push(
<MenuItem
key={'device_language'}
onClick={async () => {
await i18n.changeLanguage(navigator.language).then(() => {
setCurrentLang(t(`lang_${i18n.language}`));
});
setOpenLangList(false);
ctx.setOpenedPopper(null);
}}
>
<ListItemText>
<Typography variant="inherit" noWrap>
{`${t('system_locale')} (${t(`lang_${navigator.language}`)})`}
</Typography>
</ListItemText>
</MenuItem>
);
sortedLangList.map((lang, index) => {
const transLang = getTransLanguage(lang);
if (transLang) {
Expand Down
3 changes: 2 additions & 1 deletion map/src/resources/translations/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -5205,5 +5205,6 @@
"shared_string_modified": "Modified",
"shared_string_added": "Added",
"shared_string_deleted": "Deleted",
"shared_string_changes": "Changes"
"shared_string_changes": "Changes",
"system_locale": "System"
}