diff --git a/extractOptionsFromScript.js b/extractOptionsFromScript.js index 9c025c9..1aa6120 100644 --- a/extractOptionsFromScript.js +++ b/extractOptionsFromScript.js @@ -203,8 +203,10 @@ function extractOptionsFromScript(window, optsArgs = { const alternateLinkTag = window.document.createElement('link'); alternateLinkTag.setAttribute('rel', 'alternate'); alternateLinkTag.setAttribute('hreflang', originalLang); - // append prefix to the original lang because the subdomain will be accessed without the prefix - alternateLinkTag.href = `${window.location.protocol}//${domain}${getPrefixedPathname(window, domainSourcePrefix, window.location.pathname)}`; + + const subdirectoryHref = `${window.location.protocol}//${domain}${getUnprefixedPathname(window, domainSourcePrefix, window.location.pathname)}` + // append prefix to the original lang because the subdomain will be accessed without the prefix (dont append if subdirectory mode) + alternateLinkTag.href = translationMode == "subdirectory" ? subdirectoryHref : `${window.location.protocol}//${domain}${getPrefixedPathname(window, domainSourcePrefix, window.location.pathname)}`; window.document.head.appendChild(alternateLinkTag); // Add alternate link tags for allowed languages diff --git a/utils/selector/createLanguageSelect.js b/utils/selector/createLanguageSelect.js index 26027d7..04cf46a 100644 --- a/utils/selector/createLanguageSelect.js +++ b/utils/selector/createLanguageSelect.js @@ -375,6 +375,15 @@ async function createLanguageSelect(window, optsArgs = {}) { } } + if (prefix && options.translationMode == "subdirectory") { + newUrl.pathname = getUnprefixedPathname(window, prefix, newUrl.pathname); + // if (options.originalLanguage == language.lang) { + // newUrl.pathname = getUnprefixedPathname(window, prefix, newUrl.pathname); + // } else { + // newUrl.pathname = getUnprefixedPathname(window, prefix, newUrl.pathname); + // } + } + const url = isSelected ? "#" : addOrReplaceLangParam(window, newUrl.href, language.lang); a.href = url;