Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
LorisSigrist committed Oct 3, 2023
1 parent d6ca160 commit 3bab9e2
Showing 1 changed file with 69 additions and 7 deletions.
76 changes: 69 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,86 @@
Typesafe i18n.

## Installation
```
pnpm i -D t18s
```

This package has not yet been published. Please be patient while I get it to MVP.
## Usage
`t18s` is a vite plugin that compiles your translations to a typesafe format. It also dynamically generates the runtime code to work with your translations.

## Features
1. Add the plugin to your vite config
```js
// vite.config.js
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { t18s } from "t18s"

export default defineConfig({
//Plugin order doesn't matter
//Default options are shown
plugins: [sveltekit(), t18s({
translationsDir: "src/translations",
dts: "src/t18s.d.ts"
})]
});
```

Then start the dev server with `(p)npm dev`.

2. Create a translations file
In the `translationsDir` that you specified in the vite config, create a file called `en.json` (or whatever locale you want to use). The file should contain key-value pairs of translations.

```json
{
"hello": "Hello World!",
"helloName": "Hello {name}!"
}
```

The values must be valid ICU MessageFormat strings.
You can also use YAML files.

3. Use the translations in your code
```svelte
<script>
import { t } from "$t18s" //The $t18s module is dynamically generated by the plugin
</script>
<h1>{$t("hello")}</h1>
<h1>{$t("helloName", { name: "John" })}</h1>
```

That's it.

## Roadmap

- [x] TypeSafe
- [x] Precompile translations, no runtime overhead
- [x] Supports SSR
- [x] Full ICU MessageFormat support
- [x] Supports HMR, no page reload on translation changes
- [x] HMR: No page reload on translation changes
- [x] Supports Svelte
- [x] Lazy loading locales
- [x] SSR
- [x] Works with SSR
- [ ] Fallback Locale
- [ ] Sub Locales (eg EN_US, EN_UK)
- [x] Loading Delay
- [ ] Namespaces
- [ ] Message Description Intellisense
- [ ] More File Formats
- [ ] Edit translations in the browser
- [ ] Locale extraction helpers
- [ ] Documentation Site
- [ ] All Common Message-File Formats
- [x] JSON
- [x] YAML
- [ ] TOML
- [ ] CSV
- [ ] XLIFF
- [ ] PO
- [ ] INI
- [ ] XML
- [ ] Edit translations inline in the browser (like [Better i18n for Svelte](https://github.com/versiobit/better-i18n-for-svelte))
- [ ] Frameworks other than Svelte
- [ ] Vanilla
- [ ] React
- [ ] Vue
- [ ] Message Description Intellisense

0 comments on commit 3bab9e2

Please sign in to comment.