Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/amoutonbrady/solid-i18n
- Owner: amoutonbrady
- Archived: true
- Created: 2020-09-12T09:10:44.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-24T08:21:10.000Z (over 2 years ago)
- Last Synced: 2024-09-21T14:11:17.542Z (about 2 months ago)
- Topics: i18n, solidjs
- Language: TypeScript
- Homepage: https://codesandbox.io/s/i18n-fg88e?file=/src/index.tsx
- Size: 64.5 MB
- Stars: 18
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
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)
# 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'),
);
```