1.1.1 • Published 6 months ago
@open-xchange/vite-plugin-i18next-gettext v1.1.1
@open-xchange/vite-plugin-i18next-gettext
A Vite plugin that allows using i18next in source code, while using gettext with .po and .pot files under the hood.
This plugin has the following responsibilities:
- Vite's development server will convert
.pofiles imported in source code to i18next-compatible JSON data on-the-fly. - When building the project,
.pofiles will be converted to and written as i18next-compatible JSON files into the bundle. - When building the project, the source code will be scanned for translation strings (
tfunction calls), and a.potfile containing all strings will be generated into the output directory.
This plugin is designed to work together with the i18next plugin @open-xchange/i18next-plugin-pofile-backend that will load the .po files into the i18next instance.
Usage
Add the plugin to your Vite configuration:
// vite.config.ts
import { defineConfig } from "vite" // or "vitest/config"
import i18nextPlugin from "@open-xchange/vite-plugin-i18next-gettext"
export default defineConfig(() => {
// ...
plugins: [
// ...
i18nextPlugin({
poFiles: "i18n/*.po",
srcFiles: "src/**/*.{js,jsx,ts,tsx}",
potFile: "main.pot",
projectName: "My Project",
}),
],
})Options
| Name | Type | Default | Description |
|---|---|---|---|
poFiles | string\|string[] | required | Glob pattern(s) for all .po files containing the translations. |
srcFiles | string\|string[] | required | Glob pattern(s) for all source files to be scanned for UI strings. |
potFile | string | required | Path to the .pot file to be generated when building the project, relative to the build output directory. |
projectName | string | required | The project name to be inserted into the .pot file under the key "Project-Id-Version". |