the best way to make codeigniter website multi-language. calling from lang arrays depends on lang session?

后端 未结 11 1107
情深已故
情深已故 2020-11-27 10:34

I\'m researching hours and hours, but I could not find any clear, efficient way to make it :/

I have a codeigniter base website in English and I have to add a Polish

11条回答
  •  盖世英雄少女心
    2020-11-27 11:10

    I second Randell's answer.

    However, one could always integrate a GeoIP such as http://www.maxmind.com/app/php or http://www.ipinfodb.com/. Then you can save the results with the codeigniter session class.

    If you want to use the ipinfodb.com api You can add the ip2locationlite.class.php file to your codeigniter application library folder and then create a model function to do whatever geoip logic you need for your application, such as:

    function geolocate()
    {
        $ipinfodb = new ipinfodb;
        $ipinfodb->setKey('API KEY');
    
        //Get errors and locations
        $locations = $ipinfodb->getGeoLocation($this->input->ip_address());
        $errors = $ipinfodb->getError();
    
       //Set geolocation cookie
       if(empty($errors))
       {
           foreach ($locations as $field => $val):
                if($field === 'CountryCode')
                {
                    $place = $val;
                }
           endforeach;
       }
       return $place;
    }
    

提交回复
热议问题