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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sveltekit-mf2

v0.1.4

Published

A Message Format 2 formatter component for SvelteKit with @sveltekit-i18n/base

Readme

SvelteKit MF2

A localization library for SvelteKit based on sveltekit-i18n/base and MessageFormat2.

Installation

npm install sveltekit-mf2

Guide

1. Install @sveltekit-i18n/base and messageformat

npm install @sveltekit-i18n/base messageformat

2. Setup i18n

Create the translations.ts file in you lib folder.

import i18n from "@sveltekit-i18n/base";
const config = {
	// Add your languages in the loaderfunction eaither from JSON files or directly as JSON
	loaders: [
		{
			locale: "en",
			key: "common",
			loader: async () => (await import("./en/common.json")).default
		},
		{
			locale: "es",
			key: "common",
			loader: async () => (await import("./es/common.json")).default
		}
	],
	parser: {
		parse(value: string, [props]: Record<string, any>[], locale: string) {
			return { value, props, locale };
		}
	}
};

export const { setLocale, t, locale, locales, loading, loadTranslations } = new i18n(config);

The locale files

en/common.json

{
	"test": "Hello {#bold}{$world}!{/bold}",
	"bye": "Bye"
}

es/common.json

{
	"test": "Hola {#bold}{$world}!{/bold}",
	"bye": "adios"
}

Make sure to not change the parser!

3. Use the FormatterProvider

Inside of your +layout.svelte use the <FormatterProvider> by importing t and sorounding {@render children} with the provider.

<script lang="ts">
	import favicon from '$lib/assets/favicon.svg';
  import { FormatterProvider } from 'sveltekit-mf2';
	import { t } from "$lib/translations"

	let { children } = $props();
</script>

<svelte:head>
	<link rel="icon" href={favicon} />
</svelte:head>

<FormatterProvider {t}>
	{@render children()}
</FormatterProvider>

4. Set the default locale and load the translations

Create a layout.ts file in your routes folder.

import { loadTranslations } from "$lib/translations";

const initLocale = "en";

export const load = async ({ url }) => {
	await loadTranslations(initLocale, url.pathname);
};

5. Use the Formatter component in you application

The <Formatter> component takes in an id which uses the loader key and the key value in the JSON oject to reference the correct line. Props are the variables passed to the Messageformat string.

<script>
  import { setLocale } from "$lib/translations";
  import { Formatter } from "sveltekit-mf2";


  function switchToEnglish() {
    setLocale("en");
  }

  function switchToSpanish() {
    setLocale("es");
  }
</script>

<div>
  <Formatter id="common.test" values={{ world: "SvelteKit" }} />
  // values is optional
  <Formatter id="common.bye" />

  <button onclick={switchToEnglish}>english</button>
  <button onclick={switchToSpanish}>spanish</button>
</div>

References

Message Format 2 svleltekit-i18n/base

Provider

<FormatterProvider>

Props: t - The t function from the i18n object

Component

<Formatter>

Props:

  • id: string - Translation key (e.g., "common.greeting")
  • values: Record<string, any> - Variables to interpolate