百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

polyglot

> 编程语言
开源

:abc: 一个用于 Jekyll 博客的多语言和 i18n 支持工具

495 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

:abc: 一个用于 Jekyll 博客的多语言和 i18n 支持工具

Polyglot

Polyglot is a fast, painless, open-source internationalization plugin for Jekyll blogs. Polyglot is easy to set up and use with any Jekyll project, and it scales to the languages you want to support. With fallback support for missing content, automatic url relativization, and powerful SEO tools, Polyglot allows any multi-language jekyll blog to focus on content without the cruft.

Why?

Jekyll doesn't provide native support for multi-language blogs. This plugin was modeled after the jekyll-multiple-languages-plugin, whose implementation I liked, but execution I didn't.

Installation

Add jekyll-polyglot to your Gemfile if you are using Bundler:

ruby
group :jekyll_plugins do
   gem "jekyll-polyglot"
end

Or install the gem manually by doing gem install jekyll-polyglot and specify the plugin using _config.yml:

yaml
plugins:
  - jekyll-polyglot

Configuration

In your _config.yml file, add the following preferences

yaml
languages: ["en", "sv", "de", "fr"]
default_lang: "en"
exclude_from_localization: ["javascript", "images", "css", "public", "sitemap", "CNAME"]
parallel_localization: true
serial_default_lang: true
url: https://polyglot.untra.io

These configuration preferences indicate

  • what i18n languages you wish to support
  • what is your default "fallback" language for your content
  • what root level files/folders are excluded from localization, based on if their paths start with any of the excluded regexp substrings. (this is different from the jekyll exclude: [ .gitignore ] ; you should exclude files and directories in your repo you dont want in your built site at all, and exclude_from_localization files and directories you want to see in your built site, but not in your sublanguage sites.)
  • whether to run language processing in parallel or serial. Set to false if building on Windows hosts, or if Polyglot collides with other Jekyll plugins. - If parallel_localization collides with other jekyll plugins, this setting makes polyglot build the default language first before processing the other language sites.
  • your jekyll website production url. Make sure this value is set; Polyglot requires this to relative site urls correctly, and to make functioning language switchers.

The optional lang_from_path: true option enables getting the page language from a filepath segment seperated by / or ., e.g de/first-one.md, or _posts/zh_HK/use-second-segment.md , if the lang frontmatter isn't defined.

Netlify _redirects localization

If you are deploying to Netlify and use a _redirects file, you can enable automatic localization of redirects:

yaml
localize_redirects: true
exclude_from_redirect_localization:
  - /signin
  - /app

See Localizing Netlify _redirects for more details.

How To Use It

When adding new posts and pages, add to the YAML front matter:

lang: sv

or whatever appropriate I18n language code the page should build for. And you're done. Ideally, when designing your site, you should organize files by their relative urls.

You can see how the live Polyglot website configures and supports multiple languages, and examples of community language contributions.

Polyglot works by associating documents with similar permalinks to the lang specified in their frontmatter. Files that correspond to similar routes should have identical permalinks. If you don't provide a permalink for a post, make sure you are consistent with how you place and name corresponding files:

_posts/2010-03-01-salad-recipes-en.md
_posts/2010-03-01-salad-recipes-sv.md
_posts/2010-03-01-salad-recipes-fr.md

Organized names will generate consistent permalinks when the post is rendered, and Polyglot will know to build separate language versions of the website using only the files with the correct lang variable in the front matter.

In short:

  • Be consistent with how you name and place your posts files
  • Always give your pages permalinks in the frontmatter
  • Don't overthink it, :wink:

Translation permalink information in page

New in 1.8.0

Whenever page_id frontmatter properties are used to identify translations, permalink information for the available languages is available in permalink_lang. This is useful in order to generate language menus and even localization meta information without redirects!

Sample code for meta link generation:

{% for lang in site.languages %}
  {% capture lang_href %}{{site.baseurl}}/{% if lang != site.default_lang %}{{ lang }}/{% endif %}{% if page.permalink_lang[lang] != '/' %}{{page.permalink_lang[lang]}}{% endif %}{% endcapture %}
  
{% endfor %}

Available and missing translations

New in 1.13.0

Polyglot exposes two arrays on every page describing its translation status:

  • page.available_languages — language codes that have an actual translation of this page.
  • page.missing_languages — languages that don't yet have a translation of this page.

missing_languages is intentionally empty for pages that have no per-language translations at all: a single-source page falls back to identical content for every visitor, so there is nothing missing to flag. Only pages that already have at least one translations report the gaps.

Combine with page.rendered_lang to also flag fallback content on the page itself.

Using different permalinks per language

New in 1.7.0

Optionally, for those who may want different URLs on different languages, translations may be identified by specifying a page_id in the frontmatter.

If available, Polyglot will use page_id to identify the page, and will default to the permalink otherwise.

As an example, you may have an about page located in /about/ while being in /acerca-de/ in Spanish just by changing the permalink and specifying a page_id that will link the files as translations:

markdown
---
title: About
permalink: /about
lang: en
page_id: about
---
This is us!
markdown
---
title: Acerca de
permalink: /acerca-de
lang: es
page_id: about
---
Estos somos nosotros!

Additionally, if you are also using the jekyll-redirect-from plugin, pages coordinated this way will automatically have redirects created between pages. So /es/about will automatically redirect to /es/acerca-de and /acerca-de can redirect to /about. If you use this approach, be sure to also employ a customized redirect.html.

As of version 1.12, Polyglot also properly supports redirect_from frontmatter across sublanguages. When you add redirect paths to pages in non-default languages, Polyglot will correctly scope those redirects to each language's prefix, preventing duplicate redirects and ensuring proper routing.

Fallback Language Support

Lets say you are building your website. You have an /about/ page written in english, german and swedish. You are also supporting a french website, but you never designed a french version of your /about/ page!

No worries. Polyglot ensures the sitemap of your english site matches your french site, matches your swedish and german sites too. In this case, because you specified a default_lang variable in your _config.yml, all sites missing their languages' counterparts will fallback to your default_lang, so content is preserved across different languages of your site.

Smart hreflang Generation

Polyglot only generates hreflang tags for languages that have actual translations. This improves SEO correctness by not advertising language alternatives that don't actually exist.

For example, if you have /about.html in English and Spanish but not French:

  • The English page gets hreflang="en", hreflang="es", and hreflang="x-default"
  • The Spanish page gets the same hreflang tags
  • No hreflang="fr" is generated, even though a French fallback page exists

This behavior:

  • Generates pages for all languages (fallback content is still served)
  • Only advertises translations that actually exist via hreflang tags
  • Always includes hreflang for the default language and x-default

Translation detection works via:

  1. page_id matching: Documents with the same page_id frontmatter are considered translations
  2. permalink matching: Documents with matching permalinks (and different lang) are considered translations
  3. Searches both collections and standalone pages: The {% I18n_Headers %} tag searches site.collections and site.pages

Relativized Local Urls

No need to meticulously manage anchor tags to link to your correct language. Polyglot modifies how pages get written to the site so your french links keep visitors on your french blog.

markdown
---
title: au sujet de notre entreprise
permalink: /about/
lang: fr
---
Nous sommes un restaurant situé à Paris . [Ceci est notre menu.](/menu/)

becomes

xml

  
au sujet de notre entreprise

  
Nous sommes un restaurant situé à Paris . Ceci est notre menu.

Notice the link ... directs to the french website.

Even if you are falling back to default_lang page, relative links built on the french site will still link to french pages.

Relativized Absolute Urls

If you defined a site url in your _config.yaml, Polyglot will automatically relativize absolute links pointing to your website directory:

markdown
---
lang: fr
---
Cliquez [ici]({{site.url}}) pour aller à l'entrée du site.

becomes

xml

Cliquez ici pour aller à l'entrée du site.

Canonical URL Handling

For proper canonical URL handling on multilingual sites, we recommend using Polyglot's {% I18n_Headers %} tag for canonical URLs instead of jekyll-seo-tag's default canonical output. This provides intelligent canonical URL generation that:

  • Points to the translated URL for pages with actual translations
  • Points to the default language URL for fallback pages (pages without translations)
  • Properly handles the page_id and permalink matching for translation detection

Setup with jekyll-seo-tag:

If you're using jekyll-seo-tag, you can disable its canonical output and let Polyglot handle it:

liquid
{% seo canonical=false %}
{% I18n_Headers %}

The canonical=false option is available in jekyll-seo-tag v2.9.0+

Fallback Canonical Behavior:

To have fallback pages (pages without translations) point their canonical URL to the default language version, add to your _config.yml:

yaml
fallback_canonical_to_default_lang: true

With this option enabled:

  • Pages with actual translations: canonical points to the translated URL (e.g., /es/sobre-nosotros/)
  • Fallback pages (no translation): canonical points to the default language URL (e.g., /about/ instead of /es/about/)

This improves SEO by:

  • Preventing search engines from indexing duplicate fallback content under multiple language URLs
  • Consolidating SEO authority to the original content
  • Signaling to search engines which version is the authoritative source

Note: hreflang URLs pointing to the default language or x-default are intentionally NOT relativized, as they should always point to the canonical language-specific URLs.

Localizing Netlify _redirects

New in 1.13.0

When using Polyglot with Netlify, redirect rules defined in a Netlify _redirects file will get relativized (e.g., /github becomes `/f

Issues· 6 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyi18njekylljekyll-blogmulti-language-blogs

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言