si

@amoutonbrady/solid-i18n

A tiny i18n library for Solid js

Showing:

Popularity

Downloads/wk

21

GitHub Stars

9

Maintenance

Last Commit

2mos ago

Contributors

2

Package

Dependencies

1

License

MIT

Type Definitions

Built-In

Tree-Shakeable

Yes?

Categories

Readme

preview badge

solid-i18n

Tiny translation library for solid-js inspired by rosetta

Quick start

Install it:

yarn add @amoutonbrady/solid-i18n

Use it:

import { render } from 'solid-js/dom';
import { Component, createSignal } from 'solid-js';
import { I18nProvider, useI18n } from '@amoutonbrady/solid-i18n';

const App: Component = () => {
  const [t, { add, locale, dict }] = useI18n();
  const [name, setName] = createSignal('Greg');

  const addLanguage = () => {
    add('sw', { hello: 'hej {{ name }}, hur mar du?' });
    locale('sw');
  };

  return (
    <>
      <button onClick={() => locale('fr')}>fr</button>
      <button onClick={() => locale('en')}>en</button>
      <button onClick={() => locale('unknownLanguage')}>unknown language</button>
      <button onClick={addLanguage}>add and set swedish</button>
      <input value={name()} onInput={(e) => setName(e.target.value)} />

      <hr />

      <h1>{t('hello', { name: name() }, 'Hello {{ name }}!')}!</h1>
      <p>{locale()}</p>
      <pre>
        <code>{JSON.stringify(dict('sw'), null, 4)}</code>
      </pre>
    </>
  );
};

const dict = {
  fr: {
    hello: 'bonjour {{ name }}, comment vas-tu ?',
  },
  en: {
    hello: 'hello {{ name }}, how are you?',
  },
};

render(
  () => (
    <I18nProvider dict={dict} locale="fr">
      <App />
    </I18nProvider>
  ),
  document.getElementById('app'),
);

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100