Astro I18n screenshot

Astro I18n

Updated: 23 Jan 2024
260 Stars

A TypeScript-first internationalization library for Astro.

Overview:

The astro-i18n internationalization library offers features such as lightweight design, internationalized routing, type-safety, autocompletion, support for plurals, context, interpolations, and formatters. It is specifically built for Astro, providing compatibility with Astro island.

Features:

  • Lightweight: Designed to be lightweight for efficient performance.
  • Internationalized Routing: Supports internationalized routing.
  • Type-Safety and Autocompletion: Generates project-specific types for type-safety and autocompletion.
  • Plurals, Context, Interpolations, and Formatters: Provides support for plurals, context, interpolations, and formatters.
  • Built for Astro: Specifically developed for Astro framework.
  • Astro Island Compatible: Compatible with Astro island.

Installation:

To install the astro-i18n library, follow these steps:

  1. Run the quick install command.
  2. Verify and configure the middleware file at src/middleware.ts or src/middleware/index.ts to use the astro-i18n middleware.
  3. For serverless setups, import the root astro-i18n config and pass it to the middleware.
  4. For node environments (SSR or SSG), configure the astro-i18n config file generated in the root directory.
  5. Place translations in locations such as inside the middleware config, root config file, src/pages folder, or src/i18n directory.
  6. Utilize groups like “common”, current page group, and custom groups for translations.
  7. Run npm run i18n:sync to get type-safe translated routes.
  8. Use the t function for translations, handling duplicate keys based on specificity.

Summary:

The astro-i18n library is a feature-rich internationalization tool designed for Astro frameworks, offering lightweight performance, internationalized routing, type-safety, and support for various translation elements. With easy installation steps and support for different translation file formats, astro-i18n provides a comprehensive solution for managing multilingual content in Astro projects.