Registry / serialization / gettext-extractor-vue

gettext-extractor-vue

JSON →
library5.2.0jsnpmunverified

gettext-extractor-vue is a specialized extension for the `gettext-extractor` library, designed to facilitate the extraction of gettext messages from Vue Single File Components (SFCs). It works by decorating `gettext-extractor`'s `JSExtractor` to preprocess `.vue` files, transforming their template and script sections into standard JavaScript that the core `gettext-extractor` can then parse. The current stable version is 5.2.0. This package differentiates itself by offering compatibility with both Vue 2 applications (requiring `vue-template-compiler` as a user-provided dependency) and Vue 3 applications (requiring `@vue/compiler-sfc`). Additionally, it provides utility functions, such as `decorateExtractorWithHelpers`, to add message transformation capabilities to the core `GettextExtractor` instance. While its release cadence isn't strictly defined, it generally aligns with major versions of `gettext-extractor` and Vue itself to ensure ongoing compatibility.

npm install gettext-extractor-vue
INSTALL
IMPORT
SIG · GETTEXT-EXTRACTOR-
G
gettext-extractor-vue
serializationjavascriptv5.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

decorateJSParserWithVueSupport
import { decorateJSParserWithVueSupport } from 'gettext-extractor-vue';
const { decorateJSParserWithVueSupport } = require('gettext-extractor-vue');
The recommended ES Module import for modern JavaScript projects, though CommonJS `require()` is also supported.
decorateExtractorWithHelpers
import { decorateExtractorWithHelpers } from 'gettext-extractor-vue';
const { decorateExtractorWithHelpers } = require('gettext-extractor-vue');
Utility function for adding message transformation, available via both ESM and CommonJS.
* as gettextVue
import * as gettextVue from 'gettext-extractor-vue';
import gettextVue from 'gettext-extractor-vue';
Wildcard import for accessing all named exports from the package in an ES Module context.

This quickstart demonstrates how to set up `gettext-extractor` with `gettext-extractor-vue` to parse both JavaScript and Vue Single File Components (SFCs), saving extracted messages to a `.pot` file. It shows how to integrate `decorateJSParserWithVueSupport` and highlights the conditional requirement for `vue-template-compiler` (for Vue 2) or `@vue/compiler-sfc` (for Vue 3).

const { GettextExtractor, JsExtractors } = require('gettext-extractor'); const { decorateJSParserWithVueSupport } = require('gettext-extractor-vue'); const extractor = new GettextExtractor(); const jsParser = extractor.createJsParser([ JsExtractors.callExpression('getText', { arguments: { text: 0, context: 1, }, }), JsExtractors.callExpression('getPlural', { arguments: { text: 1, textPlural: 2, context: 3, }, }), ]); // For vue@2 support, ensure vue-template-compiler is installed let vueParser = decorateJSParserWithVueSupport(jsParser, { vue2TemplateCompiler: require('vue-template-compiler'), }); // For vue@3 support, ensure @vue/compiler-sfc is installed // vueParser = decorateJSParserWithVueSupport(jsParser, { // vue3TemplateCompiler: require('@vue/compiler-sfc'), // }); vueParser.parseFilesGlob('./src/**/*.@(js|vue)'); extractor.savePotFile('./messages.pot'); extractor.printStats();
Debug
Known issues
gotchaThis package is an extension for `gettext-extractor` and requires it as a peer dependency. Ensure `gettext-extractor` is installed in your project at a compatible version.
fix
Install `gettext-extractor`: `npm install gettext-extractor` or `yarn add gettext-extractor`.
affects: >=1.0
gotchaTo parse Vue Single File Components, you must explicitly provide the correct Vue compiler: either `vue-template-compiler` for Vue 2 or `@vue/compiler-sfc` for Vue 3. These are peer dependencies of `gettext-extractor-vue` and must be installed by your project.
fix
For Vue 2: `npm install vue-template-compiler`. For Vue 3: `npm install @vue/compiler-sfc`.
affects: >=1.0
gotchaWhile the README examples primarily use CommonJS `require()`, the package generally supports both CommonJS and ES Modules. Be consistent with your project's module system. If using ES Modules, use `import` statements.
fix
For ESM: `import { func } from 'gettext-extractor-vue';`. For CJS: `const { func } = require('gettext-extractor-vue');`.
affects: >=1.0
Errors
Common errors & fixes
Error: Cannot find module 'vue-template-compiler' or 'Error: Cannot find module '@vue/compiler-sfc''
The required Vue compiler dependency (either for Vue 2 or Vue 3) was not installed in your project.
fix
Install the appropriate Vue compiler: `npm install vue-template-compiler` for Vue 2, or `npm install @vue/compiler-sfc` for Vue 3.
TypeError: extractor.createJsParser is not a function
The `gettext-extractor` package is either not installed, or an incompatible version is installed, preventing access to its core methods.
fix
Ensure `gettext-extractor` is correctly installed and its version satisfies the peer dependency requirement: `npm install gettext-extractor`.
Upgrade
Version history
5.2.0latest on npm
Audit
Dependencies
gettext-extractorrequiredCore dependency; this package extends its functionality.
vue-template-compileroptionalRequired for parsing Vue 2 Single File Components. Must be installed by the consumer if targeting Vue 2.
@vue/compiler-sfcoptionalRequired for parsing Vue 3 Single File Components. Must be installed by the consumer if targeting Vue 3.
Agent activity
2 hits · last 30 days
node
2
Resources
gettext-extractor-vue — npm install gettext-extractor-vue · libregistry