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 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-intl

v1.1.4

Published

Internationalize your Svelte 3 apps

Downloads

270

Readme

svelte-intl

NPM Version

Sizes (svelte-intl and format-message):

Package Size Package Size

Internationalize your Svelte 3 apps using format-message.

Svelte 2

For Svelte 2 version see this branch.

Installation

npm i svelte-intl format-message # format message is a peer dependency

Usage

<script context="module">
  import { locale, translations, getBrowserLocale } from 'svelte-intl';

  // If you want to split your bundle, you can call this multiple times,
  // the dictionaries will be merged.
  translations.update({
    en: {
      hello: 'Hello, {name}',
    },
    pt: {
      hello: 'Olá, {name}',
    },
  })

  locale.set(getBrowserLocale('en')) // try to use window.navigator.language
</script>

<script>
  // use _ or translate
  import { _ } from 'svelte-intl'

  export let name = 'John'
</script>

<h1> {$_('hello', { name })} </h1>

API

translate (or "_")

Translation store

  • Type: svelte.Readable<typeof formatMessage>

Example

<script>
  import { get } from 'svelte/store'
  import { translate } from 'svelte-intl'

  const title = get(translate)('title')
</script>

<h1> Title: {title} </h1>
<h1> Reactive Title: {$translate('title')} </h1>

translations

Available translations

  • Type: Object
    • set(translations) => void : Replace translations (avoid this)
    • update(translations) => void : Add more translations
    • subscribe : Store subscription, avoid using this directly

locale

Current locale

  • Type: like svelte.Readable<string>, but with safe update and set (logs error if locale is not found)
  • Note: Set and update return a boolean indicating if the locale was found

locales

Available locales, derived from translation

  • Type: svelte.Readable<string[]>

Usage

<!-- LanguageSelector.svelte -->
<script>
  import { locale, locales } from 'svelte-intl'

  const setLocale = e => locale.set(e.target.value)
</script>

<select value={$locale} on:change={setLocale}>
  {#each $locales as l}
    <option value={l}> {l} </option>
  {/each}
</select>

options

See format-message options
Just call options.set({ }) :)

  • Type: svelte.Readable<formatMessage.SetupOptions> (but update merges with current config)

getBrowserLocale

Tries to match the window.navigator.language to the available dictionaries

  • Params:
    • defaultLocale {string}: If no match is found, returns this