Results 1 to 4 of 4

Thread: Translation

  1. #1
    Join Date
    Jun 2006
    Posts
    42
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Translation

    I have this piece of code

    Code:
    <? echo" $curr_text"; ?>
    The value of $curr_text is in english and i would like to translate it in french
    example :
    if $curr_text=Most then the value displayed is Plus
    if $curr_text=Often then the value displayed is Souvent
    continuing with other words
    How could i write those conditions ?
    Any advice would be helpfull
    Thanks

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    The two word lists can be stored in arrays:
    Code:
    <?php
    $english = array("Most","Often");
    $french = array("Plus","Souvent");
    $cur_text = "Most";
    for ($i = 0;$i < count($english);$i++) {
    	if ($cur_text == $english[$i]) {
    		echo $french[$i];
    		}
    	}
    ?>
    Note: they must be in corresponding order.
    - Mike

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The common approach is to store all the translations in a big array:
    Code:
    $LANG = array(
      'en' => array(
        'l_most' => 'most',
        'l_often' => 'often'
      ),
      'es' => array(
        'l_most' => 'm&#225;s',
        'l_often' => 'a menudo'
      ),
      'fr' => array(
        'l_most' => 'plus',
        'l_often' => 'souvent'
      )
    );
    Store it in an external file, include it into every page, then
    Code:
    echo $LANG[$_SESSION['pref_lang']]['l_most']
    where $_SESSION['pref_lang'] is the name of the language. However, beware of differing word order, especially if dealing with non-Romance languages. For this reason, every site I've ever seen translate things by the sentence rather than by the word.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Or just store like this in a file:

    segment 1|two|three|etc.

    and use explode() for the array. I use that for my menus and lists on my site, it keeps things organized. Same method, different approach.
    - Mike

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
  •