I am working on an Angular application and I am using OneTrust for cookie consent management. The issue I am facing currently is that although rest of the components of the login page are translated properly into the target language the OneTrust cookie banner isn't translated and remains in english language.
Here's my function handling OneTrust Cookie Banner written in TypeScript:
loadingOneTrustCookieJavaScript()
{
let OTjs = document.createElement('script') as HTMLScriptElement;
OTjs.src = "https://cdn.cookielaw.org/scripttemplates/otSDKStub.js";
OTjs.type = "text/javascript";
OTjs.charset = "UTF-8";
OTjs.setAttribute("data-domain-script". environment.OneTrustKey);
OTjs.setArrtibute("data-document-language", true);
let OTfn = document.createElement('script') as HTMLScriptElement;
OTfn.type = "text/javascript";
OTfn.textContent = "function OptanonWrapper(){ }"'
head.appendChild(OTjs);
head.appendChild(OTfn);
}
You need to select required languages in Onetrust cookie template. https://my.onetrust.com/articles/en_US/Knowledge/UUID-2b6cc670-059c-5342-275c-4a7d8da5630e#:~:text=To%20manage%20Banner%20languages
Make sure the declared document language matches the actual language.
You can check it by typing in the console: document.documentElement.lang
Or you can enforce the language of cookie banner by using data-language="fr"
attribute instead of data-document-language=true
.