@anchanix/unplugin-fluent
v0.1.0-beta.3
Published
Plugin for Vite and other bundlers to easily import [project fluent](https://projectfluent.org/) bundles.
Downloads
219
Maintainers
Readme
@anchanix/unplugin-fluent
Plugin for Vite and other bundlers to easily import project fluent bundles.
Install
pnpm add @anchanix/unplugin-fluent
// vite.config.ts
import fluent from '@anchanix/unplugin-fluent/vite'
export default defineConfig({
plugins: [
fluent({ /* options */ }),
],
})
Example: playground/
// rollup.config.js
import fluent from '@anchanix/unplugin-fluent/rollup'
export default {
plugins: [
fluent({ /* options */ }),
],
}
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('@anchanix/unplugin-fluent/webpack')({ /* options */ })
]
}
// nuxt.config.js
export default defineNuxtConfig({
modules: [
['@anchanix/unplugin-fluent/nuxt', { /* options */ }],
],
})
This module works for both Nuxt 2 and Nuxt Vite
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('@anchanix/unplugin-fluent/webpack')({ /* options */ }),
],
},
}
// esbuild.config.js
import { build } from 'esbuild'
import fluent from '@anchanix/unplugin-fluent/esbuild'
build({
plugins: [fluent()],
})
Usage
Importing a single language bundle
import enBundle from 'virtual:fluent/langs/en-AU'
Dynamically loading bundles
To dynamically load bundles you first have to import the bundle map:
import bundleMap from 'virtual:fluent/langs/all'
and then in a function you can use the map to load a bundle
async function switchLang(langCode: string) {
if (!bundleMap[langCode]) {
throw new Error(`Language not supported: ${langCode}`)
}
const bundleImport = await bundleMap[langCode]
const bundle = bundleImport.default
// start using the bundle
}