eleventy-plugin-i18n
eleventy-plugin-i18n copied to clipboard
Extend dictionaries on a per-page basis
As proposed in #23 I extended this plugin instead of providing a custom implementation: easier to see what's going on!
This adds the ability to extend the dictionary on a per-page basis by reading the available data in the context (e.g. data added in the frontmatter) and pulling it in under the i18n
key.
This lets you add translations in the frontmatter for a specific page that might use a layout shared across languages, enabling you to add one-off translations that won't clutter up your base dictionaries.
Example
📄 src/en/about.njk
---
title: About
layout: layouts/about.njk
i18n:
favouriteFood: Lasagna
---
Hi, I am an example.
📄 src/fr/about.njk
---
title: À Propos
layout: layouts/about.njk
i18n:
favouriteFood: Lasagnes
---
Bonjour, je suis un exemple.
📄 src/_includes/layouts/about.njk
<aside>😋 = {{ 'favouriteFood' | i18n }}</aside>
The favouriteFood
key does not exist in en.json
or fr.json
but can be accessed by adding it to each localised content file.