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

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

Merged
merged 8 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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';
export const fgHeaderName = 'X-Adobe-Floodgate';
Expand Down Expand Up @@ -273,10 +274,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',
});
});
});
Expand Down
24 changes: 18 additions & 6 deletions tools/send-to-caas/send-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ 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' },
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 @@ -30,27 +36,34 @@ 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' },
mena_fr: { ietf: 'fr-mena' },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted as mena_fr isn't supported when rolled out and to keep parity with the 93 values supported by Milo's getLocale() api

ng: { ietf: 'en-NG' },
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 @@ -68,9 +81,9 @@ 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 @@ -366,8 +379,7 @@ const getBulkPublishLangAttr = async (options) => {
const getCountryAndLang = async (options) => {
const langStr = window.location.pathname === '/tools/send-to-caas/bulkpublisher.html'
? await getBulkPublishLangAttr(options)
: document.documentElement.lang;

: (LOCALES[window.location.pathname.split('/')[1]] || LOCALES['']).ietf;
const langAttr = langStr?.toLowerCase().split('-') || [];

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