I18n and custom theme


#1

Hello!

I am developing internationalized ghost theme. And there are certain things that I need to switch depending on current locale. For example, I need to have language switcher in a navigation bar, with highlighted current language.
I wanted to use a custom helper, but it seems that now it’s not possible to add it via experimental Apps-feature like described here https://github.com/TryGhost/Ghost/wiki/Apps-Getting-Started-for-Ghost-Devs#handlebars-helpers
So are there any options to achieve my goal? Something like {{has locale=“en”}}

Thanks!


#2

Currently the site language is selected by the admin in settings. To allow site visitors to choose it themselves, there are community proposals for multilingual Ghost sites, still waiting for interested people to prepare pull requests, etc. See [i18n] Multi-lingual Content Publishing (Mockups) · Issue #8509 · TryGhost/Ghost.

For the time being, there is the workaround of installing several Ghost sites, one for each language (e.g. example.com/es, example.com/fr, etc.). See Set Up Multilingual Ghost.org Blog.

Maybe the devs can say, but it looks like the {{has}} helper doesn’t include a locale attribute at this moment. Of course I agree it would be a nice addition.

The {{lang}} helper gives the language code: en, fr, etc. If you prefer to get the full words English, Français, etc., a possibility is to use for example a {{t}} translation helper {{t "English"}} in the .hbs theme templates, and lines like the following in the translation files (en.json, fr.json…):

"English": "English",
"English": "Français",

#3

Thanks for the reply!

That is the way I am implementing it. But I have a multicountry blog, and one of the countries is bilingual. So I want to have a link in the header to another language site that will be visible only for a particular locale.

Maybe I will find some workaround with translations file.


#4

Yes, that’s likely, since translated strings can include unescaped HTML such as links by using triple braces:
{{{t "..."}}}


#5

hey guys, I wonder what if need fully sunchronized two-language blog – should I go with Ghost? I know that I can use third-party tranlsation widgets like Weglot or Localizer, though I would prefer something like WPML in Wordpress or native “cultures” in EnduroJS

babel

So can I?


#6

@sorokinvj That’s more like the proposal Multi-lingual Content Publishing - Ideas - Ghost Forum, and issue [i18n] Multi-lingual Content Publishing (Mockups) · Issue #8509 · TryGhost/Ghost, to be developed.


#7

Thanks!

From your experienced developer opinion – is it hard to handle issue in Ghost? If I decide to do it – what crucial steps should I undertake? Right now it is just the url handlng that bothers me most, other things like ID + language seems to be not so hard to implement.


#8

@sorokinvj It depends on the different issues. I think that one—multilingual Ghost site—can take time because, in the case of open source, people are busy with many other things, work, family, etc. However, like you, several people have already expressed their interest in contributing to that project. :+1:

In my humble opinion, open source works best when, not just one contributor, but multiple people—developers or not—are welcome to contribute ideas, designs, code, testing, etc. The Ghost team usually reviews contributions and gives guidance. So, rather than waiting for someone, those interested in any particular issue can start brainstorming possible solutions, defining the main goals, dividing these into many smaller tasks that people can contribute to, and so on.

Or, for the small tasks, it can be as well like the good old, interesting open source read, A tale of two developers. :wink:


#9

It’s worth noting that the Ghost core team is working on internal projects that will make multi-language sites easier. The first stepping stone to this is the “Ghost’s Channels” project that would enable you to section your site via tag, that would open up the possibility of using #lang tags on posts to separate different languages.

There is also the “Nested/hierarchical tags, subtags” project that is in the pipeline that would allow more flexibility with language tags.

As the above two projects develop we also have plans for improving the UI and allowing customisation to better expose various “collections” of content. The idea being to make Ghost much more powerful and flexible, using tags and private tags to provide site structure.

So, while there is no specific multi-language support planned we’re definitely working on underlying improvements that will lead to multi-lingual sites being easier to work with.

In the meantime, the recommended approach is definitely to run a separate Ghost blog for each language and implementing some JS or very basic (even web-server level) server-side code for the redirects and/or cookies to remember a user’s selected language.