Forum Replies Created

Viewing 1 replies (of 1 total)
  • Forum: Plugins
    In reply to: A bilingual blog solution

    3 languages support:
    =============================== language.js =======================
    window.onload, createCookie() and readCookie() are the same as they were. Here is the relevant code: (excuse the length)


    function language(lang_on, lang_off, lang_offf) {
    createCookie("langue_on",lang_on,365);
    createCookie("langue_off",lang_off,365);
    /* aalex aded 1 line here */
    createCookie("langue_offf",lang_offf,365);
    for (var i=0; i<document.getElementsByTagName("div").length; i++ ) {
    if (document.getElementsByTagName("div")[i].lang == lang_on) {
    document.getElementsByTagName("div")[i].style.display="block";
    }
    if (document.getElementsByTagName("div")[i].lang == lang_off) {
    document.getElementsByTagName("div")[i].style.display="none";
    }
    /* aalex added 3 lines here */
    if (document.getElementsByTagName("div")[i].lang == lang_offf) {
    document.getElementsByTagName("div")[i].style.display="none";
    }
    }
    /* aalex added 11 lines here */
    for (var i=0; i<document.getElementsByTagName("span").length; i++ ) {
    if (document.getElementsByTagName("span")[i].lang == lang_on) {
    document.getElementsByTagName("span")[i].style.display="block";
    }
    if (document.getElementsByTagName("span")[i].lang == lang_off) {
    document.getElementsByTagName("span")[i].style.display="none";
    }
    /* aalex also added 3 lines here */
    if (document.getElementsByTagName("span")[i].lang == lang_offf) {
    document.getElementsByTagName("span")[i].style.display="none";
    }
    }
    }

    function startlanguage() {
    var notdefined;
    var lang_on = readCookie("langue_on");
    var lang_off = readCookie("langue_off");
    var lang_offf = readCookie("langue_offf");
    if (lang_on == notdefined) {
    lang_on = "en";
    }
    if (lang_off == notdefined) {
    lang_off = "de";
    }
    if (lang_offf == notdefined) {
    lang_offf = "fr";
    }
    language(lang_on,lang_off, lang_offf);
    }

    ============================ language.html (to be put in the template)============

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "https://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <title>A bilingual blog solution &laquo; WordPress Support</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!-- fix the FOUC -->
    <script type="text/javascript" src="language.js"> </script>

    </head>

    <body>
    <a href="javascript:language('fr', 'en', 'de');">Fr</a>
    <a href="javascript:language('en', 'fr', 'de');">En</a>
    <a href="javascript:language('de', 'en', 'fr');">De</a>

    <div lang="de">Deutsh</div>
    <div lang="fr">Francais</div>
    <div lang="en">English</div>
    <div>
    <span lang="de">Deutsh</span>
    <span lang="fr">Francais</span>
    <span lang="en">English</span>
    </div>
    </body>
    </html>

    ================================================================
    It would be nice to put the “off” languages in an array, and all the tags (div, span…) in an array too for the loop. Can somoeone do that ? Then, no more copy-paste code and we got our tool !!

    aalex

Viewing 1 replies (of 1 total)