Getting started
Installation
Section titled “Installation”To install wuchale
, you have to install the base package and the
adapter(s) you want to use. The adapter for vanilla JS/TS
projects is built into the base package. For other projects, the adapter
package has to be installed additionally.
This installation guide assumes that you have your source files under src
. If
not, you will have to configure the adapter and provide the files
.
-
Install
Terminal window npm install wuchale @wuchale/jsx @wuchale/vite-pluginTerminal window npm install wuchale @wuchale/svelte @wuchale/vite-pluginTerminal window npm install wuchale @wuchale/jsx @wuchale/vite-pluginTerminal window npm install wuchale @wuchale/vite-pluginTerminal window npm install wuchale -
Configure Vite
vite.config.js import { defineConfig } from 'vite'import react from '@vitejs/plugin-react'import { wuchale } from '@wuchale/vite-plugin'export default defineConfig({plugins: [ wuchale(), react() ],})vite.config.js import { svelte } from '@sveltejs/vite-plugin-svelte'import { wuchale } from '@wuchale/vite-plugin'export default {plugins: [ wuchale(), svelte() ]}vite.config.js import { sveltekit } from '@sveltejs/kit/vite'import { wuchale } from '@wuchale/vite-plugin'export default {plugins: [ wuchale(), sveltekit() ]}vite.config.js import { defineConfig } from 'vite';import solidPlugin from 'vite-plugin-solid';import { wuchale } from '@wuchale/vite-plugin';export default defineConfig({plugins: [wuchale(), solidPlugin()],});vite.config.js import { wuchale } from '@wuchale/vite-plugin'export default {plugins: [wuchale()]}No need
-
Create Configuration
wuchale.config.js // @ts-checkimport { adapter as jsx } from "@wuchale/jsx"import { defineConfig } from "wuchale"export default defineConfig({// sourceLocale is en by defaultotherLocales: ['es'],adapters: {main: jsx(),}})wuchale.config.js // @ts-checkimport { adapter as svelte } from "@wuchale/svelte"import { defineConfig } from "wuchale"export default defineConfig({// sourceLocale is en by defaultotherLocales: ['es'],adapters: {main: svelte(),}})wuchale.config.js // @ts-checkimport { adapter as svelte } from "@wuchale/svelte"import { adapter as js } from 'wuchale/adapter-vanilla'import { defineConfig } from "wuchale"export default defineConfig({// sourceLocale is en by defaultotherLocales: ['es'],adapters: {main: svelte(),js: js({files: ['src/**/+{page,layout}.{js,ts}','src/**/+{page,layout}.server.{js,ts}',],})}})wuchale.config.js // @ts-checkimport { adapter as jsx } from "@wuchale/jsx"import { defineConfig } from "wuchale"export default defineConfig({// sourceLocale is en by defaultotherLocales: ['es'],adapters: {main: jsx({variant: "solidjs"}),}})wuchale.config.js // @ts-checkimport { adapter as basic } from 'wuchale/adapter-vanilla'import { defineConfig } from 'wuchale'export default defineConfig({// sourceLocale is en by defaultotherLocales: ['es'],adapters: {main: basic()}}) -
Initialize locales
Terminal window npx wuchale initThis command:
- Creates the locales directory if it doesn’t exist
- Creates the loader files, asking you which is correct
- Performs an initial extraction
-
Setup in Your App
Now that the loader files are created, you can edit them, export the things you need from there, and setup how the translations are loaded.
Look in the React setup guide
- Svelte: Look in the Svelte setup guide
- SvelteKit: Look in the SvelteKit setup guide
Look in the SolidJS setup guide
import { loadLocale } from 'wuchale/load-utils'await loadLocale(locale)No need
-
Start Coding!
Write your code components naturally.
wuchale
will extract and compile translations automatically:function Hello() {return <p>Hello world</p>}<p>Hello world</p>function Hello() {return <p>Hello world</p>}E.g. DOM
const showMsg = (element) => {element.innerHTML = 'Hello world'}
For full usage examples, look inside the examples repository. It contains examples for different frameworks and usage patterns.
Workflow
Section titled “Workflow”wuchale
’s workflow is inspired by Lingui. It follows
similar steps but it does most of the steps automatically.
-
You write your code
-
wuchale
auto extracts the messages into the catalog filesDuring this step, if configured, Gemini does the automatic translation
-
The translator translates the messages by editing the extracted
.po
files -
wuchale
picks up the changes and updates the UI during dev -
When you do the production build,
wuchale
auto compiles the catalogs and passes them to Vite to be included in the final build.
-
You write your code
-
You invoke the CLI command
wuchale
to extract the messages into the catalog filesDuring this step, if configured, Gemini does the automatic translation
-
The translator translates the messages by editing the extracted
.po
files -
You invoke the CLI command
wuchale
again to compile the translated messages and write them to disk -
When you run the app, everything works.