I’m evaluating Kirby for an upcoming website that will be available in three languages. But as I understand, the default way that Kirby handles multi-language websites, is that there is only one page tree structure. That is, the default language is the master that defines the page tree structure. Then, each page can optionally be translated in other languages. If a page is missing a translated language, the default language is shown. This is what I understand is the default behavior of Kirby in a multi-language setup. Correct me if I’m wrong here.
This way to handle a multi-language site is not what my client want. The client wants an independent page tree structure for every language. For example they may want to have a specific page only available in the german version of the site. And another page only available in the swedish version of the site.
This is the prerequisites that the client has:
The users should only need one login each, to access all language specific pages.
Independent page tree structure for every language
Possibility to choose the desired language version in the panel, to only show pages in that language.
Possibility to create a new page in one language that is not shown in the other languages.
The only option to prevent this behavior I can think of, would be to use different folders for each language. But in that case, you would loose the language functions (translating blueprints, switching languages in the Panel etc.)
While you can use redirects and filters to prevent the default fallback behavior in a standard setup in the frontend, I don’t see a way to fulfill all your requirements, particularly [quote=“ola, post:1, topic:6203”]
Possibility to choose the desired language version in the panel, to only show pages in that language.
[/quote]
Would a possible solution be to use a multi-site setup somehow? Each site would then have a specific language specified. The only drawback would then be that there will be three different login for each author that needs access to all three language versions? In that case, that might be an acceptable drawback.
I tried this multi-site setup but could not get it to work with different languages. But then again, I’m not that of an experienced Kirby developer yet. So I might have missed something essential.
Looks like I have to go back to WordPress for this project.
Only one login, separate file structure, URLs are correct.
The language.txt files would be used for global information that is normally placed inside site.txt.
This is a hack and probably more work than with the standard setup, but I think this could work.
Blueprint translations are still possible as they are based on the user language in the Panel, not the multilang feature.
Regarding locale settings etc.: Yes, definitely. But you can work around those, e.g. by getting the current language code from the URL in a plugin and setting custom options based on that.
Thanks @lukasbestle and @texnixe. I will definitely try this out. Yes it sounds like a hack, but a valid one. I will let you know how it went after I had a chance to experiment with this idea.
Ja det är alltid trevligt med lite svenskar @jenstornell
Thanks for all help here. I have played around a little with this and got a working solution. As you suggested I have a directory structure with a root page for all languages.
The problem I encountered was that I was unable to use the custom language variables for string translations. This needed the multi language mode to be activated, which I don’t wanted in the first place. But in the source code I found the code that loaded these language files, so I copied them to my site.php file and loaded them manually.
After writing some code that extracts the language code from the url, my site.php looks like this:
<?php
$kirby = kirby();
// Map of languages used:
$languages = array(
'en' => 'en_US',
'de' => 'de_DE',
'sv' => 'sv_SE'
);
// Get paths from url:
$paths = str::split($kirby->path, '/');
// Extract possible language code from first path. I.e: 'en' from www.example.com/en/another/page
if (count($paths) && isset($languages[$paths[0]])) {
$language = $paths[0];
} else {
$language = 'sv'; // Fallback language
}
// Path for the language file:
$path = $kirby->roots()->languages() . DS . $language;
// Load .php file if it exists:
if(f::exists($path . '.php')) include_once($path . '.php');
// Load .yml file and set as language variables if it exists:
if(f::exists($path . '.yml')) l::set(data::read($path . '.yml', 'yaml'));
// Set correct locale for php date and time functions:
setlocale(LC_ALL, $languages[$language]);
This works. But please correct me if I did something wrong or if it’s possible to simplify this even more.
I guess that language variables are not loaded at all on a single language installation. Therefor you need to do it yourself like you did. If this works I don’t find anything wrong with that.
Personally I would try to wrap it up as a plugin. I have not tested but in my mind this might work:
Copy the code you have to like plugins/my-plugin/my-plugin.php.
Add this to your site.php file: kirby()->plugin('my-plugin');
If it works it will force load your plugin before other things are loaded. It will run only once even if you force load it like this.
As I said, it’s untested but if it works it would be a “nice” hack.
As I wrote before, you shouldn’t do this. If you force load a single plugin before the plugins get loaded by Kirby, the other plugins won’t get loaded automatically anymore. Force loading just works to load in dependencies from plugins.
It seems to me that Ola problem is pretty related to another topic awaiting Kirby 2.5 to be solved. Once it’s solved, there will be no need for hacks. Ola would be able to use the same structure for all langauges, benefits from all nice language features, and filter menu/contents by language as it was possible before Kirby 2.3. What is not translated will be ignored in other languages.
The actual problem is that Kirby requieres the default language .txt file to be present in each page’s folder to work correctly. Free us from this constraint, and everything would become easy.
this topic is nearly one year old, and i stumpled upon it, while looking for how to have a multilang-site with independent pages/page trees per language.
is this still best practice?