« Return to Thread: Change i18n locale from a controller before calling the view

Re: Change i18n locale from a controller before calling the view

by AleCaste :: Rate this Message:

Reply to Author | View in Thread

Sure,
We are using google maps in our website so we have a key to use google APIs.
Once you have yours, you add the following code in the web page:

<script type="text/javascript">
    // Detects country by IP
    google.setOnLoadCallback(function() {
      if (google.loader.ClientLocation) {
        currentCountry = google.loader.ClientLocation.address.country_code;
      } else {
        //Can't find location
      }
    });
</script>

Apart from the country code, you can get other area info too, but we only need the country.
Our page redirects to the main page of our site, adding the country code as a param.
On the server side we have a table in a database with all countries and the languages spoken in each one of them.
You get the country code, look up the table, get the language code, and set the proper locale before calling the view (as I posted in my previous response)

Alex


Moe-25 wrote:
Good job! But I was wondering if you'd mind sharing the code for the nation
ip lookup? :D

Moe

 « Return to Thread: Change i18n locale from a controller before calling the view