Skip to content

Commit

Permalink
Revert "MWPW-136766, MWPW-136143: Milo not supporting sending to CaaS… (
Browse files Browse the repository at this point in the history
#1427)

Revert "MWPW-136766, MWPW-136143: Milo not supporting sending to CaaS all locales & Autodetect not working (#1324)"

This reverts commit ef0d26a.
  • Loading branch information
sanrai authored Oct 17, 2023
1 parent ef0d26a commit d87b8a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
11 changes: 3 additions & 8 deletions libs/blocks/caas/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* 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';
export const fgHeaderName = 'X-Adobe-Floodgate';
Expand Down Expand Up @@ -274,14 +273,10 @@ const getFilterArray = async (state, country, lang, strs) => {

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

const locale = pageConfigHelper()?.locale;
return {
country: currCountry,
language: currLang,
country: locale.region?.toLowerCase() || 'us',
language: locale.ietf?.toLowerCase() || 'en-us',
};
}
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',
country: 'be',
language: 'fr-be',
});
});

Expand All @@ -592,8 +592,8 @@ describe('getCountryAndLang', () => {
autoCountryLang: true,
});
expect(expected).to.deep.eq({
country: 'US',
language: 'en',
country: 'us',
language: 'en-us',
});
});
});
Expand Down
24 changes: 6 additions & 18 deletions tools/send-to-caas/send-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,18 @@ 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);

export const LOCALES = {
const LOCALES = {
// Americas
ar: { ietf: 'es-AR' },
br: { ietf: 'pt-BR' },
ca: { ietf: 'en-CA' },
ca_fr: { ietf: 'fr-CA' },
cl: { ietf: 'es-CL' },
co: { ietf: 'es-CO' },
cr: { ietf: 'es-CR' },
ec: { ietf: 'es-EC' },
el: { ietf: 'es-EL' },
gt: { ietf: 'es-GT' },
la: { ietf: 'es-LA' },
mx: { ietf: 'es-MX' },
pe: { ietf: 'es-PE' },
pr: { ietf: 'es-PR' },
'': { ietf: 'en-US' },
langstore: { ietf: 'en-US' },
// EMEA
africa: { ietf: 'en-africa' },
be_fr: { ietf: 'fr-BE' },
Expand All @@ -36,34 +30,27 @@ export const LOCALES = {
dk: { ietf: 'da-DK' },
de: { ietf: 'de-DE' },
ee: { ietf: 'et-EE' },
eg_ar: { ietf: 'ar-EG' },
eg_en: { ietf: 'en-GB' },
es: { ietf: 'es-ES' },
fr: { ietf: 'fr-FR' },
gr_en: { ietf: 'en-GR' },
gr_el: { ietf: 'el-GR' },
ie: { ietf: 'en-IE' },
il_en: { ietf: 'en-IL' },
il_he: { ietf: 'he-il' },
it: { ietf: 'it-IT' },
kw_ar: { ietf: 'ar-KW' },
kw_en: { ietf: 'en-GB' },
lv: { ietf: 'lv-LV' },
lt: { ietf: 'lt-LT' },
lu_de: { ietf: 'de-LU' },
lu_en: { ietf: 'en-LU' },
lu_fr: { ietf: 'fr-LU' },
hu: { ietf: 'hu-HU' },
mt: { ietf: 'en-MT' },
mena: { ietf: 'en-mena' },
mena_en: { ietf: 'en-mena' },
mena_ar: { ietf: 'ar-mena' },
ng: { ietf: 'en-NG' },
mena_fr: { ietf: 'fr-mena' },
nl: { ietf: 'nl-NL' },
no: { ietf: 'no-NO' },
pl: { ietf: 'pl-PL' },
pt: { ietf: 'pt-PT' },
qa_ar: { ietf: 'ar-QA' },
qa_en: { ietf: 'en-GB' },
ro: { ietf: 'ro-RO' },
sa_en: { ietf: 'en-sa' },
ch_fr: { ietf: 'fr-CH' },
Expand All @@ -81,9 +68,9 @@ export const LOCALES = {
bg: { ietf: 'bg-BG' },
ru: { ietf: 'ru-RU' },
ua: { ietf: 'uk-UA' },
il_he: { ietf: 'he-il' },
ae_ar: { ietf: 'ar-ae' },
sa_ar: { ietf: 'ar-sa' },
za: { ietf: 'en-ZA' },
// Asia Pacific
au: { ietf: 'en-AU' },
hk_en: { ietf: 'en-HK' },
Expand Down Expand Up @@ -379,7 +366,8 @@ const getBulkPublishLangAttr = async (options) => {
const getCountryAndLang = async (options) => {
const langStr = window.location.pathname === '/tools/send-to-caas/bulkpublisher.html'
? await getBulkPublishLangAttr(options)
: (LOCALES[window.location.pathname.split('/')[1]] || LOCALES['']).ietf;
: document.documentElement.lang;

const langAttr = langStr?.toLowerCase().split('-') || [];

const [lang = 'en', country = 'us'] = langAttr;
Expand Down

0 comments on commit d87b8a5

Please sign in to comment.