PHP Simple implementation of multi-language switching method, PHP language switch
In this paper, a simple way to implement multi-language switching is described. Share to everyone for your reference, as follows:
1. Main program code:
<?phpinclude "lib/function.php";? ><?phpif (Isset ($_get["language"])) { $_session["language"] = $_get["language"];} else{ $_session["language"] = Getdefalutlanguage ();} $language _name = getlanguagename ($_session["language"]), include "lang/". $language _name. ". Inc ";? ><?php $language _array = Array_language (); foreach ($language _array as $key + $value) { if ($_session["language"] = = $value) { $selected = ' selected = ' Selected ' "; } else{ $selected = ""; }? ><?php echo="" $selected;?="">><?php Echo Getlanguagename ($value);? >;<? }? >
<?php if ($_get["language"] = = $value) { //$selected = "selected = ' selected '"; } echo "Language:". $_session["Language"];echo "test:". $name;? >
2. Included Language pack: English.inc
<?php$name = "Name";? >chinese.inc<?php$name = "Name";? >
3. The included function.php
<?php function Getvailablelanguage () {$language = array (' af ' = ' Afrikaans ', ' az ' = ' azer Baijani ', ' eu ' = ' Basque ', ' be ' = ' Belarusian ', ' Be-lat ' + ' Belarusian Latin ', ' BG ' = ' Bulgarian ', ' bs ' = ' Bosnian ', ' ca ' = ' Catalan ', ' zh ' = ' Chinese ', ' ZH-TW ' = ' Chinese Traditional ',//' zh-cn ' = ' Chinese Simplified ', ' cs ' = ' Czech ', ' Da ' = ' Danish ', ' de ' = ' German ', ' el ' = ' Greek ', ' en ' = ' 中文版 ', ' Es ' = ' Spanish ', ' et ' = ' Estonian ', ' fa ' = ' Persian ', ' fi ' = ' Finnish ', ' fr ' = ' French ', ' gl ' = ' Galician ', ' he ' = ' Hebrew ', ' hi ' = ' Hindi ', ' hr ' = ' Croatian ', ' hu ' = ' Hungarian ', ' id ' = ' Indonesian ', ' it ' = ' it ' Alian ', ' ja ' =&Gt ' Japanese ', ' ko ' = ' Korean ', ' ka ' = ' Georgian ', ' lt ' = ' Lithuanian ', ' LV ' = ' Latvian ', ' mk ' = ' Macedonian ', ' mn ' = ' Mongolian ', ' ms ' = ' Malay ', ' NL ' = ' Dutch ', ' no ' = ' Norwegian ', ' pl ' = ' Polish ', ' pt-br ' + ' Brazilian Portug Uese ', ' pt ' = ' Portuguese ', ' ro ' = ' Romanian ', ' ru ' = ' Russian ', ' Si ' => ; ' Sinhala ', ' sk ' = ' Slovak ', ' sl ' = ' Slovenian ', ' sq ' = ' Albanian ', ' Sr-lat ' = ' Serbian Latin ', ' sr ' = ' Serbian ', ' sv ' = ' Swedish ', ' th ' = ' Thai ', ' tr ' = ' Turkish ', ' tt ' = ' tatarish ', ' uk ' = ' Ukrainian ',); return $language; } function Getlanguagename ($language) {$languages = Getvailablelanguage (); return $languages [$language]; } function Array_language () {$arrAy_language = Array ("En", "zh"); return $array _language; } function Getdefalutlanguage () {return "zh";}? >
4. The included Language.js
function Changelanguage (obj) { var url = document. URL; var re = re =/[?&]language=[^&]*/; url = url.replace (Re, ""); if (Url.indexof ("?") >-1) { URL + = "&language=" + obj.value; } else { URL + = "? language=" + Obj.value; } location.href = URL;}
More about PHP related content readers can view the topic: "PHP array" operation Skills Daquan, "PHP Data structure and algorithm tutorial", "PHP Math Skills Summary", "PHP date and Time usage summary", "PHP object-oriented Programming introduction Tutorial", " PHP String Usage Summary, "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"
I hope this article is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1126070.html www.bkjia.com true http://www.bkjia.com/PHPjc/1126070.html techarticle PHP Simple implementation of multi-language switching method, PHP language switch This article describes the PHP simple implementation of multi-language switching method. Share to everyone for your reference, as follows: 1. Main program Generation ...