Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Different language conversion

    hi,

    i am trying to change some text which is written in default language
    i,e english language now i am want to change it language
    like Deutsch ,English (UK),Italiano,Français etc.Is it possible
    with the help of php?.

  • #2
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    This topic should be in the PHP section, and not the PHP Snippet section. Perhaps you misunderstood this sections name meaning. If you could, change your topic title to include (Move This) or something.

    Anyway, you would need to creat seperate files, containing an array of phrases in each language, for example:

    PHP Code:
    // Array of phrases on language.en.inc
    $phrase=array();
    $phrase['good_afternoon'] = "Good Afternoon!";
    $phrase['good_evening'] = "Good Evening!";
    // ... etc. 
    PHP Code:
    // Array of phrases on language.de.inc
    $phrase=array();
    $phrase['good_afternoon'] = "Guten Tag!";
    $phrase['good_evening'] = "Guten Abend!";
    // ... etc. 
    And then based by either a $_GET superglobal, or cookies, you would set the default language, like 'de' or 'en' then include the appropriate file... a simple example:

    PHP Code:
    <?php

    $valid_languages 
    = array('en''de');
    if(isset(
    $_GET['lng']) && in_array($_GET['lng'], $valid_languages)) {
      include(
    "languages/language.".$_GET['lng'].".inc");
    } else {
      include(
    "languages/language.en.inc");
    }

    echo 
    $phrase['good_evening'];

    ?>
    Then you could test it by going to http://example.com/index.php?lng=de (Not a working example; an example URL of how it would beb used on your site.)
    Last edited by Element; 01-03-2006 at 10:38 PM.

  • #3
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    Why reinvent the wheel?
    http://uk.php.net/gettext

  • #4
    New Coder
    Join Date
    Dec 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Because some people use english windows and speak dutch or so i guess

  • #5
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by GJay
    Why reinvent the wheel?
    http://uk.php.net/gettext
    Gettext is a PHP extension that must be added or compiled in...it's not enabled by default. You can emulate the functions, but thats slower, and without writing wrapper functions to test for the functions, and if they don't exist emulate them isn't worth the effort in most cases. I prefer to use language files or store the language in the database myself.
    "$question = ( to() ) ? be() : ~be();"

  • #6
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    Not having the access to add the extension is a fair point I guess, no idea what diod meant (if it was a reply to me...)
    If multi-language is really that important, then the effort of finding a host with it installed would probably be less than doing what was suggested :|

  • #7
    New Coder
    Join Date
    Dec 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I mean that if im correct about the function of gettext, is that it checks what language your windows is; But if you have a english windows, then gettext thinks that u r english speaking, while u could be dutch speaking or so

  • #8
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    You're not correct
    You tell it what language you want to use in the script (so could be based on a DB value, or a $_GET var etc.)


  •  

    Posting Permissions

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