Uutiset:

Wondering if this will always be free?  See why free is better.

Main Menu
Advertisement:

Automatic language detection?

Aloittaja Teunel, huhtikuu 15, 2007, 12:15:07 IP

« edellinen - seuraava »

Teunel

I'm planning on creating an international forum, for users from all over the world. Is there some mod available that checks for the language settings on the user's browser, and shows that language on my forum?

:)
Thanks

klumy


Technological Deep

#2
This is simple =)
I will not create mod this time, becourse changes that should be made is very specific...

First of all.... modification target is Settings.php... so there are security risks to make mod....

Here goes necessary steps:

  • Open file with any text-editor (for example Notepad)
  • Look for line $language '<your default board language>';
  • Change it to:
    ###### Language detection ######
    $locale getenv("HTTP_ACCEPT_LANGUAGE"); # Looking for locales
    $locale eregi_replace("\,.+","",$locale); # Cleaning up all, except first one

    switch(
    $locale) {
    default    : $language 'english'; break; # Default board language
    case('ru') : $language 'russian'; break; # Russian
    }

    unset(
    $locale); # Cleaning up variable $locale
    ## End of language detection ##

    You can write any number of cases, for me I need only one - russian
  • Save your file and upload it to your server
  • Enjoy =)
Of course if you wish, you can change default board language to anything else, for example:
switch($locale) {
default    : $language 'russian'; break; # Default board language
case('es') : $language 'spanish'; break; # Spanish
}

If you don't know what sends your browser to site in HTTP_ACCEPT_LANGUAGE you can create simple php-file, that contains:
<?php
echo(getenv("HTTP_ACCEPT_LANGUAGE"));
?>


Good luck in programming =)

P.S.
Of course this only will work for first time this user opens forum, becourse language information stores in cookies
Best regards,
  Alexander 'Angelius' Filippov, hxxp:technodeep.net [nonactive]

Advertisement: