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

fix(tarteaucitron.js): adds a conditionnal for empty lang attribute #1264

Conversation

liorchamla
Copy link

@liorchamla liorchamla commented Jul 19, 2024

So when the lang attribute is empty : <html lang>, the getLanguage method is not able to see it and goes in the conditionnal :

if (document.documentElement.getAttribute("lang") !== undefined && document.documentElement.getAttribute("lang") !== null) {
    if (availableLanguages.indexOf(document.documentElement.getAttribute("lang").substr(0, 2)) !== -1) {
        return document.documentElement.getAttribute("lang").substr(0, 2);
    }
}

And it returns ... "" so the lang script does not load :'(

This PR fixes this behavior.

@liorchamla liorchamla changed the title fix(tarteaucitron.js): adds a conditionnal to discard lang attribute … fix(tarteaucitron.js): adds a conditionnal for empty lang attribute Jul 19, 2024
@AmauriC
Copy link
Owner

AmauriC commented Jul 19, 2024

Nice catch, thanks! 😎

Just need to fix an issue, it's document.documentElement.getAttribute("lang") !== "", the document. is missing.

I release this on Monday if ready.

@@ -2077,7 +2077,7 @@ var tarteaucitron = {
}

// get the html lang
if (document.documentElement.getAttribute("lang") !== undefined && document.documentElement.getAttribute("lang") !== null) {
if (document.documentElement.getAttribute("lang") !== undefined && document.documentElement.getAttribute("lang") !== null && documentElement.getAttribute("lang") !== "") {
Copy link
Owner

Choose a reason for hiding this comment

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

Missing document.

documentElement.getAttribute return ReferenceError: Can't find variable: documentElement

Copy link
Author

Choose a reason for hiding this comment

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

My bad ! bad copy / paste :'(

@AmauriC AmauriC merged commit bc1f1ae into AmauriC:master Aug 9, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants