Svelte I18n Lingui

screenshot of Svelte I18n Lingui
svelte
vite

Use lingui for i18n in Svelte/Sveltekit projects

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.

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.

svelte
Svelte

Svelte is a modern front-end framework that compiles your code at build time, resulting in smaller and faster applications. It uses a reactive approach to update the DOM, allowing for high performance and a smoother user experience.

vite
Vite

Vite is a build tool that aims to provide a faster and leaner development experience for modern web projects

eslint
Eslint

ESLint is a linter for JavaScript that analyzes code to detect and report on potential problems and errors, as well as enforce consistent code style and best practices, helping developers to write cleaner, more maintainable code.

Multilingual

Multilingual websites are websites that are available in more than one language. Multilingual websites typically include features such as language selectors, automatic translation, and localized content to make it easier for users to navigate and access the content they need.

typescript
Typescript

TypeScript is a superset of JavaScript, providing optional static typing, classes, interfaces, and other features that help developers write more maintainable and scalable code. TypeScript's static typing system can catch errors at compile-time, making it easier to build and maintain large applications.