So I have successfully set up two locales on my site, with a button to switch between, this works fine for all the sections that have the langauges set, but I cannot seem to get it to work for the news index template, my news feed. An individual entry will work fine, but the collated entries don’t. Is there a snippet I need to place at the top of the News index template to define what locale it should contain?

  • Is this the language switch you are using? Do you want to translate URLs and slugs? – carlcs Jul 9 '14 at 19:01
up vote 10 down vote accepted

This Google+ thread may help: https://plus.google.com/116942350387086245334/posts/TBtR3XwuZGx

Current options as per above thread:

  • It’s a shame that something as standard as a blog needs a workaround like these. Thanks Andrea. – simonsweeney Jul 9 '14 at 18:29
  • @simon it's not a workaround but simply the difference between entry pages, which get the Url from section url and slug settings, and unrelated pages as your index.html, that Craft doesn't know about. – carlcs Jul 9 '14 at 18:47
  • Other then to make the index a Single section, I suggest to also consider designing a Structure section, with all your single pages and your channel index page becoming entries of that section (with individual entry types if needed). Then you can translate the slugs of all your pages with ease and your language switch works as it is. – carlcs Jul 9 '14 at 18:58

If you don't want to translate the sections URLs and the entries slugs then there's a very easy way to do a language switch. Just append craft.request.path() to your localized base URL.

<a href="{{ 'http://craft.dev/' ~ craft.request.path() }}" class="nav-link{{ craft.locale == 'pt_BR' ? ' current' }}">BRA</a>
<a href="{{ 'http://craft.dev/de/'  ~ craft.request.path() }}" class="nav-link{{ craft.locale == 'de' ? ' current' }}">GER</a>

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.