Vue 3 Gettext is a library for internationalizing Vue 3 applications using the gettext translation system. It provides a simple, ergonomic API for reactive translations within Vue templates and TypeScript/JavaScript code, supporting pluralization and message contexts. The package includes a CLI tool for automatic message extraction from code files, facilitating the translation workflow. Currently in a 4.0.0-beta.1 state, it is actively developed with continuous enhancements and breaking changes between major and minor alpha/beta releases. Its key differentiator is the direct integration with Vue 3's reactivity system and adherence to the established gettext standard, offering a robust alternative to other i18n solutions for projects already using or preferring gettext.
npm install vue3-gettextVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to initialize vue3-gettext, use $gettext for singular and plural translations in a template, and dynamically change the locale using `useGettext` in the setup function.
Migrate all `require()` statements to `import` statements. Ensure your project is configured for ESM.
Upgrade your Node.js environment to version 20.19.0 or higher.
Replace usages of `<translate>` component and `v-translate` directive with the `$gettext` helper function directly in templates or via `useGettext` in script setup blocks.
Review your existing `.po` and `.pot` files. Re-extract messages and carefully merge translations, ensuring consistency in message IDs and line endings to avoid broken translations.
Update any TypeScript interfaces or type references from `GettextConfigOptions` to `Config`.
Ensure your `tsconfig.json` includes `vue` and/or `@vue/runtime-core` types, and that `vue3-gettext`'s global type declarations are being picked up correctly by your TypeScript setup.
Change `require('vue3-gettext')` to `import { ... } from 'vue3-gettext'`. Ensure your project uses an ESM-compatible build setup (e.g., `"type": "module"` in `package.json`).Verify that `app.use(gettext)` is called after `createApp()`. Ensure your `tsconfig.json` is set up to include the type declarations from `vue3-gettext` (e.g., check `include` array and ensure `node_modules` is not excluded).
Remove the `<translate>` component and `v-translate` directive. Use the `$gettext` helper function directly in templates: `{{ $gettext("Your message") }}`.