Hello,
I have some troubles finishing the set-up of my multi-language architecture.
Basically the main page will be in English, and a few selected articles will be translated into French.
I have Ghost 3.12.0. My theme is a fork of Casper-XYZ, itself a fork of Casper.
Bascially it is a few tweaks here and there, a custom CSS. The original fork was up-to-date with Casper 3.0.6, I merged the latest changes until 3.10.0.
Besides that, I would say the core of my theme is 98% Casper, no breaking changes were made to its core.
So I followed the famous tutorial.
I created the #fr tag.
My routes look like that:
routes:
collections:
/:
permalink: /{year}/{month}/{slug}/
template: index
filter: 'tag:-hash-fr'
/fr/:
permalink: /{year}/{month}/{slug}/
template: index-fr
filter: 'tag:hash-fr'
taxonomies:
tag: /tag/{slug}/
author: /author/{slug}/
Then I duplicated the index.hbs
and named it index-fr.hbs
.
Since I am still on a development phase, I moved 3 default Ghost articles from getting-started to #fr and I see that the routing is working great.
4 articles on the main page and 3 articles when I go to /fr
Now here are 2 issues.
First issue:
In Casper, the <html lang="{{@site.lang}}">
attribute is hard-coded in default.hbs and applies to all templates.
The point 2 of the tutorial is not really working. In posts, it passes a second html lang attribute in the middle of the post code, and this tweak has no effects on other templates than posts.
I am no HBS expert so my solution may be dirty, here is what I did:
in default.hbs
:
I changed <html lang="{{@site.lang}}">
to <html lang="{{block "lang"}}">
in post.hbs
:
at the very bottom, I added:
{{#post}}
{{#has tag="#fr"}}
{{#contentFor "lang"}}fr{{/contentFor}}
{{else}}
{{#contentFor "lang"}}{{@site.lang}}{{/contentFor}}
{{/has}}
{{/post}}
And all the other templates: index.hbs, author.hbs, tag.hbs I added at the very bottom:
{{#contentFor "lang"}}{{@site.lang}}{{/contentFor}}
except of course index-f.hbs
which is:
{{#contentFor "lang"}}fr{{/contentFor}}
It works fine, the html lang is ‘en’ everywhere, except the index-fr and the #fr posts, which is ‘fr’.
The problem with that solution is that I hade to made many changes, and in the future it may be a pain to maintain with the merges with the Casper upstream. I would like to keep my core files as unchanged as possible.
Is there a more elegant solution than the one I described above? To pass the right html lang attribute to the default.hbs template?
Second issue:
The index.hbs I duplicated into index-fr.hbs has no context. When I check the source code on Chrome, I see
</head>
<body class="">
I tried all {{#is “contexts”}} nothing is returned.
What can I do to pass the right {{body_class}}?
I would like the index-fr.hbs template to be recognized just like index.hbs, as a home-template:
</head>
<body class="home-template">
Thank you a lot for your help!