Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/noelmugnier/svelte-translate

Use a dynamic translation service (loaded from xx-XX.json files) and fallback to the text in html tags if no translations are provided.
https://github.com/noelmugnier/svelte-translate

svelte sveltejs translate

Last synced: 2 days ago
JSON representation

Use a dynamic translation service (loaded from xx-XX.json files) and fallback to the text in html tags if no translations are provided.

Awesome Lists containing this project

README

        

# Svelte Translate (inspired by angular i18n and svelte-i18n)

Dynamic translation service (loaded from xx-XX.json files) and fallback to the text in html tags if no translations are provided.

# ICU support (FormatJS)

This component use [formatjs](https://github.com/formatjs/formatjs) to handle complex formatting (plural, select, etc...)

# Usages

```js

import {
i18n,
def,
i18nStore,
languages,
DynamicTranslatedApp,
getLocaleFromNavigator
} from "svelte-translate";

import LanguageSelector from "./LanguageSelector.svelte";

import enGB from './../public/lang/en-GB.json';
import frFR from './../public/lang/fr-FR.json';

let count = 0;

i18nStore.addTranslations("en-GB", enGB);
i18nStore.addTranslations("fr-FR", frFR);

```

```html


Default text with bindings {sampleValue}
Text without complex construction

```
Then add two json files (fr-FR.json/en-GB.json) in public/lang folder containing your translations :

```json
{
"myid": "Custom translation text with bindings {sampleValue}",
"simpleid": "Custom text without bindings",
}
```

# TODO

* [ ] support context/description in def() helper in order to extract them and complete xlf files require a fork on xliff library to use custom attributes