Blog localisation via templates & navigation and tags

Hey all!

I have a few question about adding localisation to Ghost.

I’m using similar structure like in the default theme Casper where body content is set into default.hbs via referencing {{!< default}} at top of the templates. Would it be possible to set the html lang attribute in the templates as a parameter e.g. {{!< default lang="fi"}} ?

Also, is it possible to add translations to Ghost navigation items, and tags?

Thanks in advance!

Or if any of you has alternative suggestions how to make a language toggle in the theme, I’m all ears.

…wait, it’s not possible change the language directly in the theme?

Hey tzzo,

Check this out, I think it should help -

David B

Thanks for the reply.

Doesn’t really help with the issue. Yes, strings can be translated and posts can be filtered by language tag, but the theme language can only be set from the admin panel, right?

@tzzo yes it can only be changed through the admin so at the end is useless for a multi-lang site. What you can do is “hardcode” the lang html attribute as suggested in the link that @DavidB sent you:

{{#post}}{{#has tag="de"}}<html lang="de">{{else}}<html lang="en">

Technically, my understanding is that you cannot set the html lang attribute through a parameter as you needed in your initial post.

Here is another discussion about working with multilang templates (is not exactly what you’re looking for but is another way to work with templates in different languages):

Thanks for your reply @Tony!

Yeah, seems quite desperate to be honest. So I guess I’ll have to multiple templates of every page that has plain strings, and add html lang attribute programatically…

There are several ways to do this. You don’t have to have multiple templates, you could also implement Tony’s suggestion by passing the value up to a parent template through a block helper.

Nothing desperate about it - docs are just a little sparse atm, will have those fleshed out soon

// post.hbs

  {{#has tag="de"}}
    {{#contentFor "lang"}}de{{/contentFor}}
    {{#contentFor "lang"}}en{{/contentFor}}
// default.hbs

<html lang="{{block "lang"}}">

Thanks for the reply @John!

But… that only works for setting the lang attribute in post page, right? How about e.g. tag and author pages? And is there an other way to localise plain strings than creating different templates?

Yeah doesn’t work for those, atm, they can only be in 1 fixed language based on the site lang

Not atm unfortunately, that’s outside the scope of the initial implementation

Thank you John for the reply.

Exactly, felt like I was missing something :D.
I think I can parse something together thanks to your replies. Cheers!

+1 upvote for feature to change lang vie theme :angel:.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.