Can I change content loaded by Disqus using JavaScript

42 Views Asked by At

I wanna translate text generated by Disqus through the JS. Because Disqus didn't translate all content to my language(Kazakh)

HTML-page with 3 options to select the language(In picture Kazakh language is selected, but not all words translating)

This is language selector

<form class="langform" action="/i18n/setlang/" method="POST">
<input type="hidden" name="csrfmiddlewaretoken" value="RpNWxn373QncBYC7djkBAdb8vE1dv4MMP2WFpv6QtJNbPJjoRVCXn5rXwcMRJE2X">
<input name="next" type="hidden" value="">
<select class="form-control form-control-sm formlang" name="language" onchange="this.form.submit()">
    <option value="ru">Русский</option>
    <option value="en">English</option>
    <option value="kk" selected>Қазақ</option>
</select>

This is how I change Disqus language

langsel = document.getElementsByClassName('formlang')[0];
idx = langsel.selectedIndex;
var disqus_config = function () {
    if(idx==2){
        this.language = "kk";
        //document.getElementById('no-posts').innerHTML = '(my translation to kazakh text)'
        //stuff like this not working
    }
    else if(idx==1){
        this.language="en"
    }
    else{
        this.language="ru"
    }
    
    this.page.url = "{{ request.build_absolute_url }}"
    this.page.identifier = "{{url}}"; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};

I can't access to HTML-elements generated by Disqus, to manually translate words that not translated by Disqus. When I'm trying to set .innerHTML property to the not translated text, I get 'Cannot set properties of NULL' error. I used window.onload and setTimeout functions, but these stuffs also not working. Disqus have a project on Transifex, where all translations are saved. Even if I publish my translation there, checking and publishing the translation on the Disqus system takes a very long time.

0

There are 0 best solutions below