Skip to content

Vanilla

Importimport { adapter } from "wuchale/adapter-vanilla"
Loader extensions.js, .ts
Default filessrc/**/*.{js,ts}

The Vanilla adapter adds support for plain JavaScript/TypeScript projects. And how you use it is different based on whether you use Vite or not. If you are not using Vite, then it is impossible to use virtual modules. Therefore you have to write every file that your application needs, including compiled catalogs and proxies.

To support with that, wuchale provides the options to write those files to disk and will adjust the importing to use relative paths when it writes the output files.

This is assuming that you did not modify the default loader.

import { loadLocale } from 'wuchale/load-utils'
await loadLocale(locale)

And you use it like normal, putting strings inside function definitions.

const showMsg = (element) => {
element.innerHTML = 'Hello world'
}

For example, for use with a server,

import { runWithLocale } from 'wuchale/load-utils/server'
//...
app.get('/:locale', (req, res) => {
runWithLocale(req.params.locale, () => res.send('Hello world'))
})

In addition to the default rules, this adapter implements additional restrictions.

If the message is not in a function definition, it is ignored.

Examples:

const message = 'This is not extracted'
const lowercase = 'not extracted'
function foo() {
const extracted = 'Hello!'
}

For the main configuration, look in the configuration reference.

For the common adapter configuration, look in the common adapter options.

This adapter doesn’t have additional configuration options.