Use lingui for i18n in Svelte/Sveltekit projects
svelte-i18n-lingui is a package that allows users to add internationalization (i18n) to Svelte/Sveltekit projects using Lingui. It offers a gettext-style approach, where the base language text is written as-is in the codebase and marked for extraction. The package provides a CLI command to scan the codebase and extract the marked messages into a message catalog (usually .po files). Translations for different locales can be added to these catalog files. Another CLI command can then compile the catalog files into an optimized message dictionary to be loaded during runtime. The package includes functions to translate messages in real time based on the user’s language preference.
To install svelte-i18n-lingui, follow these steps:
Open your terminal.
Navigate to your project directory.
Run the following command to install the package:
npm install svelte-i18n-lingui
Once installed, you can import the package in your Svelte/Sveltekit files to start using it for internationalization.
svelte-i18n-lingui is a package designed to address the limitations of existing i18n libraries for Svelte. It offers a gettext-style approach, allowing developers to write base language text directly in their code and mark it for extraction. The package provides commands to extract and compile the marked messages into a message dictionary for runtime translation. It also utilizes Svelte stores to subscribe to locale changes and enable real-time text translation. With its clean syntax and focus on simplicity, svelte-i18n-lingui provides a convenient solution for internationalizing Svelte/Sveltekit projects.