Svelte Intl Precompile screenshot

Svelte Intl Precompile

Author Avatar Theme by Cibernox
Updated: 9 Aug 2023
275 Stars

I18n library for Svelte.js that analyzes your keys at build time for max performance and minimal footprint

Overview

Svelte Intl Precompile is an i18n library for Svelte.js that offers a different approach to processing translations. Instead of performing all the translation work in the client, this library acts as a compiler for translations. By moving the translation parsing into the build step, it eliminates the need for a runtime ICU-message parser and results in smaller and faster apps. This product analysis will explore the features of Svelte Intl Precompile, provide an installation guide, and summarize its key benefits.

Features

  • API Similarity: The API of Svelte Intl Precompile is identical or very similar to kaisermann/svelte-i18n, allowing for easy migration between the two libraries.
  • Translation Compiler: Svelte Intl Precompile acts as a compiler for translations, analyzing and transforming strings in the ICU message syntax into optimized output.
  • Native Intl API: The library makes use of the native Intl API available in modern browsers and in Node.js, resulting in improved performance.
  • Small Footprint: By moving the translation parsing into the build step and leveraging tree-shaking, Svelte Intl Precompile has a smaller footprint compared to alternative libraries with a runtime ICU-message parser.
  • Faster Rendering: Rendering keys that have been previously rendered is approximately 25% faster, while initial rendering or rendering new keys is around 400% faster.

Installation

To install Svelte Intl Precompile, follow these steps:

  1. Install Svelte Intl Precompile as a runtime dependency.
  2. Create a folder, such as /messages or /locales, at the root of your project to store translations.
  3. In the created folder, create separate files for each language you want to support, such as en.json and es.json, or export translation objects using JS files.
  4. Export an object with your translation strings in each language file.

For a more detailed guide and example setup, you can refer to the sample-app-svelte-intl-precompile repository.

Summary

Svelte Intl Precompile is an i18n library for Svelte.js that acts as a compiler for translations, providing a unique approach to processing translations. By moving the translation parsing into the build step, it reduces the size and improves the performance of apps. With a familiar API, compatibility with the native Intl API, and a small footprint, Svelte Intl Precompile offers a convenient and optimized solution for internationalization in Svelte.js projects.