News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Language based on your ip

Started by PLAYBOY, December 02, 2010, 10:16:00 AM

Previous topic - Next topic

PLAYBOY

Is there a way to set the forum language change automatically based on the persons ip adress.
Like if the guy is in US the forum will appear in english or if he is from Pakistan the forum will in..... whatever the language they speak... that was a stupid example :D

anyways you got the point :)

1.1.12

All Colours Sam

it can be done, however, what will happen if an English man who lives in Mexico wants to see your site?  the guy will the see the site in Spanish.  another issue for me will be the amount of language files to install and maintain, for every mod you install you have to make sure you put the proper translation in all your languages.  some browsers like chrome detects the language and tells you to iether trasnlate to yours or keep it the original, that would be a better choice IMO.
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

Deaks

im with MissSunday on this its possible but I would suggest it, case in point im Scottish, I live in Scotland on here I use Finnish language, so basing on my ip would insult me ... also you are forgetting about proxy sites
~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

YogiBear

Sometimes, a server will use different IP ranges. A friend on AOL who lives in the UK sometimes finds her IP is registered to the United States or beyond.

SMF v2.1.4  Mods : Snow & Garland v1.4, Simple Image Upload v2.0.0,  PHP  v.8.1

PLAYBOY

Quote from: Miss All Sunday on December 02, 2010, 10:31:22 AM
it can be done, however, what will happen if an English man who lives in Mexico wants to see your site?  the guy will the see the site in Spanish.  another issue for me will be the amount of language files to install and maintain, for every mod you install you have to make sure you put the proper translation in all your languages.  some browsers like chrome detects the language and tells you to iether trasnlate to yours or keep it the original, that would be a better choice IMO.

Pretty good idea. I didnt think about that.
Well then maybe something like this can be done.... First of all there will a dropdown (or a list of) Languages option on the side anyways but if a guy visiting from USA the forum will be english. A guy from pakistan will see the forum in that special language :) but if there is a visitor from like southpole (or a place you dont have an installed language of) will see the default language aside from a dropdown language option there also.

How about this idea?

1.1.12

All Colours Sam

Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

PLAYBOY

I know but thas not what i am looking for. Dropdown menu is just an extra option on the side for the people like
Quoteim Scottish, I live in Scotland on here I use Finnish language, so basing on my ip would insult me
and
Quotean English man who lives in Mexico

JimM

You might want to post you suggestion on the Mod Requests board.  Also if you are suggesting this as a feature to future versions, then feel free to post a topic on the Feature Requests board.

Personally, I don't think it's a valid suggestion because of all the space you would use installing all the different languages.  Additionally most forums wouldn't need that many languages.
Jim "JimM" Moore
Former Support Specialist


PLAYBOY

Well actually its good to see this topic again so i can write the solution i found for this.

I havent tried it on the forum but it works perfectly on html pages. It doesnt go by the ip, it goes by your browser language which is lot better way to go. Because i could be a japanese guy living in mexico. I would still want to see the website in japanese.

Add this code before the < /head > in your index.html

<SCRIPT LANGUAGE="JavaScript1.2">
<!-- Begin
if (navigator.appName == 'Netscape')
var language = navigator.language;
else
var language = navigator.browserLanguage;

/*-------------------------------------------------------------
Dil Algilama Scripti Baslangici
-------------------------------------------------------------*/

if (language.indexOf('tr') > -1) document.location.href = '/turkish.htm';
else if (language.indexOf('en') > -1) document.location.href = '/english.htm';
else if (language.indexOf('de') > -1) document.location.href = '/deutsch.htm';
else
document.location.href = '/turkish.htm';
// Bitimi -->
</script>


I got the script from i think javascriptkit.com i dont really remember. So dont blame me for copyright stuff.
Just change the language files to your language pages make sure you put the right encode language code. Example en for english de for deusch etc...

Oh, here is something that is pretty important.
Make sure to put this code in index.html because if you put it as it is on one of the language pages, it will just keep loading (refreshing) the same page. Now you can either do it like i did and make your html homepage open up with this code and it redirects people to language pages... or you can try to implement it to smf somehow.

I guess you can implement it like this into smf...
Create an html file called "language_script.html" in your source folder and put this code in it...

<SCRIPT LANGUAGE="JavaScript1.2">
<!-- Begin
if (navigator.appName == 'Netscape')
var language = navigator.language;
else
var language = navigator.browserLanguage;

/*-------------------------------------------------------------
Dil Algilama Scripti Baslangici
-------------------------------------------------------------*/

if (language.indexOf('tr') > -1) document.location.href = ';language=turkish';
else if (language.indexOf('en') > -1) document.location.href = ';language=english';
else if (language.indexOf('de') > -1) document.location.href = ';language=deutsch';
else
document.location.href = ';language=turkish';
// Bitimi -->
</script>


And after the below code in index.template.php

// The following will be used to let the user know that some AJAX process is running

put this

// Calling the language script file
require_once 'language_script.html';


And now when people who sees any of your forum pages they will see.........
Oh DAMN! Nevermind... this code like i wrote above wont work on your forum like that. I just realized it but i dont wanna delete it because a more professional coder maybe able to make it work.

Again the code as above wont work with your forum.
A more professional coder can figure out a way to implement it. However you can use the html way of it like i did and direct people from your html pages to forum pages with the right language settings by just adding ;language=ENGLISH part to your forum page addresses.

Im not a pro coder nor im good with php. Im sure there are lotto errors and mistakes up there but i hope it would be helpful on the progress though.

MrPhil

Let's back up for a moment and figure out what the OP is trying to accomplish (not how are they trying to do it). I take it that PLAYBOY wants to have pages displayed in the forum's best guess as to the user's language, as a guest or before they've signed in and SMF can look up their stored language preference. As suggested, going by IP address could cause problems. I know that the osCommerce application asks the browser what language it's using, and uses that for the default (if available). Judging from the number of complaints that pages are in English and not the desired language, 1) most browsers are still configured in English, and 2) osC is not properly switching languages upon user request or sign-in. In either case, obviously if the language isn't supported by your SMF installation, you need to fall back to a default such as English. Installing every available language is simply not necessary. I think that asking the browser what language it's using is the best path -- if it's a public terminal, it's likely to be a language that most of the locals speak, or if it's a private terminal, the owner has likely configured the browser to use the language they want to use. Everyone is happy, unless you don't have that language installed on SMF, forcing the user to deal with English. I suppose that trying to map the IP address to the most likely local language could be a backup to using the browser language (if that language isn't available), but you'll still have plenty of visitors presented with English. All you can do in that case is make it easy to spot where on the page you can change the language, and make it intuitive enough that someone who can't read English can at least recognize a flag and know that they can click there to see a list of languages. As long as each language is presented in both some common alphabet/language (such as English) and in its own alphabet/spelling (see this forum's language support boards list), a flag is not absolutely required. Flags can cause more problems than they're worth -- e.g., for Spanish speakers, how many are going to recognize Spain's flag, if that's the only one you use? How about a Spanish-speaking American -- are they going to feel insulted by having to click on a foreign flag? I think that flags are most useful for grabbing the user's attention that "here is where you select your language", and should not be used for the sole means of selecting the language.

Advertisement: