-
Notifications
You must be signed in to change notification settings - Fork 45
Translation of Layouts
The liquid tags of this plugin can be used within layouts without problems. However, since layouts are used by pages and posts which hold the necessary YAML front-matter, developers ought to be more cautious naming language keys inside layouts.
For instance, if you declare a different language subset
for each page containing a title
string, you can access the page's title inside the layout used by the page very easily. You can also devote a specific language subset, e.g. common
to common translations that apply for each page that can be accessed without the page's subset
.
<!DOCTYPE html>
<html>
<head lang="{{ page.language }}">
<meta charset="utf-8">
<title>{% t 'title' %} | {{ site.title }}</title>
</head>
<body>
{{ content }}
<p><small>{% t 'common.footnote' %}</small></p>
</body>
</html>
As a sidenote, the variable page.language
provides access to the currently rendered language of the page. In the case that the t
liquid tag cannot find the specified key within the page's subset
, it will attempt to look it up in the language root. This is why it is possible to devote a separate subset for page-common translations.
The lang.yml
file from the previous example needs to be complemented by the language-specific footnote
keys:
---
en:
common:
footnote: Copyright (c) Example home page 2015. All rights reserved.
de:
common:
footnote: Copyright (c) Beispielhomepage. Alle Rechte vorbehalten.