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

DEX-19810 fixed html lang attribute #284

Merged
merged 3 commits into from
Oct 8, 2024
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
19 changes: 3 additions & 16 deletions _src/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
import {
adobeMcAppendVisitorId,
createTag,
getDefaultLanguage,
getParamValue,
GLOBAL_EVENTS, pushToDataLayer, pushTrialDownloadToDataLayer,
getLocale,
Expand All @@ -26,8 +25,6 @@ import {
const LCP_BLOCKS = ['hero']; // add your LCP blocks to the list

export const SUPPORTED_LANGUAGES = ['en'];
export const DEFAULT_LANGUAGE = getDefaultLanguage();
export const DEFAULT_COUNTRY = getDefaultLanguage();
export const METADATA_ANALYTICS_TAGS = 'analytics-tags';
const TARGET_TENANT = 'bitdefender';

Expand Down Expand Up @@ -65,9 +62,10 @@ export function createMetadata(name, value) {
}

export function getLanguageCountryFromPath() {
const currentPathUrl = window.location.pathname;
return {
language: DEFAULT_LANGUAGE,
country: DEFAULT_COUNTRY,
language: currentPathUrl.split('/')[1].split('-')[0],
country: currentPathUrl.split('/')[1].split('-')[1],
};
}

Expand Down Expand Up @@ -186,16 +184,6 @@ export function getLocalizedResourceUrl(resourceName) {
return `${pathnameAsArray.join('/')}/${resourceName}`;
}

/**
* Sets the page language.
* @param {Object} param The language and country
*/
function setPageLanguage(param) {
document.documentElement.lang = param.language;
createMetadata('nav', `${getLocalizedResourceUrl('nav')}`);
createMetadata('footer', `${getLocalizedResourceUrl('footer')}`);
}

export function getTags(tags) {
return tags ? tags.split(':').filter((tag) => !!tag).map((tag) => tag.trim()) : [];
}
Expand Down Expand Up @@ -537,7 +525,6 @@ function pushPageLoadToDataLayer(targetExperimentDetails) {
* @param {Element} doc The container element
*/
async function loadEager(doc) {
setPageLanguage(getLanguageCountryFromPath(window.location.pathname));
decorateTemplateAndTheme();

await window.hlx.plugins.run('loadEager');
Expand Down
30 changes: 0 additions & 30 deletions _src/scripts/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,8 @@ export function getParamValue(param) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
}
export const localisationList = ['zh-hk', 'zh-tw', 'en-us', 'de-de', 'nl-nl', 'fr-fr', 'it-it', 'ro-ro'];
export function getDefaultLanguage() {
// TODO: refactor. It's not working as should for en locales.
const currentPathUrl = window.location.pathname;
const foundLanguage = localisationList.find((item) => currentPathUrl.indexOf(`/${item}/`) !== -1);
let lang = 'site';

if (foundLanguage) {
if (foundLanguage.startsWith('zh-') || foundLanguage.startsWith('en-')) {
lang = foundLanguage.replace('zh-', '').replace('en-', '') || 'site';
} else {
[, lang] = foundLanguage.split('-');
}
}

return lang;
}

const cacheResponse = new Map();
const siteName = getDefaultLanguage();

// eslint-disable-next-line import/prefer-default-export
export function createTag(tag, attributes, html) {
Expand Down Expand Up @@ -415,18 +397,6 @@ export async function fetchProduct(code = 'av', variant = '1u-1y', pid = null) {
data.set('data', JSON.stringify(newData));
}

if (siteName === 'uk') {
const newData = JSON.parse(data.get('data'));
newData.config.force_region = '3';
data.set('data', JSON.stringify(newData));
}

if (siteName === 'fr') {
const newData = JSON.parse(data.get('data'));
newData.config.force_region = '14';
data.set('data', JSON.stringify(newData));
}

const currentPriceSetup = PRICE_LOCALE_MAP.get(locale) || 'en-us';
const newData = JSON.parse(data.get('data'));
FETCH_URL = `${FETCH_URL}?force_country=${currentPriceSetup.force_country}`;
Expand Down
Loading