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

chore: fix language not correct when redirect from deriv-com #9632

Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 7 additions & 6 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { RudderStack } from '@deriv/analytics';
import { WS, requestLogout } from 'Services';
import { action, computed, makeObservable, observable, reaction, runInAction, toJS, when } from 'mobx';
import { getAccountTitle, getClientAccountType, getAvailableAccount } from './Helpers/client';
import { getLanguage, localize } from '@deriv/translations';
import { getLanguage, localize, getRedirectionLanguage } from '@deriv/translations';
import { getRegion, isEuCountry, isMultipliersOnly, isOptionsBlocked } from '_common/utility';

import BaseStore from './base-store';
Expand All @@ -40,7 +40,6 @@ import moment from 'moment';
import { setDeviceDataCookie } from './Helpers/device';

const LANGUAGE_KEY = 'i18n_language';
const DEFAULT_LANGUAGE = 'EN';
const storage_key = 'client.accounts';
const store_name = 'client_store';
const eu_shortcode_regex = new RegExp('^(maltainvest|malta|iom)$');
Expand Down Expand Up @@ -429,9 +428,11 @@ export default class ClientStore extends BaseStore {
reaction(
() => [this.account_settings],
() => {
const lang_from_url = new URLSearchParams(window.location.search).get('lang') || DEFAULT_LANGUAGE;
this.setPreferredLanguage(lang_from_url);
LocalStore.set(LANGUAGE_KEY, lang_from_url);
const language = getRedirectionLanguage(this.account_settings.preferred_language);
suisin-deriv marked this conversation as resolved.
Show resolved Hide resolved
window.history.replaceState({}, document.title, urlForLanguage(language));

this.setPreferredLanguage(language);
LocalStore.set(LANGUAGE_KEY, language);
}
);

Expand Down Expand Up @@ -1683,7 +1684,7 @@ export default class ClientStore extends BaseStore {
runInAction(() => {
this.is_populating_account_list = false;
});
const language = authorize_response.authorize.preferred_language;
const language = getRedirectionLanguage(authorize_response.authorize.preferred_language);
const stored_language = LocalStore.get(LANGUAGE_KEY);
if (language !== 'EN' && stored_language && language !== stored_language) {
window.history.replaceState({}, document.title, urlForLanguage(language));
Expand Down
6 changes: 6 additions & 0 deletions packages/translations/src/i18next/i18next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ const isLanguageAvailable = (lang: string) => {
return Object.keys(getAllowedLanguages()).includes(selected_language);
};

export const getRedirectionLanguage = (preferred_language: string) => {
const language_query = new URLSearchParams(window.location.search).get('lang');
const is_language_query_valid = language_query && isLanguageAvailable(language_query);
return is_language_query_valid ? language_query : preferred_language ?? DEFAULT_LANGUAGE;
};

export const getAllLanguages = () => ALL_LANGUAGES;

export const getInitialLanguage = () => {
Expand Down