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?
2 Answers
This Google+ thread may help: https://plus.google.com/116942350387086245334/posts/TBtR3XwuZGx
Current options as per above thread:
- Create a Single for the News index template
- Create a localized template as per http://buildwithcraft.com/docs/templating-overview#template-localization
-
It’s a shame that something as standard as a blog needs a workaround like these. Thanks Andrea. Jul 9, 2014 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.– carlcsJul 9, 2014 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.– carlcsJul 9, 2014 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>