Skip to content

Commit

Permalink
Taking changes from PR:1323 and merging into here (as requested)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanrai committed Sep 23, 2023
1 parent 9391cc6 commit df57736
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions libs/blocks/caas/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-underscore-dangle */
import { loadScript, loadStyle, getConfig as pageConfigHelper } from '../../utils/utils.js';
import { fetchWithTimeout } from '../utils/utils.js';
import { LOCALES } from '../../../tools/send-to-caas/send-utils.js';

const URL_ENCODED_COMMA = '%2C';

Expand Down Expand Up @@ -261,10 +262,14 @@ const getFilterArray = async (state, country, lang, strs) => {

export function getCountryAndLang({ autoCountryLang, country, language }) {
if (autoCountryLang) {
const locale = pageConfigHelper()?.locale;
const prefix = pageConfigHelper()?.locale?.prefix?.replace('/', '') || '';
const locale = LOCALES[prefix]?.ietf || 'en-us';
/* eslint-disable-next-line prefer-const */
let [currLang, currCountry] = locale.split('-');

return {
country: locale.region?.toLowerCase() || 'us',
language: locale.ietf?.toLowerCase() || 'en-us',
country: currCountry,
language: currLang,
};
}
return {
Expand Down
8 changes: 4 additions & 4 deletions test/blocks/caas/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ describe('getCountryAndLang', () => {
autoCountryLang: true,
});
expect(expected).to.deep.eq({
country: 'be',
language: 'fr-be',
country: 'BE',
language: 'fr',
});
});

Expand All @@ -592,8 +592,8 @@ describe('getCountryAndLang', () => {
autoCountryLang: true,
});
expect(expected).to.deep.eq({
country: 'us',
language: 'en-us',
country: 'US',
language: 'en',
});
});
});
2 changes: 1 addition & 1 deletion tools/send-to-caas/send-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const VALID_URL_RE = /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-
const isKeyValPair = /(\s*\S+\s*:\s*\S+\s*)/;
const isValidUrl = (u) => VALID_URL_RE.test(u);

const LOCALES = {
export const LOCALES = {
// Americas
ar: { ietf: 'es-AR' },
br: { ietf: 'pt-BR' },
Expand Down

0 comments on commit df57736

Please sign in to comment.