Kirby language_region šŸŒ

Hi there,

I love the language support in Kirby, and the automatic language detect / switch in Kirby.
Italians see the website automatically in Italianā€¦

I would like to expand this functionality with regions as well.
Users can selection their country, example: Design Your Model 3 | Tesla

In the top right you can select your country/region and language: they combine both in 1 string: ā€œlanguage_countryā€.

Can someone point me in the right direction how I would do this in Kirby?
Any help would be greatly appreciated!

In theory, there is nothing that hinders you to create de-de, de-at as language codes (underscores donā€™t work).

This would then create different translations. The question is if this actually makes sense, when the translations themselves will not really differ, but itā€™s more about providing the right prices, terms & conditions etc. per region while the language will always be the same. If that is the case, then it might probably make more sense to choose a different approach.

The region selector is purely about showing different prices (euro, dollar, ā€¦)

The other approach would be working with cookies?

Or is there a way to add the region in the url and that kirby remembers it?
ā€” For example: site.com/nl/be/ā€¦ (the second paramater would be the region)
ā€” Or: site.com/nl-be and the router splits that parameter by the dash, first part is language, second part is region.

Iā€™m quite new to this, my approach might seem weird.
What would you recommend?

Honestly, I donā€™t know, since I have never implemented anything like this.

But letā€™s think about it.

Suppose you have these different languages as your basis. Then depending on region, you would have to inject different content into these translations. For example, your English translation would need prices for US, GB, Canada etc. and also all other world regions for which you donā€™t have a specific translation.

How could we store these regional price variants in the translations? Probably as structure fields? Then using a route part (or a parameter) like be, de, us etc as parameters, we could inject these regional prices into the translation. I think a URL path like nl-be wouldnā€™t work, because languages would stop working.

You would have to preserve the parameter or route path across pages, though, so you would have to store this information in your session and modify your paths accordingly.

The router would send information about the region to the controller and your controller would handle what information to inject into the page.

Maybe someone has already done this and has other, better ideas.

Thanks for your inspiration and help :slight_smile:

What about this: site.com/nl/design/region:be
How could I make sure, if I navigate to any other page, that I maintain my ā€œregionā€ paramter in the URL?

When I navigate to home, I want: site.com/nl/region:be
When I navigate to contact, I want: www.com/nl/contact/region:be

You would have to store the parameter value in a cookie, and add the parameter to your urls depending on cookie value. The $page->url() method accepts options, where you can set the parameter:

1 Like