1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Multi language Website

Discussion in 'PHP' started by myharshdesigner, Sep 22, 2007.

  1. #1
    i want to develop multi language website in php. but i don't want to use a database on my server so how can i do that. language can be trancelate on the fly.


    is there any way ?
     
    myharshdesigner, Sep 22, 2007 IP
  2. ziya

    ziya Well-Known Member

    Messages:
    1,971
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #2
    You can use a language file . There you can store all your labels and there values.
    You can have files like these :
    label_eng.php
    label_fra.php
    ....

    And have inside each file something like these :
    $lang['Name'] = 'Name';
    $lang['Message'] = 'Message';
    $lang['Subject'] = 'Subject';

    You can include those lang files , and use variable.
     
    ziya, Sep 22, 2007 IP
  3. Twade Media

    Twade Media Banned

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    You can apply the language to a COOKIE or a SESSION and call on it time after time. You can also use the DEFINE function in your language files.
     
    Twade Media, Sep 22, 2007 IP
  4. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    from where i get this file.
    label_eng.php
    label_fra.php



     
    myharshdesigner, Sep 22, 2007 IP
  5. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #5
    You make them ;)

    If you don't want to as your first post suggests, you could link to Google translator versions though they are terrible, might be better than nothing though.
     
    krt, Sep 22, 2007 IP
  6. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks dear,

    i will use Google translator but if want to translate any dynamic data on the fly ( when my web site will run or some one post any comment etc. ) then i can i convert that data in to other language with the help of Google translator. ?

     
    myharshdesigner, Sep 22, 2007 IP
  7. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #7
    Go to Google's language tools, enter a page URL and language to/fro and copy the link into your code in a <a href="...">[language]</a> link. You can replace the link in the URL with the full path to the current page with $_SERVER['HTTP_HOST'] and $_SERVER['REQUEST_URI']
     
    krt, Sep 22, 2007 IP
  8. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thanks For your help.
    but i am new in php

    so can you explane me.
    like explane me with the help of code ?

     
    myharshdesigner, Sep 22, 2007 IP
  9. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #9
    <?php
    $current_page = ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    
    $content_lang = 'en';
    $content_lang_name = 'English';
    $translations = array('es' => 'Spanish', 'fr' => 'French');
    
    foreach ($translations as $k=>$v) {
      echo "<a href=\"http://translate.google.com/translate?u=" . urlencode($current_page) . "&langpair={$content_lang}%7C{$k}\">Translate from {$content_lang_name} to {$v}</a>";
    }
    
    PHP:
     
    krt, Sep 23, 2007 IP
  10. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    1st of all thanks.

    and now can any one demonstrate this code what this code doing on each line.

    How to use this line :-
    $current_page = ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    PHP:





     
    myharshdesigner, Sep 23, 2007 IP
  11. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #11
    <?php
    
    // Gets the current page URL (more or less as the user typed it in the address bar)
    $current_page = ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    
    // The language of the content (code and name)
    $content_lang = 'en';
    $content_lang_name = 'English';
    
    // An array of all the wanted translations
    $translations = array('es' => 'Spanish', 'fr' => 'French');
    
    // Loop over the translations
    foreach ($translations as $k=>$v) {
    
      // Build a URL to the google translator substituting the current page,
      // and the languages to be translated to/fro
      echo "<a href=\"http://translate.google.com/translate?u=" . urlencode($current_page) . "&langpair={$content_lang}%7C{$k}\">Translate from {$content_lang_name} to {$v}</a>";
    }
    PHP:
     
    krt, Sep 23, 2007 IP
  12. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #12
    I would not do this. It only confuses Google and messes up direct liking to pages.
     
    nico_swd, Sep 23, 2007 IP
  13. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    suppose i have three link
    1st:-

    www [dot] techinfocomp [dot] com/

    2nd :-
    www [dot] techinfocomp.com/about [dot] html

    3rd:-
    www [dot] techinfocomp.com/career [dot] html

    now how to use this script on this website ?
    www.techinfocomp.com

    pl tell me.

    Thanks
     
    myharshdesigner, Sep 23, 2007 IP
  14. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    i mean how to apply this code to my web site ?


     
    myharshdesigner, Sep 23, 2007 IP
  15. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #15
    Does your host support PHP? If so, copy/paste my code where you want the "translate" links. If you want to keep .html pages, then add this line to your .htaccess file:

    AddType application/x-httpd-php .php .htm .html
     
    krt, Sep 23, 2007 IP
  16. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Thanks for your support.

    what it's mean :-
    If so, copy/paste my code where you want the "translate" links.

    yes my host support php

    if i want to translate hole page the what i have to do or if i just need to translate a peace of code then what i have to do ?

    i just need to copy past this code in the top or my web page?

    this code what you provide us will translate hole page ?



     
    myharshdesigner, Sep 23, 2007 IP
  17. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #17
    Copy/paste it in your web page where you want the links for translating to be displayed. It will take the user to a page translated by Google's language tools.

    Remember the line in the .htaccess (you may have to create this file in your web root if it doesn't exist)
     
    krt, Sep 23, 2007 IP
  18. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    sorry sir i cant able to understand what do you mean.

    // An array of all the wanted translations
    $translations = array('es' => 'Spanish', 'fr' => 'French');
    PHP:
    how to change language with this line.

    pl provide me some simple example or pl simplify me this example sir.
     
    myharshdesigner, Sep 23, 2007 IP
  19. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    i am so thankful to you.
     
    myharshdesigner, Sep 23, 2007 IP
  20. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #20
    $translations = array('es' => 'Spanish', 'fr' => 'French');
    PHP:
    Follow the pattern:

    The language code in single quotes, followed by => then the language name in quotes, then a comma. Get the language code from the Google language tools page, when you translate a page, you should see &langpair with 2 codes in it.

    Examples:
    'es' => 'Spanish',
    'ko' => 'Korean',
    'jp' => 'Japanese',

    Remember to put them inside the array( ... )

    This might be an easier format:
    $translations = array(
      'es' => 'Spanish',
      'fr' => 'French',
      'ko' => 'Korean',
      'jp' => 'Japanese',
    );
    PHP:
     
    krt, Sep 23, 2007 IP