8

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?

carlcs
  • 36,220
  • 5
  • 62
  • 139
simonsweeney
  • 399
  • 3
  • 9

2 Answers2

10

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

Current options as per above thread:

Andrea DeMers
  • 1,226
  • 7
  • 15
  • It’s a shame that something as standard as a blog needs a workaround like these. Thanks Andrea. – simonsweeney Jul 09 '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 09 '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 09 '14 at 18:58
4

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>
carlcs
  • 36,220
  • 5
  • 62
  • 139