moosmann-svelte
TypeScript icon, indicating that this package has built-in type declarations

0.4.1 • Public • Published

moosmann-svelte

npm version

Integrate moosmann into svelte

I'm currently developing this while doing other things because I wanted to have a simple system for localization. It is in no way ready to use in production and the API may will change on a whim.

How to use

  1. Create your locales:
// [locales/en.ts]
export default {
    greeting: (name: string) => `Hello, ${name}!`,
};
// [locales/de.ts]
import type en from "./en";

export default {
    greeting: (name) => `Hallo, ${name}!`,
} satisfies typeof en;
  1. Create moosmann stores
export const { locale, t, localeKeys, isInitialized } = moosmannStores("en", {
    en: () => import("./locales/en"),
    de: () => import("./locales/de"),
});
  1. Use your created stores in your components
// [greeting.svelte]
<script lang="ts">
    import { t, isInitialized } from "./i18n";
</script>

{#if $isInitialized}
    <h1>{$t("greeting", "Moosmann")}</h1>
{/if}

See examples for more!

Package Sidebar

Install

npm i moosmann-svelte

Weekly Downloads

0

Version

0.4.1

License

MIT

Unpacked Size

9.75 kB

Total Files

9

Last publish

Collaborators

  • niphram