@texnixe: Now ->findByURI() works for the german uri, but not for the default language in my case.
@lukasbestle: Ok, is there a way to find the find the uri of the default language of a translated url? I donāt want to hard code my routes to muchā¦
What you could try is to call site()->visit('something', 'de') (where something is an arbitrary page) before accessing the page by its localized URI. I havenāt tested this, but maybe Kirby will then know that you are looking for the German version.
I have a approach but it works not correctly. The suggestion of first calling site()->visit('', 'de');
seems to work.
In the following code i can perform a site()->children()->findBy('title', 'title of the visited language');
for example.
I found out, that kirby writes a key named url-key in the content files with translated urls. So my approach is, that i first visit the site with the needed language and then search for the url-key:
kirby()->routes(array(
array(
'pattern', '(((de|en)/)?((unterseite|subpage)/?(:all)))',
'action' => function($fullPath, $langPath, $lang, $uri, $firstUriPart, $rest) {
$lang = ($lang) ? $lang : 'en';
site()->visit('', $lang);
# find page if default language is active:
$page = site()->children()->find($uri);
# now this is what doesn't work
if(!$page) $page = site()->children()->findBy('url-key', $uri);
# but i wonder why, because the following would work:
# if(!$page) $page = site()->children()->findBy('title', 'title of the translated page');
if(!$page) go('error');
# ... more code ...
}
)
));
Any ideas why findBy('url-key', '...'); doesnāt work?
Iāve just tested it. But it doesnāt seems to work. In the content file the key is written with a dash.
@bastianallgeier: do you have a solution for this problem? Would be very nice. Otherwise i have to hard code the uri of the default language. Works, but is a bit ugly.
Yes $site->visit() works fine when itās okay to hard-code everything. But I plus @tobias, it would be great to have a way to query a page object from within a route, in multilanguage.