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

thisyahlen/fix: login change language error #7963

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Text, Icon, Counter } from '@deriv/components';
import { BinaryLink } from '../../Routes';
import { observer, useStore } from '@deriv/stores';
Expand Down Expand Up @@ -81,16 +82,16 @@ const CashierTab = observer(() => {
});

const MenuLinks = observer(() => {
const { client, common, ui } = useStore();
const { i18n } = useTranslation();
const { client, ui } = useStore();
const { is_logged_in } = client;
const { current_language } = common;
const { is_mobile } = ui;
const is_traders_hub = window.location.pathname === routes.traders_hub;

if (!is_logged_in) return <></>;

return (
<div key={`menu-links__${current_language}`} className='header__menu-links'>
<div key={`menu-links__${i18n.language}`} className='header__menu-links'>
{!is_traders_hub && <ReportTab />}
{!is_mobile && <CashierTab />}
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,7 @@ export default class ClientStore extends BaseStore {
const language = authorize_response.authorize.preferred_language;
if (language !== 'EN' && language !== LocalStore.get(LANGUAGE_KEY)) {
window.history.replaceState({}, document.title, urlForLanguage(language));
await this.root_store.common.changeSelectedLanguage(language);
}
if (this.citizen) this.onSetCitizen(this.citizen);
if (!this.is_virtual) {
Expand Down
38 changes: 23 additions & 15 deletions packages/core/src/Stores/common-store.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as SocketCache from '_common/base/socket_cache';
import { reject } from 'lodash';

import { action, computed, makeObservable, observable } from 'mobx';
import { changeLanguage, getAllowedLanguages } from '@deriv/translations';
Expand Down Expand Up @@ -114,26 +115,33 @@ export default class CommonStore extends BaseStore {
}
}

changeSelectedLanguage = key => {
changeSelectedLanguage = async key => {
SocketCache.clear();
if (key === 'EN') {
window.localStorage.setItem('i18n_language', key);
}

WS.setSettings({
set_settings: 1,
preferred_language: key,
}).then(() => {
const new_url = new URL(window.location.href);
if (key === 'EN') {
new_url.searchParams.delete('lang');
} else {
new_url.searchParams.set('lang', key);
}
window.history.pushState({ path: new_url.toString() }, '', new_url.toString());
changeLanguage(key, () => {