Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend dictionaries on a per-page basis #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chriskirknielsen
Copy link

@chriskirknielsen chriskirknielsen commented Aug 22, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant