Zum Inhalt springen

Internationalization (i18n)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

The starlight-tags plugin integrates with Starlight’s i18n system and provides built-in translations for:

  • English (en)
  • French (fr)
  • Spanish (es)
  • German (de)

The plugin uses the following translation keys for its UI components:

KeyEnglish Default
starlightTags.totalTagsTotal Tags
starlightTags.tagsAppliedTags Applied
starlightTags.tagCloudTag Cloud
starlightTags.alphabeticalIndexAlphabetical Index
starlightTags.allTagsAll Tags
starlightTags.pagepage
starlightTags.pagespages
starlightTags.pageTagsTags:
starlightTags.taggedPrefixTagged:
starlightTags.relatedTagsRelated Tags
starlightTags.pagesWithTagPages with this tag
starlightTags.relatedrelated
starlightTags.pathPath:
starlightTags.pagination.labelPagination
starlightTags.pagination.pagePage
starlightTags.pagination.ofof
starlightTags.pagination.previousPrevious page
starlightTags.pagination.nextNext page
starlightTags.pagination.itemtagged item
starlightTags.pagination.itemstagged items

You can override any translation by adding entries to your src/content/i18n/ files. This allows you to customize the labels or add support for additional languages.

If you haven’t already, add the i18n collection to your src/content.config.ts:

import { defineCollection } from 'astro:content';
import { docsLoader, i18nLoader } from '@astrojs/starlight/loaders';
import { docsSchema, i18nSchema } from '@astrojs/starlight/schema';
export const collections = {
docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }),
i18n: defineCollection({ loader: i18nLoader(), schema: i18nSchema() }),
};

Create JSON files in src/content/i18n/ for each language you want to customize:

src/content/i18n/en.json
{
"starlightTags.totalTags": "Topics",
"starlightTags.tagsApplied": "Total References"
}
src/content/i18n/fr.json
{
"starlightTags.totalTags": "Catégories",
"starlightTags.tagsApplied": "Références totales"
}

To add a language not included in the plugin’s built-in translations, create a translation file with all the keys:

src/content/i18n/ja.json
{
"starlightTags.totalTags": "タグ総数",
"starlightTags.tagsApplied": "適用されたタグ",
"starlightTags.tagCloud": "タグクラウド",
"starlightTags.alphabeticalIndex": "アルファベット順索引",
"starlightTags.allTags": "すべてのタグ",
"starlightTags.page": "ページ",
"starlightTags.pages": "ページ",
"starlightTags.pageTags": "タグ:",
"starlightTags.taggedPrefix": "タグ付き:",
"starlightTags.relatedTags": "関連タグ",
"starlightTags.pagesWithTag": "このタグのページ",
"starlightTags.related": "関連",
"starlightTags.path": "パス:",
"starlightTags.pagination.label": "ページネーション",
"starlightTags.pagination.page": "ページ",
"starlightTags.pagination.of": "/",
"starlightTags.pagination.previous": "前のページ",
"starlightTags.pagination.next": "次のページ",
"starlightTags.pagination.item": "タグ付きアイテム",
"starlightTags.pagination.items": "タグ付きアイテム"
}

The plugin automatically detects the current locale from Starlight’s routing and displays the appropriate translations. When a translation key is not found for a locale, it falls back to the English default.

All tag-related URLs are automatically localized:

  • Default locale: /tags/authentication/
  • French: /fr/tags/authentication/
  • German: /de/tags/authentication/

This works seamlessly with Starlight’s defaultLocale: 'root' configuration, where the default language has no URL prefix.