Jump to content

Is this thing on?


MarcC
 Share

Recommended Posts

I'm testing ProcessWIre's localization features, trying out fields like TextAreaLanguage and PageTitleLanguage. I've got them installed, assigned, and filled out. Now, how do I, for example, make Spanish-language fields show up on the public site for Spanish-language visitors?

It feels like a bit of a dumb question, but I swear I looked at the docs!

I thought it might be automatic detection based on a header string or something, but that hasn't worked for me. I don't know exactly what details to look for as this is my first time through. Thanks!

Link to comment
Share on other sites

You won't be redirected just like that. You know that Ryan wouldn't do something like that to us, remember, you're still in full control ;)

Now you have to use the available methods to take people to the correct url. My favourite is implementing a simple language switch, since I personally hate to be redirected to my browser's language without being asked. You would use $page->localUrl($language) for this. Check how to do it here https://processwire.com/api/multi-language-support/multi-language-urls/

I usually do something as simple as this:

foreach($languages as $lang) {
    $active = $user->language===$lang ? 'class="active"':'';
    echo "<li {$active}><a href='{$page->localUrl($lang)}'>{$lang->title}</a></li>";
}

--

For serving the language based on the browser language, you don't even need the language urls —and since I've never done it, I may be giving you a wrong info— Just detect the browser language http://www.paulund.co.uk/auto-detect-browser-language-in-php and switch the user language accordingly with:

$user->language = $language;

Of course, if you prefer, set up the URLs and make the redirect instead.

  • Like 1
Link to comment
Share on other sites

Thanks Diogo, I didn't know that was there. So I've enabled /es/. Should I now change my browser language and test to see if I am redirected?

To do that use my super awesome AutoDetect Language module! Does that automagically for you!

Sorry no link, writing from my iPad. :)

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...