# MultIanguage switcher

**URL:** <https://forum.ghost.org/t/multianguage-switcher/29698>\
**Category:** Routing\
**Created:** [April 21, 2022, 2:34pm UTC](https://forum.ghost.org/t/multianguage-switcher/29698 "2022-04-21T14:34:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Svetlana\_Tsupryk](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/svetlana_tsupryk/32/10416_2.png) [@Svetlana\_Tsupryk](https://forum.ghost.org/u/Svetlana_Tsupryk)\
**Post date:** [April 21, 2022, 2:34pm UTC](https://forum.ghost.org/t/multianguage-switcher/29698/1 "2022-04-21T14:34:12Z")

</div>

Is there any way to change language from the user interface using js or it can be done only from the admin panel?  
I need it for a multi-lang site which is made by collections.

---

<div class="post-metadata">

**Author:** ![TheRoyalFig](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/theroyalfig/32/27771_2.png) [@TheRoyalFig](https://forum.ghost.org/u/TheRoyalFig)\
**Post date:** [April 21, 2022, 7:21pm UTC](https://forum.ghost.org/t/multianguage-switcher/29698/2 "2022-04-21T19:21:25Z")

</div>

The way to do this is to use the `{{#contentFor}}` helper.

> **[Ghost Handlebars Theme Helpers: block & contentFor](https://ghost.org/docs/themes/helpers/block/)**
>
> Create templates that inherit reusable templates with handlebars block and contentFor helpers. Read more about Ghost themes! 👻

In relation to setting up a multilanguage site, please see this tutorial: [Tutorials](https://ghost.org/docs/tutorials/multi-language-content/#create-templates-for-translated-collections)

There’s a section there on how to set the language using this helper. The other useful tool here is to tag content with the language code, which is also discussed in the tutorial.

---

<div class="post-metadata">

**Author:** ![Svetlana\_Tsupryk](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/svetlana_tsupryk/32/10416_2.png) [@Svetlana\_Tsupryk](https://forum.ghost.org/u/Svetlana_Tsupryk)\
**Post date:** [April 22, 2022, 12:54pm UTC](https://forum.ghost.org/t/multianguage-switcher/29698/3 "2022-04-22T12:54:02Z")

</div>

Thank you. I followed [this](https://ghost.org/docs/tutorials/multi-language-content/) tutorial and was managed to change html lang using this

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

```

and

```auto
{{!< default}}

{{#contentFor "lang"}}{{@site.locale}}{{/contentFor}}

{{!< default}}

{{#contentFor "lang"}}de{{/contentFor}}

```

It is shown right in console, but text is still on the default language not from files `locales/de.json` . When language is changed from admin panel all is in correct language.  
I can not understand why changing doesn`t change anything like from the admin panel? Is it my mistake? It should work the same? For me it looks like this property is ignored and used admin value.

---

<div class="post-metadata">

**Author:** ![TheRoyalFig](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/theroyalfig/32/27771_2.png) [@TheRoyalFig](https://forum.ghost.org/u/TheRoyalFig)\
**Post date:** [April 22, 2022, 1:09pm UTC](https://forum.ghost.org/t/multianguage-switcher/29698/5 "2022-04-22T13:09:43Z")

</div>

The locales files aren’t actually for multi-language sites–they’re only for translating templates from one language to another on single language sites.

Instead, to translate for multi-language **content** , you need to use a combination of custom routing and tags.

With routing, you’d navigate to different index files based on the URL path. For example, [yoursite.com/es](http://yoursite.com/es) would load the `index-es.hbs` file for Spanish.

For content, you’d need to tag it as #es. Then, in your `post.hbs` file, you can use the `{{#has}}` helper to look for the `#es` tag and translate accordingly.

These techniques are explained in more detail in the tutorial:

> **[Tutorials](https://ghost.org/tutorials/)**
>
> A library of resources to help you to customize, build, and create beautiful Ghost sites

But, creating a multi-language site with Ghost is not a trivial task, so let me know if there’s anything that remains unclear. 😄

---

<div class="post-metadata">

**Author:** ![Svetlana\_Tsupryk](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/svetlana_tsupryk/32/10416_2.png) [@Svetlana\_Tsupryk](https://forum.ghost.org/u/Svetlana_Tsupryk)\
**Post date:** [April 22, 2022, 1:56pm UTC](https://forum.ghost.org/t/multianguage-switcher/29698/6 "2022-04-22T13:56:24Z")

</div>

Thanks a lot!!! 😀  
Now I understand that changing the language from admin and from this tutorial, shouldn’t work the same. 🥳 It doesn’t for a multi-language site, it works only for content.  
So if I want to translate other things(blocks, buttons, banners) this doesn’t work  
`{{#contentFor "lang"}}es{{/contentFor}}` because there a word **content** 😆  
I should make a custom copy of everything with stable es language in ich or find some other elegant decision?

---

<div class="post-metadata">

**Author:** ![TheRoyalFig](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/theroyalfig/32/27771_2.png) [@TheRoyalFig](https://forum.ghost.org/u/TheRoyalFig)\
**Post date:** [April 22, 2022, 3:01pm UTC](https://forum.ghost.org/t/multianguage-switcher/29698/7 "2022-04-22T15:01:13Z")

</div>

The way I approach it is to make copies of your index page and route to the different versions via custom routing. This is necessary because on an index page, there’s no tag you can pull from to determine the language.

For your post page, I would switch the text content based on tags. For example:

```handlebars
<p>{{#has tag="#es"}}Escrito por{{#else}}Written by{{/has}} {{primary_author.name}}</p>

```

You can do the same thing with buttons and other components.

---

<div class="post-metadata">

**Author:** ![Svetlana\_Tsupryk](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/svetlana_tsupryk/32/10416_2.png) [@Svetlana\_Tsupryk](https://forum.ghost.org/u/Svetlana_Tsupryk)\
**Post date:** [April 22, 2022, 3:37pm UTC](https://forum.ghost.org/t/multianguage-switcher/29698/8 "2022-04-22T15:37:58Z")

</div>

I am very appreciated you for help. We have different structure and this variant doesn’t suit but now everything is much clear for me. Thanks!
