@lingui/extractor-vue 4.0.0-next.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ [![License][badge-license]][license]
2
+ [![Version][badge-version]][package]
3
+ [![Downloads][badge-downloads]][package]
4
+
5
+ # @lingui/vue-extractor
6
+
7
+ This package contains a custom extractor that handles Vue.js files. It supports extracting messages from script and setup scripts as well as Vue templates.
8
+
9
+ `@lingui/vue-extractor` is part of [LinguiJS][linguijs]. See the [documentation][documentation] for all information, tutorials and examples.
10
+
11
+ ## Installation
12
+
13
+ ```sh
14
+ npm install --save-dev @lingui/extractor-vue
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ This custom extractor requires that you use JavaScript for your Lingui configuration.
20
+
21
+ ```js
22
+ import { vueExtractor } from "@lingui/extractor-vue"
23
+ import babel from "@lingui/cli/api/extractors/babel"
24
+
25
+ const linguiConfig = {
26
+ locales: ["en", "nb"],
27
+ sourceLocale: "en",
28
+ catalogs: [
29
+ {
30
+ path: "<rootDir>/src/{locale}",
31
+ include: ["<rootDir>/src"],
32
+ },
33
+ ],
34
+ extractors: [babel, vueExtractor],
35
+ }
36
+
37
+ export default linguiConfig
38
+ ```
39
+
40
+ ## License
41
+
42
+ This package is licensed under [MIT][license] license.
43
+
44
+ [license]: https://github.com/lingui/js-lingui/blob/main/LICENSE
45
+ [linguijs]: https://github.com/lingui/js-lingui
46
+ [documentation]: https://lingui.dev/tutorials/extractor-vue
package/dist/index.cjs ADDED
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ const compilerSfc = require('@vue/compiler-sfc');
4
+ const babel = require('@lingui/cli/api/extractors/babel');
5
+
6
+ const vueExtractor = {
7
+ match(filename) {
8
+ return filename.endsWith(".vue");
9
+ },
10
+ async extract(filename, code, onMessageExtracted, ctx) {
11
+ const { descriptor } = compilerSfc.parse(code, {
12
+ sourceMap: true,
13
+ filename,
14
+ ignoreEmpty: true
15
+ });
16
+ const compiledTemplate = compilerSfc.compileTemplate({
17
+ source: descriptor.template.content,
18
+ filename,
19
+ inMap: descriptor.template.map,
20
+ id: filename
21
+ });
22
+ const isTsBlock = (block) => block?.lang === "ts";
23
+ const targets = [
24
+ [
25
+ descriptor.script?.content,
26
+ descriptor.script?.map,
27
+ isTsBlock(descriptor.script)
28
+ ],
29
+ [
30
+ descriptor.scriptSetup?.content,
31
+ descriptor.scriptSetup?.map,
32
+ isTsBlock(descriptor.scriptSetup)
33
+ ],
34
+ [
35
+ compiledTemplate?.code,
36
+ compiledTemplate?.map,
37
+ isTsBlock(descriptor.script) || isTsBlock(descriptor.scriptSetup)
38
+ ]
39
+ ];
40
+ await Promise.all(
41
+ targets.filter(([source]) => Boolean(source)).map(
42
+ ([source, map, isTs]) => babel.extract(
43
+ filename + (isTs ? ".ts" : ""),
44
+ source,
45
+ onMessageExtracted,
46
+ {
47
+ sourceMaps: map,
48
+ ...ctx
49
+ }
50
+ )
51
+ )
52
+ );
53
+ }
54
+ };
55
+
56
+ exports.vueExtractor = vueExtractor;
@@ -0,0 +1,5 @@
1
+ import { ExtractorType } from '@lingui/conf';
2
+
3
+ declare const vueExtractor: ExtractorType;
4
+
5
+ export { vueExtractor };
package/dist/index.mjs ADDED
@@ -0,0 +1,54 @@
1
+ import { parse, compileTemplate } from '@vue/compiler-sfc';
2
+ import babel from '@lingui/cli/api/extractors/babel';
3
+
4
+ const vueExtractor = {
5
+ match(filename) {
6
+ return filename.endsWith(".vue");
7
+ },
8
+ async extract(filename, code, onMessageExtracted, ctx) {
9
+ const { descriptor } = parse(code, {
10
+ sourceMap: true,
11
+ filename,
12
+ ignoreEmpty: true
13
+ });
14
+ const compiledTemplate = compileTemplate({
15
+ source: descriptor.template.content,
16
+ filename,
17
+ inMap: descriptor.template.map,
18
+ id: filename
19
+ });
20
+ const isTsBlock = (block) => block?.lang === "ts";
21
+ const targets = [
22
+ [
23
+ descriptor.script?.content,
24
+ descriptor.script?.map,
25
+ isTsBlock(descriptor.script)
26
+ ],
27
+ [
28
+ descriptor.scriptSetup?.content,
29
+ descriptor.scriptSetup?.map,
30
+ isTsBlock(descriptor.scriptSetup)
31
+ ],
32
+ [
33
+ compiledTemplate?.code,
34
+ compiledTemplate?.map,
35
+ isTsBlock(descriptor.script) || isTsBlock(descriptor.scriptSetup)
36
+ ]
37
+ ];
38
+ await Promise.all(
39
+ targets.filter(([source]) => Boolean(source)).map(
40
+ ([source, map, isTs]) => babel.extract(
41
+ filename + (isTs ? ".ts" : ""),
42
+ source,
43
+ onMessageExtracted,
44
+ {
45
+ sourceMaps: map,
46
+ ...ctx
47
+ }
48
+ )
49
+ )
50
+ );
51
+ }
52
+ };
53
+
54
+ export { vueExtractor };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@lingui/extractor-vue",
3
+ "version": "4.0.0-next.7",
4
+ "description": "Custom Vue.js extractor to be used with the CLI tool",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "keywords": [
9
+ "cli",
10
+ "i18n",
11
+ "internationalization",
12
+ "i10n",
13
+ "localization",
14
+ "i9n",
15
+ "translation",
16
+ "vue"
17
+ ],
18
+ "repository": "lingui/js-lingui",
19
+ "bugs": "https://github.com/lingui/js-lingui/issues",
20
+ "license": "MIT",
21
+ "author": {
22
+ "name": "Christoffer Jahren",
23
+ "email": "christoffer@jahren.it"
24
+ },
25
+ "scripts": {
26
+ "build": "rimraf ./dist && unbuild",
27
+ "stub": "unbuild --stub"
28
+ },
29
+ "engines": {
30
+ "node": ">=16.0.0"
31
+ },
32
+ "files": [
33
+ "LICENSE",
34
+ "README.md",
35
+ "/dist"
36
+ ],
37
+ "dependencies": {
38
+ "@lingui/cli": "^4.0.0-next.7",
39
+ "@lingui/conf": "^4.0.0-next.7",
40
+ "@vue/compiler-sfc": "^3.2.47"
41
+ },
42
+ "devDependencies": {
43
+ "@lingui/babel-plugin-extract-messages": "^4.0.0-next.7",
44
+ "unbuild": "^1.1.2"
45
+ }
46
+ }