Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/amoutonbrady/solid-i18n

A tiny i18n library for Solid js
https://github.com/amoutonbrady/solid-i18n

i18n solidjs

Last synced: about 1 month ago
JSON representation

A tiny i18n library for Solid js

Awesome Lists containing this project

README

        

This library was an experiment. This is now deprecated in favor of a similar package and officially supported by core members of solid: [@solid-primitives/i18n](https://github.com/davedbase/solid-primitives/tree/main/packages/i18n)

preview badge

# solid-i18n

Tiny translation library for [solid-js](https://github.com/ryansolid/solid) inspired by [rosetta](https://github.com/lukeed/rosetta)

## Quick start

Install it:

```bash
yarn add @amoutonbrady/solid-i18n
```

Use it:

```tsx
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 (
<>
locale('fr')}>fr
locale('en')}>en
locale('unknownLanguage')}>unknown language
add and set swedish
setName(e.target.value)} />


{t('hello', { name: name() }, 'Hello {{ name }}!')}!


{locale()}



{JSON.stringify(dict('sw'), null, 4)}

>
);
};

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

render(
() => (



),
document.getElementById('app'),
);
```