npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

svelte-translate-pro

v0.0.8

Published

A powerful and flexible internationalization (i18n) library for dynamic language management, real-time translations, and localization. Supports multiple languages, interpolation, and page-specific translations with an intuitive API.

Readme

Svelte Translate Pro

Svelte Internationalization (i18n) with Dynamic Language Loading

This project provides a flexible internationalization (i18n) solution for Svelte applications, with support for multiple languages and dynamic translation loading. It allows you to load translation files at runtime, switch languages dynamically, and retrieve translations with support for interpolation.

Svelte Translate Pro

Features

  • Support for multiple languages.
  • Dynamic loading of translation files.
  • Page-specific translations.
  • Interpolation of variables in translation strings.
  • Reactive translation system using Svelte stores.

Installation

To get started, simply install the package using npm or yarn:

npm install svelte-translate-pro

or

yarn add svelte-translate-pro

Usage

1. Define Supported Languages

You can define the languages supported by your application using the AppLanguages enum:

import { AppLanguages } from 'svelte-translate-pro';

console.log(AppLanguages.EN); // "en"

2. Load Translation Files

Use the loadTranslation function to dynamically load a translation data for a given language.

import { loadTranslation, AppLanguages } from 'svelte-translate-pro';

import en from "/lib/translations/en.json"

await loadTranslation(AppLanguages.EN, en);

Translation File Example (fr.json)

{
  "navbar.title": "Bienvenue",
  "footer.contact": "Contactez-nous"
}

3. Get the Current Language

You can retrieve the current language using the getActiveLanguage function.

import { getActiveLanguage } from 'svelte-translate-pro';

const currentLang = getActiveLanguage();
console.log(currentLang); // "en"

4. Set Page-Specific Translations

Use setPageSpecificTranslations to update translations for the current page. This allows you to set translations that are specific to the page content.

import { setPageSpecificTranslations, AppLanguages } from 'svelte-translate-pro';

setPageSpecificTranslations({
    [AppLanguages.EN]: { "title": "Welcome to the page" },
    [AppLanguages.FA]: { "title": "به صفحه خوش آمدید" }
});

5. Retrieve Translations

You can use the $t$ store to retrieve translations reactively in your Svelte components.

<script lang="ts">
  import { t$ } from 'svelte-translate-pro';
</script>

<h1>{$t$('navbar.title')}</h1> <!-- Displays the translation for "navbar.title" -->

You can also pass variables for interpolation:

const variables = { name: "John" };
const translatedText = $t$('greeting', variables);

Example with Interpolation (greeting key in JSON):

{
  "greeting": "Hello, {{name}}!"
}

Example with Language-Specific Variables

You can also pass language-specific values for interpolation:

$t$('greeting', { name: {
  [AppLanguages.EN]: "John",
  [AppLanguages.FA]: "جان"
}});

Inline Translation

If you need to provide inline translations directly in the code, you can use the following format:

$t$({
  [AppLanguages.EN]: "Hello, World!",
  [AppLanguages.FA]: "سلام دنیا!"
});

6. Language Switching

You can switch the language by calling the setActiveLanguage function, which updates the application's language:

import { setActiveLanguage, AppLanguages } from 'svelte-translate-pro';

setActiveLanguage(AppLanguages.FA); // Switches to Persian (FA)
setActiveLanguage(AppLanguages.EN); // Switches to English (EN)

7. Debugging

When loading translations in development mode (DEV environment variable is true), you will see console logs indicating successful translation file loading.

DEBUG=vite-plugin-svelte:node-modules-onwarn pnpm build

API Reference

AppLanguages

An enum that defines the supported languages:

export enum AppLanguages {
    EN = "en",
    FA = "fa",
    ES = "es",
    DE = "de",
    FR = "fr",
    IT = "it",
    RU = "ru",
    CN = "zh-cn",
    JP = "ja",
    AR = "ar"
}

getActiveLanguage(): AppLanguage

Gets the current language of the application.

const lang = getActiveLanguage(); // "en"

setPageSpecificTranslations(data: Record<AppLanguage, TranslationData>)

Sets page-specific translations for the current page.

setPageSpecificTranslations({
    en: { "title": "Welcome" },
    fa: { "title": "به صفحه خوش آمدید" }
});

t$: Readable

A derived store that provides a reactive translation function.

<h1>{$t$('navbar.title')}</h1>

TranslationObject

Represents a translation object that can map language codes to translation strings.

type TranslationObject = Partial<Record<AppLanguage, string>>;

TranslationData

Represents translation data for a single language.

type TranslationData = Record<string, string>;

reactiveTranslate: Reactive Translations for Arrays

reactiveTranslateis a utility function that provides a reactive array of translated items based on the current language.

import { reactiveTranslate } from "svelte-translate-pro";

const tabs = reactiveTranslate((t) => [
    { title: t("tabs.recieve"), id: 1 },
    { title: t("tabs.send"), id: 2 },
]);
<div>
    {#each $tabs as tab}
        <button>{tab.title}</button>
    {/each}
</div>

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please fork this repository and submit your pull requests.


Happy coding and enjoy using the Svelte i18n system!