Some questions about multi-language setups

A multi-language setup needs to have a ā€œdefaultā€ language, correct? Or is there a way to circumvent this?

Iā€™m wondering if there is there a way to configure dynamic fallbacks/detection what languages are available.

If i have a site with German, English and French set up, and English is the default, but say an article is only available in French ā€“ what will happen if I visit the articleā€™s page while browsing the German version of the site? Will it be empty?

Is there an option to detect if the content is available in the requested language, and do something if it is, and do another thing if it isnā€™t?

Yes.

Good question, but easy to test.

Yes, you can check what translations exist and output content in a particular language.

Content accepts a language code.

Tested it: Yes, if something is entered only in a language that is not the default language, it will be only displayed on that specific languageā€™s page in the frontend.

Cool, thanks! So itā€™ll be possible to create dynamic fallbacks that are independent of whether some language is the default or not, by doing something like

if ($page->content($kirby->language()->code())->get('text')->toBlocks()->isEmpty())
// etc...

Might even create a field method for this.

Thanks for your help!

Edit: aaactually maybe it would make more sense to create a hook that simply duplicates any non-default content file to the default language, if it doesnā€™t exist :bulb:

Iā€™m still pondering different ideas to implement a setup that doesnā€™t prioritise one content language over another.

Is there anything preventing me from creating a fake default language like this:

return [
    'code' => 'default',
    'default' => true,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'en_US'
    ],
    'name' => 'Default',
    'translations' => [

    ],
    'url' => '/'
];

?

Iā€™d add all other languages normally, but they would all be considered ā€œsecondaryā€. It feels counterintuitive to store metadata like a date field in a specific languageā€¦

In my experience itā€™ld be a very bad idea to try to work ā€œaroundā€ the default language idiom in Kirby. It is needed for a lot of moving parts to work as expected.

If you really, really need a website that has completely different content spread across languages, Iā€™ld consider setting up a multisite setup as those languages are separate websites anyway.

Hmmm, okay. Thanks! :~)

Itā€™s not entirely different content ā€“ all pages that exist should be visible in all languages in the frontend, just like by default. The site is fundamentally a blog with a main blocks field on each page. Everything else is metadata and doesnā€™t need translation. But all content is not necessarily available in English.

I want to provide a more precise tool for editors to fill in content. If they i.e only have a French version of a text and put that in the French mask, but the default is English, nothing will show on the English site. Except if they enter the french text in English ā€“ But that doesnā€™t make sense.

So my idea was to have a ā€œdefaultā€ thatā€™s sort of decoupled from any actual content, just for storing data like author and date. Maybe even hide the blocks field with CSS if Iā€™m not on a specific language.

Iā€™d then implement some logic to check what language the frontend is currently in, and if thereā€™s content in that language, render that, if not, give the user the option to show the content in whatever other available languageā€¦

:notes: Iā€™m absolutely overthinking this :notes:

This is possible even without defining a mock default language. After all, you only have a problem when you have content that doesnā€™t exist in the default language, otherwise non-existing translations will fall back to the default language anyway.

So in any given page, you can check if the default content is empty or not, and if not, then output an existing translation. If you have more than just two languages, you might have to support this in the Panel with some fields to indicated which language should fall back to which other language.

In general, it might help to set pages to translated via a toggle field (in case they are already published but not fully translated).