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:
- Run the quick install command.
- Verify and configure the middleware file at src/middleware.ts or src/middleware/index.ts to use the astro-i18n middleware.
- For serverless setups, import the root astro-i18n config and pass it to the middleware.
- For node environments (SSR or SSG), configure the astro-i18n config file generated in the root directory.
- Place translations in locations such as inside the middleware config, root config file, src/pages folder, or src/i18n directory.
- Utilize groups like “common”, current page group, and custom groups for translations.
- Run
npm run i18n:sync
to get type-safe translated routes. - 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.