@open-xchange/vite-plugin-po2json
v1.3.0
Published
A Vite plugin to load po files into our gettext based dictionary implementation.
Maintainers
Keywords
Readme
Vite Plugin PO2JSON
A Vite plugin that compiles GNU gettext PO files into JSON translation dictionaries for App Suite UI. Forked from @open-xchange/rollup-plugin-po2json and adapted for Vite 8 / Rolldown.
Install
pnpm i "@open-xchange/vite-plugin-po2json"How to use
// in the vite.config.js
import vitePluginPo2json from '@open-xchange/vite-plugin-po2json'
export default defineConfig({
plugins: [vitePluginPo2json({
poFiles: 'i18n/*.po'
})]
})Options
- poFiles
<string>(required) Glob pattern pointing to the PO files to compile. - outFile
<string>Path of the extracted POT file, relative to the buildoutDir. The file is written to disk next to the bundle, not emitted into it, so it never appears in the Vite manifest. Use a path outsideoutDir(e.g.'../output/ox.pot'or an absolute path) to keep it out of the build output and deployments. Default:'i18n.pot' - defaultDictionary
<string>Name of the default translation dictionary. Default:'i18n' - defaultLanguage
<string>The default language to use. Default:'en_US' - headers
<object>Headers to include in the generated POT file. Default:{ 'Content-Type': 'text/plain; charset=UTF-8', 'Content-Transfer-Encoding': '8bit' } - includeFuzzy
<boolean>Whether to include fuzzy translations in the output. Default:false - missingComments
<'off' | 'warn' | 'error'>Checks that every gettext call has a translator comment:// #. …directly above the line of the call, or<!-- #. … -->in front of a Vue template expression.'warn'lists the calls without one as a build warning,'error'fails the build with that list. The check runs at the end ofvite buildon the modules the POT file is extracted from, except those innode_modules. It looks at each call, so a msgid used twice needs a comment at both calls. Default:'off'
How to test
pnpm testTranslator comments in Vue templates
Translator hints written as HTML comments (<!-- #. … -->) directly above
a gt(...) call in a template are picked up and attached to the extracted
msgid, in addition to the usual // #. … comments in <script>:
<template>
<!-- #. Opens the Manage categories dialog -->
<button :title="gt('Manage categories')">…</button>
</template>Multiple comments before the same call are collected in order; a comment is attached to the first translatable expression that follows it.
