A simple approach to internationalization for Jekyll websites.
bundle install --path vendor/bundle
inside the cloned directory.bundle exec jekyll build
.transifex-source-file.yml
) has been automatically generated.{% translate This is a new string. %}
_site
directory includes generated content for each supported language._data/languages/
directory.translate: true
in the Jekyll front matter for any page that you want to be translated..tx/config
) demonstrates how this can be integrated into an existing project to automate the push and pull of translation updates.index.html
and creating new pages. Once you understand how everything works, you can copy the plugins and data structure into your own project.Every {% translate %}
tag is added to the source file, but translated pages for that content will only be generated when translate: true
is set in the page's front matter. This gives you an easy way to get started on new translations without deploying them right away.
A custom language
variable is added to the front matter for translated pages. You can use this to make adjustments to links or images:
<a href="/{% if page.language %}{{ page.language }}/{% endif %}">Home</a>
<img src="header-image-{{ page.language | default: "en" }}.png" />
A custom src_dir
variable is also added to the front matter for translated pages. This gives translated pages an easy way to reference the location of the canonical content.
For example, let's say you want to implement a language selector that appears on pages with translated content. Here's how you can do that using the jekyll-simple-i18n plugins alongside built-in Jekyll functionality like Liquid and Data Files:
{% if page.translate %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" aria-label="Change Language" id="language-selector"><i class="fas fa-globe"></i> {{ page.language | default: "EN" }} <span class="caret"></span></a>
<ul class="dropdown-menu" aria-labelledby="language-selector">
{% if page.src_dir %}
{% assign dir = page.src_dir %}
<li><a data-lang="en" href="{{ dir }}">English</a></li>
{% else %}
{% assign dir = page.dir %}
{% endif %}
{% assign languages = site.data.languages | sort %}
{% for language_hash in languages %}
{% assign iterated_language = language_hash[0] %}
{% if page.language != iterated_language %}
<li><a data-lang="{{ iterated_language }}" href="/{{ iterated_language }}{{ dir }}">{{ site.data.language_map[iterated_language] }}</a></li>
{% endif %}
{% endfor %}
</ul>
</li>
{% endif %}
Copyright 2019 Signal
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.