Polyglot 1.8.0 - Liberação de contribuições comunitárias

Fique animado com o Jekyll-Polyglot 1.8.0, que tem algumas melhorias de recursos e reconhece a documentação e contribuições da comunidade!

Um novo recurso é fornecer links permanentes específicos ao idioma das páginas e manter sua associação com outras páginas relativas. Este novo recurso foi novamente aprimorado por antoniovazquezblanco, que é um cavalheiro e estudioso.

geração de mapa de site e SEO i18n

Este lançamento também reconhece a qualidade sitemap.xml y robots.txt solução fornecida por jerturowetz. Este site agora demonstra e captura mais poder de SEO ao usá-los para ser rastreável como um site jekyll estático por provedores de pesquisa. Veja os arquivos do site de exemplo aqui.

jekyll :polyglot :post_write hook

Github user obfusk contribuiu com pequeno PRs alguns anos atrás:

Com o poliglota :site, :post_write como estes são executados para cada processo filho:

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

Esta versão adiciona um personalizado :post_write hook que é executado exatamente uma vez, depois que todos os idiomas foram processados (whether or not parallel_localization is used):

Jekyll::Hooks.register :polyglot, :post_write do |site|
  # faça algo incrível aqui!
end

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

Obfusk 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.

Variáveis traduzidas

Polyglot permite que você tenha diferentes páginas para diferentes idiomas em seu site Jekyll. Por exemplo, você pode ter uma página about.md em inglês e outra about.md em espanhol com layouts completamente diferentes. Mas se você quiser ter o mesmo layout para todas as páginas, você pode usar variáveis traduzidas. Esta é uma maneira de ter diferentes dados para diferentes idiomas em seu site Jekyll, mas usando o mesmo layout para todos os idiomas.

Como exemplo, usarei um site modelo criado com Polyglot.

Compartilhando um layout entre páginas

Nesse site eles têm uma página sobre para cada idioma, no caso deles inglês em _pages/en-us/about.md e português brasileiro em _pages/pt-br/about.md. Em ambas as páginas podemos ver que elas têm as mesmas chaves no frontmatter, mas algumas com valores diferentes. Ambos os arquivos apontam para o mesmo layout, about, e este layout usa os valores no frontmatter para renderizar a página.

Por exemplo, a chave subtitle na página em inglês tem o valor subtitle: <a href='#'>Affiliations</a>. Address. Contacts. Moto. Etc. e na página em português brasileiro tem subtitle: <a href='#'>Afiliações</a>. Endereço. Contatos. Lema. Etc.. Essa informação no layout é usada dessa forma:

{{ page.subtitle }}

O mesmo vale para o conteúdo abaixo do frontmatter em ambos os arquivos, que é simplesmente usado no layout dessa forma:

{{ content }}

Polyglot renderizará automaticamente a página com os valores corretos para o idioma atual.

Compartilhando um layout entre páginas com dados traduzidos

Para o subtitle da página eles usaram pares chave: valor no frontmatter, mas às vezes queremos usar esses mesmos pares em diferentes partes do site. Por exemplo, se quisermos usar o mesmo subtitle no about.md e em outra página, teríamos que repetir o mesmo par no frontmatter de ambas as páginas. Isso não é ideal porque se quisermos mudar o subtitle teríamos que mudá-lo em dois lugares. É aí que entram os dados traduzidos. Você pode criar um arquivo como _data/:lang/strings.yml, um para cada idioma, e o Polyglot trará essas chaves sob site.data[:lang].strings.

Por exemplo, no site modelo existem dois arquivos, _data/en-us/strings.yml e _data/pt-br/strings.yml. No primeiro arquivo eles têm:

latest_posts: latest posts

E no segundo arquivo eles têm:

latest_posts: últimas postagens

Dessa forma, eles podem usar a chave latest_posts no layout assim:

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

O que obterá corretamente o valor para a variável latest_posts definida no arquivo _data/:lang/strings.yml para o idioma atual.

Definindo qual variável usar no frontmatter

Agora, se você quiser definir essa variável no frontmatter da página, isso fica um pouco mais complicado. Uma possível solução é verificar se o valor da variável tem um . nele e, se tiver, usar o valor no arquivo _data/:lang/strings.yml. É assim que você faria:

{% 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 }}

Isso funcionará, por exemplo, se frontmatter_var = blog.title.

Agora, se você precisar verificar se a string de tradução (neste caso blog.title) realmente existe no arquivo _data/:lang/strings.yml antes de usá-la, você terá que criar um plugin para verificar se a variável existe no arquivo _data/:lang/strings.yml e, se existir, usá-la, caso contrário, retornar para qualquer valor que você quiser. Não entrarei em detalhes sobre como fazer isso, mas mostrarei como usá-lo. Você pode ver o código do plugin aqui.

{% 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 and Simplified Chinese language support

The Polyglot website has been updated with support for Chinese!

This is made possible by aturret, who contributed numerous bugfixes to the plugin, the website, and an entirely new site translation.

Additionally, jekyll-polyglot 1.6.0 is now available from rubygems.

Fix for relativization of frozen strings

Polyglot used String::gsub! which mutates a .frozen? string. This has now been fixed to duplicate the cloned string before modifying it.

Fix for site navigation not being translated

A typo in the html on the site layout prevented the previous page navigation from being translated correctly.

Support for Chinese Language

With a big 谢谢 of support and appreciation to aturret, polyglot.untra.io now supports a zh-CN Simplified Chinese translation!

Polyglot website is now in Korean

The Polyglot website has been updated with support for Korean!

This is made possible by SalinatedCoffee, who contributed these changes. 프로젝트를 도와 주셔서 고마워요!