PHP Simple implementation of multi-language switching method, PHP language Switch _php tutorial

Source: Internet
Author: User
Tags getting started with php

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 ' =&gt ;   ' 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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.