Forum
Blog - Switching between languages, even when in a post
Hello,
I am trying to set up a blog in which every post will be written in dutch and english. I have come across multiple ways of doing this, but I'm not sure which way will work best for me.
I would like to be able to switch language when reading a post, so that the title, content etc. will change when clicking on a flag that switches ?lang=nl to ?lang=en and vice versa. I'm guessing that my best option would be to work with conditionals inside my post.html, but will the url also change?
As you can tell I'm a bit confused now, what would be my best option?
- Mike
Can you explain what you mean?
Well, if I am using the method of creating a seperate dutch post and an english post, they will both have a different URL. How would I be able to switch between both, when changing language?
I think as you've found, it's not the easiest to set up blog with multiple languages.
Do you need to use blog? Using a standard page at least lets you use a separate region for each langauge, per page (or item).
Otherwise, the only thing I can think of is setting up multiple blogs or sections - one for each language - then you'd need to create a little field type to allow you to choose a post from each blog/section. You'd be manually choosing which language post to link the current post to (and therefore use to "switch" language).
I again think you're going to struggle with blog - if you're using a slug as the unique identifier and you don't want the url to change, which slug "wins" for the url - Dutch or English?
You can have one post for both languages. You need to work on making your edit form template to make it user-friendly though. For example, you can use the
divider-before
attribute to create some separation and collapsable sections.Assuming Dutch is the default language:
Each post would have a single slug. You can rely on URL parameters (
?lang=nl
and?lang=en
) to determine which language to use can work like you suggested. You can display the English post only when?lang=en
, otherwise display the default (Dutch).perch_get('lang')
should get you the value of thelang
parameter.perch_get('lang', 'nl')
should setlang
tonl
if there is nolang
value in case you need it!Pass the value to the template with
PerchSystem::set_var()
. On yourpost.php
:And in your template you can check for
lang
: