{"id":10943,"library":"gettext-extractor-vue","title":"Gettext Extractor Vue Support","description":"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.","status":"active","version":"5.2.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install gettext-extractor-vue","lang":"bash","label":"npm"},{"cmd":"yarn add gettext-extractor-vue","lang":"bash","label":"yarn"},{"cmd":"pnpm add gettext-extractor-vue","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency; this package extends its functionality.","package":"gettext-extractor","optional":false},{"reason":"Required for parsing Vue 2 Single File Components. Must be installed by the consumer if targeting Vue 2.","package":"vue-template-compiler","optional":true},{"reason":"Required for parsing Vue 3 Single File Components. Must be installed by the consumer if targeting Vue 3.","package":"@vue/compiler-sfc","optional":true}],"imports":[{"note":"The recommended ES Module import for modern JavaScript projects, though CommonJS `require()` is also supported.","wrong":"const { decorateJSParserWithVueSupport } = require('gettext-extractor-vue');","symbol":"decorateJSParserWithVueSupport","correct":"import { decorateJSParserWithVueSupport } from 'gettext-extractor-vue';"},{"note":"Utility function for adding message transformation, available via both ESM and CommonJS.","wrong":"const { decorateExtractorWithHelpers } = require('gettext-extractor-vue');","symbol":"decorateExtractorWithHelpers","correct":"import { decorateExtractorWithHelpers } from 'gettext-extractor-vue';"},{"note":"Wildcard import for accessing all named exports from the package in an ES Module context.","wrong":"import gettextVue from 'gettext-extractor-vue';","symbol":"* as gettextVue","correct":"import * as gettextVue from 'gettext-extractor-vue';"}],"quickstart":{"code":"const { GettextExtractor, JsExtractors } = require('gettext-extractor');\nconst { decorateJSParserWithVueSupport } = require('gettext-extractor-vue');\n\nconst extractor = new GettextExtractor();\n\nconst jsParser = extractor.createJsParser([\n  JsExtractors.callExpression('getText', {\n    arguments: {\n      text: 0,\n      context: 1,\n    },\n  }),\n  JsExtractors.callExpression('getPlural', {\n    arguments: {\n      text: 1,\n      textPlural: 2,\n      context: 3,\n    },\n  }),\n]);\n\n// For vue@2 support, ensure vue-template-compiler is installed\nlet vueParser = decorateJSParserWithVueSupport(jsParser, {\n  vue2TemplateCompiler: require('vue-template-compiler'),\n});\n// For vue@3 support, ensure @vue/compiler-sfc is installed\n// vueParser = decorateJSParserWithVueSupport(jsParser, {\n//   vue3TemplateCompiler: require('@vue/compiler-sfc'),\n// });\n\nvueParser.parseFilesGlob('./src/**/*.@(js|vue)');\n\nextractor.savePotFile('./messages.pot');\n\nextractor.printStats();","lang":"javascript","description":"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)."},"warnings":[{"fix":"Install `gettext-extractor`: `npm install gettext-extractor` or `yarn add gettext-extractor`.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"For Vue 2: `npm install vue-template-compiler`. For Vue 3: `npm install @vue/compiler-sfc`.","message":"To 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.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"For ESM: `import { func } from 'gettext-extractor-vue';`. For CJS: `const { func } = require('gettext-extractor-vue');`.","message":"While 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.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install the appropriate Vue compiler: `npm install vue-template-compiler` for Vue 2, or `npm install @vue/compiler-sfc` for Vue 3.","cause":"The required Vue compiler dependency (either for Vue 2 or Vue 3) was not installed in your project.","error":"Error: Cannot find module 'vue-template-compiler' or 'Error: Cannot find module '@vue/compiler-sfc''"},{"fix":"Ensure `gettext-extractor` is correctly installed and its version satisfies the peer dependency requirement: `npm install gettext-extractor`.","cause":"The `gettext-extractor` package is either not installed, or an incompatible version is installed, preventing access to its core methods.","error":"TypeError: extractor.createJsParser is not a function"}],"ecosystem":"npm"}