Table of Contents
multilang-core
Note: The options API is still evolving; expect tweaks as the project grows.
What it does
multilang-core adds Eleventy’s built-in I18nPlugin, builds translation collections keyed by translationKey, and registers i18n filters for looking up localized counterparts in templates. It shares language normalization with sitemap-core through a common langNormalization helper in core/helpers.js.
Defaults
defaultLanguage:”en”if not provided.errorMode:”allow-fallback”(passed to Eleventy’s I18n plugin).- Language resolution:
page.data.lang→page.data.language→defaultLanguage.
Options
| Option | Type | Default | Description |
|---|---|---|---|
defaultLanguage |
string | ”en” |
Primary locale, used for fallbacks and isDefaultLang flags. |
languages |
object or array | — | Language definitions. Object { en: {}, nl: {} } or array [‘en’, ‘nl’]. Arrays are normalized to objects. |
All three — multilingual: true, a truthy defaultLanguage, and a non-empty languages map — must be set for this module to load.
How it works
-
I18n plugin.
Registers Eleventy’s
I18nPluginwith the provideddefaultLanguageanderrorMode, so locale-aware URLs and filters are available. -
Translation collections.
Builds two collections from pages that have a
translationKey:collections.translations— an array. Each entry is a safe copy of the page withlocale: { translationKey, lang, isDefaultLang }plus page metadata (url, data, file info).collections.translationsMap— a map keyed bytranslationKey, then by language code. Each entry holds{ title, url, lang, isDefaultLang, data }.
-
Filters.
Three filters for looking up translations in templates:
i18nTranslationsFor(page, collections.translations)— all siblings for the page’stranslationKey.i18nTranslationIn(page, collections.translations, lang)— specific language variant, ornull.i18nDefaultTranslation(page, collections.translations)— default-language variant, ornull.
-
Sitemap integration.
Shares the
langNormalizationhelper (fromcore/helpers.js) with sitemap-core, so per-language sitemaps and hreflang alternates resolve against the same normalized language map.
Rendering alternate links
Use translationsMap in your layout to render hreflang links:
{% set t = collections.translationsMap[translationKey] %}
{% if t %}
{% for lang, entry in t %}
<link rel=”alternate” hreflang=”{{ entry.lang }}” href=”{{ entry.url }}”>
{% if entry.isDefaultLang %}<link rel=”alternate” hreflang=”x-default” href=”{{ entry.url }}”>{% endif %}
{% endfor %}
{% endif %}
Tips
- Every localized page should set both
translationKeyandlangin front matter. WithouttranslationKey, the page won’t appear in translation collections. - Keep your default-language page present — it powers the
x-defaultalternate. - When
multilingual: trueand alanguagesmap is set, sitemap-core emits a sitemap index and per-locale sitemaps automatically. - See Build a Multilingual Baseline Site for a step-by-step setup with hreflang examples.
Peer deps
None — uses Eleventy’s built-in I18n plugin.
Previous: head-core
Next: navigator-core