Hello everyone,
Last November we started a project with multiple domains and languages.
Currently we’re upgrading from Kirby 2.0 to 3.1.1, and also releasing new functions on our project.
What we’ve done so far:
Hello there,
Maybe in my other post my problem is going under.
My multi-language setup works so far, my content structure:
product-xyz/product.de.txt (default)
product-xyz/product.en.txt
product-xyz/product.DE-de.txt
product-xyz/product.DE-en.txt
product-xyz/product.UK-en.txt
My problem so far:
If I’m on my second domain, which is for the German Market (*.de) should always use the following languages:
product.DE-de.txt
product.DE-en.txt
If there is no .DE-.txt it should fall back to *.de.…
Hello,
I access now the current language info with the following code:
$languages_code = array_column( c::get('languages'), 'code' );
$languages_pos = array_search( $site->language()->code(), $languages_code );
$language_info = c::get('languages')[$languages_pos];
This works perfect. Maybe there is a better/faster solution.
Also the check here works in my controllers\site.php
if (!$page->content()->exists()) {
...
}
Is there a way to set/overwrite the current …
Now we run into some problems we hope to solve.
Generally we can say that we run multiple A/B tests over the whole site.
We specificed each usergroup so far as a own language, were “de” is set as the default.
The logic how we set A or B is no problem, but getting the right content without a redirect.
In general we have example.com/de/home , but decided sometimes to show version B of it under the same url.
Behind it looks like we render: example.com/de2/home , but the URL should stay the same.
Is it possible in the template (or in a plugin) to set something like this:
$kirby->setContent(‘de2’);
Thanks for your help,
frank
Routes to the rescue.
Inside your route, conditionally set $site->visit($page, $lang)
to the desired language and return the page.
Routes could help indeed, but I’m wondering what the SEO impact will be of rendering different pages on the same URL’s?
SEO shouldn’t have a big impact, Google for example can handle JavaScript and A/B tests.
page.de.txt
Text: content de
page.de2.txt
Text: content de __ 2
Plugin:
Kirby::plugin('testing/ab', [
'routes' => [
[
'pattern' => '/de/(:all)',
'action' => function() {
return site()->visit(page(), 'de2');
}
]
]
]);
Template:
<?= $page->text()->kt(); ?>
Output:
content de
Am I missing something?
Sorry,
frank
Something like this, of course with an if statement that checks your A/B-test condition and some if statement that check if the page exists:
Kirby::plugin('testing/ab', [
'routes' => [
[
'pattern' => '/de/(:all)',
'action' => function($uri) {
$page = page($uri);
site()->visit($page, 'de2');
return $page;
}
]
]
]);
Don’t know if the above pattern works for the home page, you might have to make the all
placeholder optional.
Hello,
The code above is working perfectly. Run into an issue where my controller always redirect on itself on a missing language.
Is there another possibility to only affect the content elements?
And not the header/footer snippets?
Thanks,
frank
What do you mean with missing language?
controller/site.php
if (!in_array($kirby->language()->code(), $kirby->option('languages'))) {
$go = $page->url($kirby->option('language'));
go($go);
}
Was part of the legacy code.
Well, yes, you could also use some logic in the template/controller and then display either then content from de or de2, depending. on group.
$page->content('language_code')->somefield()
should do the job.