Vanilla
Import | import { adapter } from "wuchale/adapter-vanilla" |
---|---|
Loader extensions | .js , .ts |
Default files | src/**/*.{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.
Setup in Your App
Section titled “Setup in Your App”This is assuming that you did not modify the default loader.
With Vite
Section titled “With Vite”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'}
Without Vite
Section titled “Without Vite”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'))})
Default extraction rules
Section titled “Default extraction rules”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!'}
Configuration Reference
Section titled “Configuration Reference”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.