Hi,
In kirby 4 I’m using multiple languages for my pages. When I add a new page (in my case article page), it should always switch or create the default language first.
However, when I switched the language before to a different one, e.g. German, and go back to my overview and create a new page via the panel it creates a German page first.
Is there a way to change that?
Thanks,
Christian
Well, the new page is actually created in the default language in the file system with the title and slug added in the create dialog. But you remain in the context of the currently selected language and when you enter data in that context now and save, this will be stored as a translation in the content file of the currently selected language.
But I guess what you want is then to be redirected to the default language?
Yes exactly, i want a redirect to the default language in case a user tries to create a secondary language first. (So kind of: In case no default lanugage exists, redirect to default language; or even better force that all new pages are created as default first)
So would there be a way to redirect always to default language or to force to always create a page in default language? thank you!
Unfortunately, not sure. Probably by modifying the page create dialog. Doesn’t seem to be possible to add a redirect with the language in the create->redirect
blueprint option.
1 Like
I solved it by creating a plugin. however that may not be the best use for all cases.
What it does it it always redirects to the english page (my default language) on my overview pages, but not on children pages (they contain a + in url).
I’m only translating my children pages and not the main site, so that’s why it is a working solution for me. Here’s the code in case somebody is looking for a similar solution.
<?php
# site/plugins/redirect-to-english
# this plugin redirects always to english page unless it's a page children (+)
Kirby::plugin('cb/redirect-to-english', [
'hooks' => [
'route:before' => function ($route, $path, $method) {
if (
(strpos($path, 'panel/pages/') !== false
|| strpos($path, 'panel/site') !== false /* in case your main site has only english */
) && strpos($path, '+') === false && $method === 'GET') {
if (!isset($_GET['language']) || $_GET['language'] !== 'en') {
// Construct the redirection URL
$panelPath = substr($path, strlen('panel'));
$url = kirby()->url('panel') . $panelPath . '?language=en';
go($url);
}
}
}
]
]);