Results 1 to 1 of 1

Thread: Multiple languages

  1. #1
    Moderator arnage's Avatar
    Join Date
    May 2009
    Location
    Serbia
    Posts
    712
    Thanks
    165
    Thanked 183 Times in 80 Posts
    Rep Power
    5

    Default Multiple languages

    Here are used tree languages in files srpski.php , english.php , spain.php stored in /translate/ folder, srpski.php (sr) is default.

    PHP Code:
    $lang = isset($_GET['lang']) ? trim($_GET['lang']) : 'sr';

    $langs = array('sr' => 'srpski''en' => 'english''sp' => 'spain');

    if (!empty(
    $lang) && !preg_match('/^[a-z]+$/D'$lang) || strlen($lang) > 2) { exit; }

    if (isset(
    $lang) && array_key_exists($lang$langs)) {
    $token_lang $langs[$lang];
    if (
    is_file($_SERVER['DOCUMENT_ROOT'].'/translate/'.$token_lang.'.php')) { require_once($_SERVER['DOCUMENT_ROOT'].'/translate/'.$token_lang.'.php'); }
    } else {
    if (
    is_file($_SERVER['DOCUMENT_ROOT'].'/translate/srpski.php')) { require_once($_SERVER['DOCUMENT_ROOT'].'/translate/srpski.php'); }

    Files srpski.php , english.php , spain.php are for smaller translations like link names, categories, title... and contains something like:

    PHP Code:
    $tlang = array();
    $tlang['home'] = 'Home';
    $tlang['back'] = 'Back';
    $tlang['wallpapers'] = 'Free Wallpapers';
    // ... 
    This function is for translation pages, to open the folder and include specified tpl file in case of choosen language.

    PHP Code:
    function get_lng_inc($inc_folder$inc_file) { global $lang;
    if (
    $lang == 'en' || $lang == 'sp') {
    if (
    is_file($_SERVER['DOCUMENT_ROOT'].'/'.$inc_folder.'/'.$lang.'/'.$inc_file.'.tpl')) { require_once($_SERVER['DOCUMENT_ROOT'].'/'.$inc_folder.'/'.$lang.'/'.$inc_file.'.tpl'); }
    } else {
    if (
    is_file($_SERVER['DOCUMENT_ROOT'].'/'.$inc_folder.'/sr/'.$inc_file.'.tpl')) { require_once($_SERVER['DOCUMENT_ROOT'].'/'.$inc_folder.'/sr/'.$inc_file.'.tpl'); }
    }

    For example folder structure like:
    root/folder/subfolder1/sr/file.tpl
    en/file.tpl
    sp/file.tpl
    /folder/subfolder2/sr/file.tpl
    en/file.tpl
    sp/file.tpl
    ... usage for the function when ur in /folder/ index.php is:

    PHP Code:
        echo head($tlang['PageTitle']);

    echo 
    get_lng_inc('subfolder2''file');

        echo 
    foot(); 
    Usage:

    PHP Code:
    if ($lang == 'en') {
    echo 
    '
    <a href="./index.php?lang=sr">Srpski</a>
    <a href="./index.php?lang=sp">Espańol</a>'
    ;
    }
    elseif (
    $lang == 'sp') {
    echo 
    '
    <a href="./index.php?lang=en">English</a>
    <a href="./index.php?lang=sr">Srpski</a>'
    ;
    } else {
    echo 
    '
    <a href="./index.php?lang=en">English</a>
    <a href="./index.php?lang=sp">Espańol</a>'
    ;

    Last edited by arnage; 20-04-11 at 20:22.
    <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 15
    Last Post: 21-11-10, 15:35
  2. 13 Languages for ur site
    By riderz in forum Coding Forum
    Replies: 0
    Last Post: 20-01-10, 15:56
  3. Email - Multiple Recipients.
    By blackhowk in forum Tutorials
    Replies: 0
    Last Post: 04-10-09, 09:56
  4. Translating Wap Sites To Other Languages
    By Waplego in forum Trash forum
    Replies: 8
    Last Post: 12-08-08, 02:35
  5. Multiple File Element
    By malaysia in forum Scripts Forum
    Replies: 4
    Last Post: 14-06-08, 18:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19