Author Topic: [MOD REQ] Auto change language based on IP  (Read 4674 times)

0 Members and 1 Guest are viewing this topic.

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
[MOD REQ] Auto change language based on IP
« on: July 03, 2009, 01:29:51 PM »
My main language in my 4images gallery is Slovenian. What concern me that when visitor from outside my country come to my site, he/she will live it as soon as he/she will see that the site has strange language.

I would like that based on user IP (country) gallery language would change. If user is not (myip != SI) from Slovenia -> change to English language.

I've already installed GEO IP (from http://www.maxmind.com/app/geoip_country) but I don't have idea how to automatically change language...  :roll:

EDITED:
lol i think I found the way :)

Please someone test it first!

First you have to upload GEO IP files (Next few line taken from: http://www.4homepages.de/forum/index.php?topic=7831.0)

Visit the home page of the tools will be used in this mod:
http://www.maxmind.com/app/geoip_country
Read the licence and make sure its NOT conflicts with your usage.

Download the following files:
1) http://www.maxmind.com/download/geoip/api/php/geoip.inc
Save it in includes/ directory of your 4images installation

2) http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
Extract the content of this archive (u can use WinZIP, WinRAR, 7-Zip or any other archivers)
Save the extracted file (GeoIP.dat) into includes/ directory (make sure u keep the case: its GeoIP.dat not geoip.dat)

3) http://www.maxmind.com/download/geoip/database/flag.zip
or
http://web.tampabay.rr.com/vano/redirect.html?flags.zip

4) Go to global.php and before:
Code: [Select]
include_once(ROOT_PATH.'lang/'.$config['language_dir'].'/main.php');
add:
Code: [Select]
if ($_SERVER['HTTP_X_FORWARD_FOR']) {
$ip = $_SERVER['HTTP_X_FORWARD_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
if (!class_exists("GeoIP")) {
 include(ROOT_PATH."includes/geoip.inc");
}

$gi = geoip_open(ROOT_PATH."includes/GeoIP.dat",GEOIP_STANDARD);
$countries = array();

$cid = geoip_country_code_by_addr($gi, $ip);
//$countries[$cid] = isset($countries[$cid]) ? $countries[$cid]+1 : 1;

if (strtolower($cid) == "hr") { // Croatian visitors
$config['language_dir'] = "hrvatski"; // change depend on secondary language
} elseif (strtolower($cid) == "si") { // visitors from my country Sloveniange
$config['language_dir'] = "slovenian"; // change depend on secondary language
} else { // all other visitors
$config['language_dir'] = "english";  //
}

Watch out! This is just my modification, because I have install in my 4images gallery three languages in those directories:
- slovenian
- english
- hrvatski

So depend on your installed languages change those line...

Please let me know if it's working or if you have any other suggestion.

You can check demo: http://www.slo-foto.net/galerija
« Last Edit: July 03, 2009, 03:06:14 PM by Lucifix »

Offline edonai

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: [MOD REQ] Auto change language based on IP
« Reply #1 on: August 29, 2009, 02:18:51 AM »
it's a great idea, thanks Lucifix !

Offline Sunny C.

  • Addicted member
  • ******
  • Posts: 1.806
  • I ♥ 4I
    • View Profile
Re: [MOD REQ] Auto change language based on IP
« Reply #2 on: August 29, 2009, 05:14:11 AM »
NICE