Build multiple language website using jQuery and JSON based methods

后端 未结 3 1453
太阳男子
太阳男子 2021-01-05 21:57

I\'m trying to implement a Multi-language for one website. I prefer to use client script for changing the language between English and Tr

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 22:33

    You can save the selected language on cookie.

    You can use on setting and getting cookie.

    function setCookie(name,value,days) {
        var expires = "";
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days*24*60*60*1000));
            expires = "; expires=" + date.toUTCString();
        }
        document.cookie = name + "=" + (value || "")  + expires + "; path=/";
    }
    function getCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }
    

    Source

    Here is your updated fiddle: https://jsfiddle.net/20zo4wg8/1/

提交回复
热议问题