Skip to content

Commit

Permalink
MWPW-131707 Get correct region for caas autolang (#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischrischris authored Jul 26, 2023
1 parent 99f2b38 commit b5658ae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 3 additions & 4 deletions libs/blocks/caas/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,10 @@ const getFilterArray = async (state, country, lang) => {

export function getCountryAndLang({ autoCountryLang, country, language }) {
if (autoCountryLang) {
const htmlLang = pageConfigHelper()?.locale?.ietf?.toLowerCase() || 'en-us';
const [lang, cntry] = htmlLang.split('-');
const locale = pageConfigHelper()?.locale;
return {
country: cntry,
language: lang,
country: locale.region?.toLowerCase() || 'us',
language: locale.ietf?.toLowerCase() || 'en-us',
};
}
return {
Expand Down
4 changes: 3 additions & 1 deletion libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ export function getLocale(locales, pathname = window.location.pathname) {
locale.prefix = `/${localeString}/${split[2]}`;
return locale;
}
locale.prefix = locale.ietf === 'en-US' ? '' : `/${localeString}`;
const isUS = locale.ietf === 'en-US';
locale.prefix = isUS ? '' : `/${localeString}`;
locale.region = isUS ? 'us' : localeString.split('_')[0];
return locale;
}

Expand Down
4 changes: 2 additions & 2 deletions test/blocks/caas/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ describe('getCountryAndLang', () => {
});
expect(expected).to.deep.eq({
country: 'be',
language: 'fr',
language: 'fr-be',
});
});

Expand All @@ -580,7 +580,7 @@ describe('getCountryAndLang', () => {
});
expect(expected).to.deep.eq({
country: 'us',
language: 'en',
language: 'en-us',
});
});
});

0 comments on commit b5658ae

Please sign in to comment.