Svelte I18n Lingui screenshot

Svelte I18n Lingui

Author Avatar Theme by Henrylie
Updated: 29 Jun 2025
32 Stars

Use lingui for i18n in Svelte/Sveltekit projects

Categories

Overview

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.

Features

  • Message as catalog id: Allows users to see the base language text in their code instead of a manually generated ID.
  • Message extraction: Automatically extracts plain strings in the code that are consumed or marked by the library into a catalog using a CLI command.
  • Shortened id for compiled catalog: Uses a replacement short message hash instead of the original message in the compiled catalog, reducing the catalog size and download size.
  • Simple API with stores: Utilizes Svelte stores to subscribe to locale changes and translate text in real time.
  • Clean syntax: Uses tagged template literals for simple translations.

Installation

To install svelte-i18n-lingui, follow these steps:

  1. Open your terminal.

  2. Navigate to your project directory.

  3. Run the following command to install the package:

    npm install svelte-i18n-lingui
    
  4. Once installed, you can import the package in your Svelte/Sveltekit files to start using it for internationalization.

Summary

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.