Polyglot 1.8.0 - Community Contributions Release

Get excited for Jekyll-Polyglot 1.8.0, which has a few feature improvements and recognizes community documentation and contributions!

One new feature is to give pages language specific permalinks and to retain their association to other relative pages. This new feature is again improved by antoniovazquezblanco, who is a gentleman and a scholar.

sitemap generation & i18n SEO

This release also recognizes the quality sitemap.xml and robots.txt solution provided by jerturowetz. This website now demonstrates and captures more SEO power by using these to be crawlable as a static jekyll website by search providers. See the example website files here.

jekyll :polyglot :post_write hook

Github user obfusk contributed a tiny PR a few years back:

With polyglot :site, :post_write like these run for each child processes:

Jekyll::Hooks.register :site, :post_write do |site|

This release adds a custom :post_write hook that runs exactly once, after all languages been processed (whether or not parallel_localization is used):

Jekyll::Hooks.register :polyglot, :post_write do |site|
  # do something amazing here!

This feature is helpful for complex jekyll static sites that make additional use of jekyll hook plugins.

She also contributed a fix for additional logging when language subprocesses crash. Thanks for this contribution!

localized variables and portuguese translation.

george-gca is a talented and awesome guy, contributing an entire blogpost on how best to localize rich text from site data. He also provided a site brazilian translation.

Localized variables

Polyglot allows you to have different pages for different languages in your Jekyll site. For example, one could have a page about.md in English and another about.md in Spanish with completely different layouts. But if you want to have the same layout for both pages, you can use localized variables. This is a way to have different data for different languages in your Jekyll site, but using the same layout for all languages.

As an example I will use a template site created with Polyglot.

Sharing a layout between pages

In that site they have an about page for every language, in their case english in _pages/en-us/about.md and brazilian portuguese in _pages/pt-br/about.md. In both pages we can see that they have the same keys in the frontmatter, but some with different values. Both files point to the same layout, about, and this layout uses the values in the frontmatter to render the page.

For example, the subtitle key in the english page has the value subtitle: <a href='#'>Affiliations</a>. Address. Contacts. Moto. Etc. and in the brazilian portuguese page it has subtitle: <a href='#'>Afiliações</a>. Endereço. Contatos. Lema. Etc.. To use this information in the layout, it is used like this:

{{ page.subtitle }}

The same goes for the content below the frontmatter in both files, which is simply used in the layout like this:

{{ content }}

Polyglot will automatically render the page with the correct values for the current language.

Sharing a layout between pages with localized data

For the subtitle of the page they used key: value pairs in the frontmatter, but sometimes we want to use these same pairs in different parts of the site. For example, if we want to use the same subtitle in the about.md and in another page, we would have to repeat the same pair in the frontmatter of both pages. This is not ideal because if we want to change the subtitle we would have to change it in two places. This is where localized data comes in. You can create a file like _data/:lang/strings.yml, one for each language, and Polyglot will bring those keys under site.data[:lang].strings.

For example, in the template site there are two files, _data/en-us/strings.yml and _data/pt-br/strings.yml. In the first file they have:

latest_posts: latest posts

And in the second file they have:

latest_posts: últimas postagens

This way, they can use the latest_posts key in the layout like this:

{{ site.data[site.active_lang].strings.latest_posts }}

Which will correctly get the value for the latest_posts variable defined in the file _data/:lang/strings.yml for the current language.

Defining which variable to use in the frontmatter

Now if you want to define this variable in the frontmatter of the page, this gets a little bit trickier. One possible solution is to check if the value of the variable has a . in it, and if it does use the value in the file _data/:lang/strings.yml. This is how you would do it:

{% if frontmatter_var contains '.' %}
  {% assign first_part = frontmatter_var | split: '.' | first %}
  {% assign last_part = frontmatter_var | split: '.' | last %}
  {% capture result %}{{ site.data[site.active_lang].strings[first_part][last_part] }}{% endcapture %}
{% endif %}

{{ result }}

This will work, for example, if frontmatter_var = blog.title.

Now, if you need to check if the localization string (in this case blog.title) actually exists in the file _data/:lang/strings.yml before using it, you’ll have to create a plugin to check if the variable exists in the file _data/:lang/strings.yml and if it does, use it, otherwise fallback to any value you want. I will not go into detail on how to do this, but I will show you how to use it. You can see the code for the plugin here.

{% if frontmatter_var contains '.' %}
  {% capture contains_localization %}{% localization_exists {{ frontmatter_var }} %}{% endcapture %}
  {% if contains_localization == 'true' %}
    {% assign first_part = frontmatter_var | split: '.' | first %}
    {% assign last_part = frontmatter_var | split: '.' | last %}
    {% capture result %}{{ site.data[site.active_lang].strings[first_part][last_part] }}{% endcapture %}
  {% else %}
    {% capture result %}fallback value{% endcapture %}
  {% endif %}
{% endif %}

{{ result }}

Polyglot 1.7.0 and page_id front-matter for different permalinks by language

I’m excited to announce Jekyll-Polyglot 1.7.0, which has a new feature to give pages language specific permalinks and to retain their association to other relative pages.

This new feature is provided by antoniovazquezblanco, who is a gentleman and a scholar.

Polyglot associates pages by matching their permalinks or filenames. However some site translations may instead desire pages with unique permalinks.

Polyglot already coordinates multiple copes of the same document across different languages. So keying off of a different property like page_id is no different than keying off of the permalink.

Using a page_id to coordinate similar pages with different permalinks ensures that custom permalinks can still be seen on language specific sites.

The challenge with unique permalinks comes with relativizing those urls. Polyglot avoids this problem entirely by suggesting consistent permalinks.

To help with this, polyglot sets redirect_from hidden frontmatter on these pages, listing the unique permalinks of corresponding pages.

When using the jekyll-redirect-from plugin, that frontmatter will be picked up, and intelligent redirects made to the page’s custom permalink.

To see this in action, visit this page with a long permalink in different languages.

Other bug fixes

  • This release should have a fix for #151 and #184, preventing crashes on startup when calling other jekyll commands.

Polyglot 1.6.0 以及简体中文支持

Polyglot 网站 现已更新支持中文!

本次更新由 aturret 带来。他做出了包括插件 bug 修正、网站 bug 修正,以及整个网站的中文完全翻译在内的诸多贡献。

此外,现在可以通过 RubyGems 下载 jekyll-polyglot 1.6.0 了。


Polyglot 先前使用 String::gsub! 进行字符串修正,导致在修正 .frozen? 字符串时出现错误。现在已通过在修改之前复制一份克隆的字符串修复此问题。


之前,网站布局中 html 中存在拼写错误,导致无法正确翻译之前的翻页导航。现已修复。


要向 aturret 的支持和欣赏说声大大的谢谢, polyglot.untra.io 现在支持 zh-CN 简体中文翻译了!

Polyglot 网站朝鲜语支持上线

Polyglot 网站 现已更新提供对朝鲜语的支持!

感谢 SalinatedCoffee 提供翻译贡献!프로젝트를 도와 주셔서 고마워요!