jekyll-multiple-languages-plugin icon indicating copy to clipboard operation
jekyll-multiple-languages-plugin copied to clipboard

Failed to make language.yml and titles.about function well

Open UnicrystalCN opened this issue 4 years ago • 3 comments

I'm following the readme instructions and trying to create an about page for different languages. My goal here is to have different titles for "about" pages in different languages.


Let's say the structure is like this (unrelated files and folders are hidden):

-root -_i18n -en -about.md -zh -about.md en.yml zh.yml -about.md


In en.yml and zh.yml, I defined the variable like the following:

titles:
 -about: About

In /root/about.md

---
layout: page
title: titles.about
permalink: /about/
---

{% translate_file about.md %}

Then no matter what the front matter I define in /root/_i18n/en/about.md and /root/_i18n/zh/about.md, the front matter will directly show up as the normal content. And both the title of the pages (localhost:4000/about and localhost:4000/en/about) are "titles.about", which doesn't look into the values defined in en.yml and zh.yml.

How should I solve the problem? Should I change the layout setting, eg. use some syntax like page.{{title}} to replace page.title?

UnicrystalCN avatar Aug 14 '19 01:08 UnicrystalCN

I believe you would need {%t title%} because right now you're passing in the key, and you want the translated value of that key.

shushugah avatar Oct 02 '19 09:10 shushugah

It's a pretty old issue, but I ran into it and find a solution so here you go :

First, you can't use variable (code between {{ .. }}) nor processed data (code between {% ... %}) in Front Matter. So by default you should not be able to use this plugin to translate Title and other stuff.

But, thanks to this post there's a solution \o/

Go on the post to see the solution, but to explain it, if you put variables or other in double quotes ("{{..}}"), Jekyll won't try to process it and will send that raw code in your page. Based on that kblife made a short plugin-filter (flatify) which post-process that code.

So, with all of that setup, I can use Front Matter that way :

---
layout: page
permalink: /about/
title: "{% t about.title %}"
description: "{% t about.subtitle %}"
background: '/img/bg-about.jpg'
---

Hope it will help someone ^^

RoiArthurB avatar Apr 06 '20 04:04 RoiArthurB

@RoiArthurB God bless you and your parents for giving you birth, and parents of your parents too

sithamet avatar Aug 05 '20 16:08 sithamet