kurtsson / jekyll-multiple-languages-plugin

I18n support for Jekyll and Octopress
MIT License
923 stars 201 forks source link

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

Open UnicrystalCN opened 5 years ago

UnicrystalCN commented 5 years ago

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?

shushugah commented 4 years ago

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.

RoiArthurB commented 4 years ago

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 ^^

sithamet commented 4 years ago

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