All Projects → Panya → svelte-intl

Panya / svelte-intl

Licence: MIT license
Internationalize your Svelte apps using format-message and Intl object

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to svelte-intl

svelte-eslint-parser
Svelte parser for ESLint
Stars: ✭ 30 (-37.5%)
Mutual labels:  svelte, sveltejs
ModalFileManager
A file manager built using Svelte and Wails. It has hotkeys that are modal just like Vim and NeoVim.
Stars: ✭ 21 (-56.25%)
Mutual labels:  svelte, sveltejs
aqua-fanpage
⚓ 湊あくあ Fanpage created with Svelte and Sveltestrap.
Stars: ✭ 30 (-37.5%)
Mutual labels:  svelte, sveltejs
ctx-core
A composable monorepo web-service/front-end toolkit
Stars: ✭ 25 (-47.92%)
Mutual labels:  svelte, sveltejs
svelte-undoable
Memento design pattern in Svelte
Stars: ✭ 39 (-18.75%)
Mutual labels:  svelte, sveltejs
kahi-ui
Straight-forward Svelte UI for the Web
Stars: ✭ 169 (+252.08%)
Mutual labels:  svelte, sveltejs
s-date-range-picker
📅 A date range picker built with Svelte
Stars: ✭ 13 (-72.92%)
Mutual labels:  svelte, sveltejs
sveltekit-blog
Sveltekit blog starter project created with sveltekit, typescript, tailwindcss, postcss, husky, and storybook. The project has the structure set up for the scaleable web application.
Stars: ✭ 100 (+108.33%)
Mutual labels:  svelte, sveltejs
svelte-material
Modular and customizable Material Design UI components for Svelte.js
Stars: ✭ 30 (-37.5%)
Mutual labels:  svelte, sveltejs
svelte-typewriter
A simple and reusable typewriter effect for your Svelte applications
Stars: ✭ 204 (+325%)
Mutual labels:  svelte, sveltejs
sdk-for-svelte
Appwrite SDK for Svelte 🧡 ⚠️ Warning - this SDK was designed to support Appwrite 0.9 and is not compatible with the latest Appwrite versions. We are planing to refactor it as part of the SDK Generator for better support and maintenance.
Stars: ✭ 69 (+43.75%)
Mutual labels:  svelte, sveltejs
mobx-react-intl
A connector between mobx-react and react-intl
Stars: ✭ 32 (-33.33%)
Mutual labels:  i18n, format-message
hagura-sveltekit
A minimal markdown blog template built using SvelteKit
Stars: ✭ 51 (+6.25%)
Mutual labels:  svelte, sveltejs
d3-fdg-svelte
d3 Force Directed Graph example (d3-force) implemented in sveltejs. REPL:
Stars: ✭ 31 (-35.42%)
Mutual labels:  svelte, sveltejs
svelte-color-picker
A color picker component for svelte
Stars: ✭ 96 (+100%)
Mutual labels:  svelte, sveltejs
vite-plugin-webfont-dl
⚡ Webfont Download Vite Plugin - Make your Vite site load faster
Stars: ✭ 69 (+43.75%)
Mutual labels:  svelte, sveltejs
svelte-datagrid
Svelte data grid spreadsheet best best features and performance from excel
Stars: ✭ 48 (+0%)
Mutual labels:  svelte, sveltejs
svelte-portal
Svelte component for rendering outside the DOM of parent component
Stars: ✭ 261 (+443.75%)
Mutual labels:  svelte, sveltejs
i18n-unused
The static analyze tool for finding, marking and removing unused and missing i18n translations in your JavaScript project
Stars: ✭ 76 (+58.33%)
Mutual labels:  i18n, svelte
generator-jhipster-svelte
Generate Svelte powered JHipster web applications
Stars: ✭ 44 (-8.33%)
Mutual labels:  svelte, sveltejs

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].