I feel like there’s something obvious I’m missing here, but I can’t find it anywhere in the Kirby Docs. In a multilingual site, I need to get the value of a field in a specific language - which may not be the current one. Is that what the
translation() method is for?:
<?= $page->translation('de')->myfield() ?>
Whatever method we use, if there field does not have a translated value in that language, will it automatically fallback to the default language value?
Many thanks in advance for any guidance.
No, you need the
<?= $page->content('de')->myfield() ?>
translation() gets the
[translation](https://getkirby.com/docs/reference/@/classes/cms/contenttranslation) object that you can use to check if a content file in a given language exists.
Thank you, @texnixe!
If the content is not available in the requested language, does it return whatever is available in the ‘default’ language, or does it return empty/null/error?
If the language is defined and the translation doesn’t exist, the default language content is returned. If you pass the language code of a language that is not defined, an error is thrown.