這篇文章將為大家詳細(xì)講解有關(guān)使用php怎么實(shí)現(xiàn)一個(gè)多語(yǔ)言切換功能,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
創(chuàng)新互聯(lián)公司自2013年創(chuàng)立以來(lái),先為魯山等服務(wù)建站,魯山等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為魯山企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。1.主程序代碼:
<?php include "lib/function.php"; ?> <script src="js/language.js"></script> <?php if(isset($_GET["language"])){ $_SESSION["language"] = $_GET["language"]; }else{ $_SESSION["language"] = getDefalutlanguage(); } $language_name = getLanguageName($_SESSION["language"]); include "lang/".$language_name.".inc"; ?> <SELECT NAME="language" id="language" onchange="changeLanguage(this)"> <?php $language_array = array_language(); foreach($language_array as $key => $value){ if($_SESSION["language"] == $value){ $selected = "selected = 'selected' "; }else{ $selected = ""; } ?> <OPTION VALUE="<?php echo $value;?>" <?php echo $selected;?>><?php echo getLanguageName($value);?></OPTION>; <? } ?> </SELECT> <?php if($_GET["language"] == $value){ //$selected = "selected = 'selected' "; } echo "語(yǔ)言:".$_SESSION["language"]; echo "測(cè)試:".$name; ?>
2. 所包含的語(yǔ)言包:English.inc
<?php $name = "name"; ?> Chinese.inc <?php $name = "名字"; ?>
3. 所包含的function.php
<?php function getVailableLanguage() { $language = array( 'af' => 'Afrikaans', 'az' => 'Azerbaijani', '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' => 'English', 'es' => 'Spanish', 'et' => 'Estonian', 'fa' => 'Persian', 'fi' => 'Finnish', 'fr' => 'French', 'gl' => 'Galician', 'he' => 'Hebrew', 'hi' => 'Hindi', 'hr' => 'Croatian', 'hu' => 'Hungarian', 'id' => 'Indonesian', 'it' => 'Italian', 'ja' => 'Japanese', 'ko' => 'Korean', 'ka' => 'Georgian', 'lt' => 'Lithuanian', 'lv' => 'Latvian', 'mk' => 'Macedonian', 'mn' => 'Mongolian', 'ms' => 'Malay', 'nl' => 'Dutch', 'no' => 'Norwegian', 'pl' => 'Polish', 'pt-BR' => 'Brazilian portuguese', '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.所包含的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; }
關(guān)于使用php怎么實(shí)現(xiàn)一個(gè)多語(yǔ)言切換功能就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
文章名稱:使用php怎么實(shí)現(xiàn)一個(gè)多語(yǔ)言切換功能-創(chuàng)新互聯(lián)
新聞來(lái)源:http://jinyejixie.com/article26/hgdjg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、App設(shè)計(jì)、企業(yè)網(wǎng)站制作、品牌網(wǎng)站建設(shè)、小程序開發(fā)、全網(wǎng)營(yíng)銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容