Well, I know the answers to my questions as follows:
How to determine the country of the client?
As far as I know, we need to use the geoIP service to find the IP address of the client, which can determine where the client is used (for example, maxmind )
But this is not a solution to detect and change the language of my site if you are looking for this solution in laravel 4. I will show you the following question.
How to check the language the client wants to use? (locale in laravel4)
In a nutshell, I found several ways in which you can get the language that the client wants to use by following:
HTTP (HTTP_ACCEPT_LANGUAGE) $_SERVER['HTTP_ACCEPT_LANGUAGE'] Request::server('HTTP_ACCEPT_LANGUAGE') laravel4. , .
. , . , ,
<select>
<option val="en">English</option>
<option val="th">Thailand</option>
</select>
url Ex: www.Test.com/ru/ru/p >
cookie (). cookie , , . , .
, app/config/app.php :
'languages' => array('en','th','jp'),
app/filter.php, , :
App::before(function($request){
$url_lang = Request::segment(1);
$cookie_lang = Cookie::get('language');
$browser_lang = substr(Request::server('HTTP_ACCEPT_LANGUAGE'), 0, 2);
if(!empty($url_lang) AND in_array($url_lang, Config::get('app.languages')))
{
if($url_lang != $cookie_lang)
{
Session::put('language', $url_lang);
}
App::setLocale($url_lang);
}
else if(!empty($cookie_lang) AND in_array($cookie_lang, Config::get('app.languages')))
{
App::setLocale($cookie_lang);
}
else if(!empty($browser_lang) AND in_array($browser_lang, Config::get('app.languages')))
{
if($browser_lang != $cookie_lang)
{
Session::put('language', $browser_lang);
}
App::setLocale($browser_lang);
}
else
{
App::setLocale(Config::get('app.locale'));
}});
:
App::after(function($request, $response){
$lang = Session::get('language');
if(!empty($lang))
{
$response->withCookie(Cookie::forever('language',$lang));
}
});
, .