Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Translatable: automatic language redirection


Reply


5 Posts   197 Views

Avatar
neilcreagh

Community Member, 97 Posts

14 August 2014 at 1:58am

A quick question as I'm a little confused by the Translatable documentation. I've been through the forum and various other places but I can't definitively tell if the Translatable module includes automatic language redirection [either based on the users browser language or IP address, whichever is the easiest/most straightforward] ?

ie. French users redirected to the French Translation

Have others achieved this and what's the best approach for setting this up on a Silverstripe website with Translatable installed and about half a dozen languages?

Thanks,
Neil

Avatar
martimiz

Forum Moderator, 1106 Posts

14 August 2014 at 5:44am

I have never seen the Translatable module support automatic redirection.

It does support header links of the form <link rel="alternate" (see https://support.google.com/webmasters/answer/189077) that should make Google select the correct language to display...

Probably you would only use it if the homepage is requested without specifying a locale? In that case it should be possible to redirect, off the top of my head and not tested:

For example in a Homepage_Controller:

public function init() {
      ...
      if (!isset($_GET['Locale'])) {
         $userLocale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);

         //use an array to map the userLocale to a Translatable locale, like for instance fr -> fr_FR
         $locale = someMappingArray[$userLocale];

         $this->redirect('/?Locale=' . $locale);
      }

Avatar
neilcreagh

Community Member, 97 Posts

14 August 2014 at 11:37pm

Thanks for the quick reply. I'll play around and see if this works. Anyone else done this before or got any other ideas?
Thanks

Avatar
neilcreagh

Community Member, 97 Posts

19 August 2014 at 2:42am

Edited: 19/08/2014 2:43am

I'm going to use a simple [url=http://www.javascriptkit.com/script/script2/language.shtml]browser language redirect script[/url] instead - placing it onto my homepage /home and having a duplicate homepage, without this javascript on it, at /en (the default redirect). With Translatable active and a dropdown language picker on /en this should work.

Is there any reason why this is a bad idea? If not, I'll come back here and report on the set-up when it's up and running (for anyone else looking to do this)

Avatar
martimiz

Forum Moderator, 1106 Posts

19 August 2014 at 5:57am

It looks a bit complex to mee, to have to create a duplicate homepage... Maybe you could add that script to the deafult Page_Controller, and make it check the url before deciding to redirect?