# 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

```sh
pnpm i "@open-xchange/vite-plugin-po2json"
```

## How to use

```js
// 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 build `outDir`. 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 outside `outDir` (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 of `vite build` on the modules the POT file is extracted from, except those in `node_modules`. It looks at each call, so a msgid used twice needs a comment at both calls. Default: `'off'`

## How to test

```sh
pnpm test
```

## Translator 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>`:

```vue
<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.
