@open-xchange/vite-plugin-i18next-gettext

1.0.2 • Public • Published

@open-xchange/vite-plugin-i18next-gettext

A Vite plugin that allows using i18next in source code with gettext's' .po and .pot files under the hood.

This plugin has the following responsibilities:

  • Vite's development server will convert .po files imported in source code to i18next-compatible JSON data on-the-fly.
  • When building the project, .po files 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 (t function calls), and a .pot file 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".

Readme

Keywords

none

Package Sidebar

Install

npm i @open-xchange/vite-plugin-i18next-gettext

Weekly Downloads

421

Version

1.0.2

License

MIT

Unpacked Size

8.36 kB

Total Files

5

Last publish

Collaborators

  • moritz.bach
  • johnyb
  • davidbauer
  • solygen
  • daniel.rentz
  • alexquast
  • d.haus
  • maik.schaefer
  • anne.matthes
  • andree
  • bjoern.koester
  • tran-dong.tran
  • ox-kaci