-
Notifications
You must be signed in to change notification settings - Fork 45
YAML front matter
Every page or post, that needs to be translated must either have a language
key or a languages
array inside its YAML front-matter. Additionally, it may also have an subset
key which tells the plugin to traverse further into the language data. This allows for an abridged access of language strings within the page or post.
So if you want to print out home.welcome
, you can abbreviate that to welcome
if you have the subset
key set to home
in the YAML front-matter. Also works with dot-notation, e.g. home.welcome.heading
becomes welcome.heading
. You can also have dot-notation in the subset
key by the way.
---
layout: default
languages:
- en
- de
subset: home
---
<h1>{% t 'welcome' %}</h1>
<p>{% t 'message' %}</p>
Upon build, the plugin will create two separate translations into /en
and /de
subdirectories within the destination directory with an identical filename.
Provided that language_data
is set to the default data.lang.%%
, the t
language tag will print out the strings data.lang.en.welcome
and data.lang.en.message
as well as data.lang.de.welcome
and data.lang.de.message
.
For this example, only one language file, lang.yml
living in the _data
directory is needed:
---
en:
home:
welcome: Welcome to my example home page
message: This is my example home page powered by the Jekyll language plugin.
de:
home:
welcome: Willkommen auf meiner Beispielhomepage
message: Dies ist meine Beispielhomepage getrieben vom Jekyll-Sprachplugin.
By default, the plugin will create a subdirectory for each language within the destination directory. For the example above, two subdirectories are created, /en
and /de
. You can override this behavior by using permalinks. Permalinks work normally except the :language
placeholder is available additionally.
permalink: /:language/path/to/file.html
Currently, localized URLs only work with pages since I don't see an inherent need to make it work with posts which have their own slug
mechanism.
For every page that has the subset
key set in its front-matter, the plugin will make every translation (key-value) within that subset available as a t.
-prefixed placeholder. However, there is no support for recursive subsets as there is in the t
translation liquid tag.
Add the following line to the YAML front-matter of the page from the above example:
permalink: /:language/:t.slug.html
Then, extend the language file by the following translations:
en:
home:
slug: home
de:
home:
slug: start