diff --git a/README.md b/README.md index f1dfdd0..2cb60bb 100644 --- a/README.md +++ b/README.md @@ -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 + + +