Language: add default language in single-language sites
Currently, if you run:
$lang = kirby()->defaultLanguage();
...in a single-language site, you get null. That doesn't make sense. There's an implicit default language and that's English. Look at this:

I believe those 12 literals aren't good design. Those same things that users define in the languages folder under PHP files - Kirby can have one of those in its config folder and it can be used when there's nothing defined in languages. This would:
- Allow Kirby to define metadata for its "implicit" default language just how users can. For example, locale - does Kirby use British English or American English?
- Allow users to utilize language variables even in single-language sites. This may sound strange, but it's actually useful in practice. It's better to have static content in a single place, rather than in fields (which is time consuming) or as plain text in templates (which is less organized). If the site is not set as multilang in the config - Kirby simply uses the first file in
languages - The Kirby core could reduce its source code since it wouldn't have to use "fallbacks" - it would simply have a language
- Plugin authors will have a more consistent API - currently, you have to make checks for whether the site is multilingual in cases where that's unnecessary
In conclusion, my proposal is:
kirby()->defaultLanguage()returns- In a single-language site - the language in Kirby's
configor the first language in thelanguagesfolder - In a multi-language site - works as it does now
- In a single-language site - the language in Kirby's
kirby()->language()returns- In a single-language site - the same as
defaultLanguage() - In a multi-language site - the currently viewed language (translation)
- In a single-language site - the same as
kirby()->multilang()returns whether the site is flagged as multi-language in config.php
That sounds like we would force developers ti define a language even when they don’t want to care.
@distantnative nope, I said:
Those same things that users define in the
languagesfolder under PHP files - Kirby can have one of those in itsconfigfolder and it can be used when there's nothing defined inlanguages.
Kirby can simply provide a default language for developers who don't care. It already does that, actually - in the form of 12 occurrences of 'en' in the source code. My whole point is to improve that.
At the same time, if I want to have a single-language site with Deutch as the default language, I could simply create languages/de.php and that's it. If I decide to turn it into multi-language, I just flip the switch in config.php and add more languages.
Why don’t you flip on multi-language with only one default language?
For several reasons:
- It doesn't make sense
- It would be easier for plugin developers to not rely on users setting the multi-language option in their single-language sites
- Your content files would end in
.de.txtinstead of.txt - Imagine a new developer joining the project and wondering why the site is flagged as multilingual when there's a single language
I'm testing now and actually, you can define languages/de.php without setting languages => true in the config. You indeed set the "default" language of the site with that, but all your files end up with .de.txt. I don't think that has to happen. You still have just one language.
Docs say the following about the languages config setting:
Enables language definitions via the Panel
So that doesn't alter the way Kirby treats languages. I think that's good. But apparently, Kirby internally flips the multilang switch on whenever there's a file in site/languages. I don't think that's correct.
I think it should function like this:
- No
languagesfolder or nothing inside of it - Kirby uses its own default language definition for English fromkirby/config - One file in
languages- it is used as the default site language instead (nothing appended to txt files) - More than one file in
languages- the site is now multilang and saving content appends the language locale to txt files as needed. Developers should adddefault => trueto one of the languages or an error is thrown
This is way simpler. One file - one language. Many files - many languages.