1

I have a dynamic multilanguage website. My php echos the current language right, but javascript doesn't even if loading after body.

My php:

<?php echo $language ?>

This gives me english, portuguese, german or french accordingly to the one is being used.

when i try with javascript this way:

    <script type="text/javascript">
    function language() {
        var ci = {
            language : "<?php echo $language; ?>"
        };
        if(ci.language = 'portuguese') {
            alert(ci.language);
            return false;
            fb_language = "pt_PT";
        } else if (ci.language = 'english') {
            alert(ci.language);
            return false;
            fb_language = "en_US";
        } else if (ci.language = 'german') {
            alert(ci.language);
            return false;
            fb_language = "de_DE";
        } else if (ci.language = 'french') {
            alert(ci.language);
            return false;
            fb_language = "fr_FR";
        } else {
            fb_language = "en_US";
        }
    };
    </script>

<body onload="language();">

It always gives me portuguese in javascript, can't make it alert the right language, but in php it gives me the right language im using.

4

2 回答 2

5

这个:

if(ci.language = 'portuguese') {

应该:

if(ci.language === 'portuguese') {

在其他if陈述中依此类推。

于 2012-11-14T11:27:25.443 回答
1

用作: ci.language == 'portuguese'代替ci.language = 'portuguese'

于 2012-11-14T11:27:43.073 回答