I have following requirement, and I’m unsure how to handle this properly in Kirby:
Customer wants a website that contains content translated in 5 different languages. That’s easy
But, they want to serve it via locales mapped to one of those languages. E.g.:
nl_BE → NL
fr_BE → FR
de_BE → DE
de_DE → DE
nl_NL → NL
en_GB → EN
en_CZ → EN
intl → EN
The rendered content in a selected locale is drawn from the mapped language, only for the price of the product which is country-specific (which could be handled from a helper function in a model).
They explicitely don’t want to setup the locales in Kirby to avoid managing all the different locales; instead they want to administer only the translated content in the panel.
i would use a non translatable object field for the price and set a field for each locale. then you could do things like $page->price()->toObject()->{$local}()->toNumber()
Thanks for you reply @bnomei. The problem isn’t so much the price.
The problem is I’ld like to setup those 5 languages in Kirby’s config (and in panel); but then have a frontend that serves locales: instead of mysite.tld/en/some-page → mysite.tld/en_GB/some-page.
How do you set up something like that; e.g. in Kirby’s router, in the $page->url() helpers, … ?
but it would need special setup for sitemap and canonical urls.
another idea would be to create a language for each locale BUT have custom page model that overwrites the content read/write method to just load the one from the corresponding language. not sure if that works but it might.
public function readContent(string $languageCode = null): array
{
return parent::readContent(substr($languageCode, 0, 2));
}
public function writeContent(array $data, string $languageCode = null): bool
{
return parent::writeContent($data, substr($languageCode, 0, 2)));
}
I’m testdriving the first option and the PoC seems to work. ATM, smaller things such as idd sitemaps, anything url-related and etc $site->homepage()->url(), … need extra work.
There wasn’t really a hard error, but pages appeared “empty” as if the content wasn’t in the content files…
Also; I’m unsure we can have a global model for all templates as I don’t really want to create a model for each template that is added. And, I don’t really know how to deal with reading from $site neither as I don’t think we can have a model there to force Kirby to read from the right site content files.
Maybe use two installations? One for the multilanguage content and a second one with all languages which pulls in content via content representations from the first installation?