I have a customer that needs a site setup in 3 languages. The problem is, that the content of the site is going to be vastly different between the 3 languages - for instance: the site has a blog, but it will use different article categories, tags, and will have totally different articles in the 3 languages. So, what is needed is not just a straight-forward translation of every page in the site. In each language, there will be lots of pages that the other languages wonāt have, intentionally.
It seems to me, therefore, that Kirbyās built-in multi-lingual setup may not be the best solution in this scenario Please correct me if Iām wrong, as Iād love to be able to do this with the built-in toolsā¦
The client has asked us, to have the siteās URLs like this:
ā¦and so on. I was wondering whether the following would work:
copy the entire site into de and fr subfolders within the parent English site, so that each subfolder is an entire site by itself.
edit the .htaccess file at the root of the parent site, so that /fr and /de requests donāt get routed - get passed straight through to those folders.
As this is the first time Iāve ever had to do a setup like this, I thought Iād run it by you guys first, to get some feedback, and check whether this is indeed the proper way to do it, of whether Iām missing something obvious.
Iām currently working on a similar site. We are using the customized folder setup for this so that every language has its own content folder. Then we use domain-specific configuration files to change the default language per domain.
@lukasbestle That sounds IDEAL!!! But doesnāt this kind of setup require me to have separate domains? In my case, itās all in the same domain, with sub-directories/sub-folders - i.e., āexample.com/deā rather than āde.example.comā (I tried suggesting that to the client, and they didnāt want it)ā¦
Can I use ācustomised folder setupā and ādomain specific configuration filesā with this setup, if Iām using sub-folders in the url? i.e.- how can I load specific configurations for āexample.comā, āexample.com/deā and āexample.com/frā?
Would you mind sharing some of your setup, as an example?
Your ācustomized folder setupā can use any logic you need. So you could also extract the language code from url::path() and use that to determine the language. Maybe something like this in the site.php:
// Initiate Kirby
$kirby = kirby();
$domain = server::get('server_name');
// Manually set the index URL
$kirby->urls->index = url::scheme() . '://' . $domain;
// Get the current language code
$code = explode('/', url::path())[0];
if(!in_array($code, array('en', 'de', 'fr'))) $code = 'en';
// Set the content root and URL
$kirby->roots->content = __DIR__ . DS . 'content' . DS . $code;
$kirby->urls->content = $kirby->urls->index . '/content/' . $code;
// Set a configuration var so that you can later set the default language
// Note: You have to do this manually in the config, Kirby won't do it automatically
c::set('language.default', $code);
How will the Panel know which ācontentā folder to access? - i.e., if I use āexample.com/de/panelā, will it know that it needs to read from the ādeā content folder?
I have done the following, as per your instructions:
put a folder āenā inside the content folder, and moved all the content into it.
duplicated the āenā folder to make āfrā and ādeā folders.
at the root level, next to index.php, created a āsite.phpā with the code you provided above.
at the end of the file, I added the following code, to try and set the locale - I donāt know whether this will work or not, so please feel free to guide me here, too:
switch ($code){
case 'fr':
c::set('locale','fr_FR');
break;
case 'de':
c::set('locale','de_DE');
break;
default:
c::set('locale','en_US');
}
If I simply try to access āexample.comā, it goes fine - it finds the content that is inside ācontent/enā. But if I try to access āexample.com/deā or āexample.com/frā, it fails - it takes me to the error pageā¦
[...]
case 'de':
c::set('locale','de_DE');
c::set('url', $domain . '/de');
break;
As mentioned, this means that everything works, except for the panel: if I try to access āexample.com/de/panelā or āexample.com/fr/panelā I get a blank page. No php errors, no html code on the page at all, it simply returns blankā¦
EDIT: setting the base url via c::set('url', $domain . '/de') doesnāt actually work - Iām now getting blank pages everywhere, and it seems that the browser is trying to load assets from āde/assetsā, thumbs from āde/thumbsā, etc. Itās not just a panel issue, and I canāt see a way around thisā¦
I think it might be easier to just have sub-folders inside the parent site, as I described in my initial post. Not elegant, but probably the easiest solution in this scenario, where we must use sub-folders, instead of sub-domainsā¦
The advantage: You can use language variables (l::set and l::get) and language selectors and Kirby will do all the routing for you.
But please note that you will have to rename all content files from e.g. project.txt to project.en.txt, project.de.txt and project.fr.txt respectively.
I havenāt tested this code specifically, so please let me know if that works.