@lingui/metro-transformer 4.12.0
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/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/expo/index.cjs +16 -0
- package/dist/expo/index.d.cts +8 -0
- package/dist/expo/index.d.mts +8 -0
- package/dist/expo/index.d.ts +8 -0
- package/dist/expo/index.mjs +10 -0
- package/dist/react-native/index.cjs +16 -0
- package/dist/react-native/index.d.cts +8 -0
- package/dist/react-native/index.d.mts +8 -0
- package/dist/react-native/index.d.ts +8 -0
- package/dist/react-native/index.mjs +10 -0
- package/dist/shared/metro-transformer.23194d80.d.cts +8 -0
- package/dist/shared/metro-transformer.23194d80.d.mts +8 -0
- package/dist/shared/metro-transformer.23194d80.d.ts +8 -0
- package/dist/shared/metro-transformer.57627695.mjs +66 -0
- package/dist/shared/metro-transformer.5b55be19.cjs +73 -0
- package/package.json +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2022 Tomáš Ehrlich, (c) 2022-2023 Crowdin.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[![License][badge-license]][license]
|
|
2
|
+
[![Version][badge-version]][package]
|
|
3
|
+
[![Downloads][badge-downloads]][package]
|
|
4
|
+
|
|
5
|
+
# @lingui/metro-transformer
|
|
6
|
+
|
|
7
|
+
> Metro bundler transformer for LinguiJS catalogs
|
|
8
|
+
|
|
9
|
+
`@lingui/metro-transformer` is part of [LinguiJS][linguijs]. See the
|
|
10
|
+
[documentation][documentation] for all information, tutorials and examples.
|
|
11
|
+
|
|
12
|
+
## Installation & Usage
|
|
13
|
+
|
|
14
|
+
See the [reference][reference] documentation.
|
|
15
|
+
|
|
16
|
+
## License
|
|
17
|
+
|
|
18
|
+
This package is licensed under [MIT][license] license.
|
|
19
|
+
|
|
20
|
+
[license]: https://github.com/lingui/js-lingui/blob/main/LICENSE
|
|
21
|
+
[linguijs]: https://github.com/lingui/js-lingui
|
|
22
|
+
[documentation]: https://lingui.dev
|
|
23
|
+
[reference]: https://lingui.dev/ref/metro-transformer
|
|
24
|
+
[package]: https://www.npmjs.com/package/@lingui/metro-transformer
|
|
25
|
+
[badge-downloads]: https://img.shields.io/npm/dw/@lingui/metro-transformer.svg
|
|
26
|
+
[badge-version]: https://img.shields.io/npm/v/@lingui/metro-transformer.svg
|
|
27
|
+
[badge-license]: https://img.shields.io/npm/l/@lingui/metro-transformer.svg
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const metroTransformer = require('../shared/metro-transformer.5b55be19.cjs');
|
|
4
|
+
const expoTransformer = require('@expo/metro-config/babel-transformer');
|
|
5
|
+
require('@lingui/conf');
|
|
6
|
+
require('@lingui/cli/api');
|
|
7
|
+
require('path');
|
|
8
|
+
require('memoize-one');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
11
|
+
|
|
12
|
+
const expoTransformer__default = /*#__PURE__*/_interopDefaultCompat(expoTransformer);
|
|
13
|
+
|
|
14
|
+
const transform = metroTransformer.createLinguiMetroTransformer(expoTransformer__default);
|
|
15
|
+
|
|
16
|
+
exports.transform = transform;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { c as createLinguiMetroTransformer } from '../shared/metro-transformer.57627695.mjs';
|
|
2
|
+
import expoTransformer from '@expo/metro-config/babel-transformer';
|
|
3
|
+
import '@lingui/conf';
|
|
4
|
+
import '@lingui/cli/api';
|
|
5
|
+
import 'path';
|
|
6
|
+
import 'memoize-one';
|
|
7
|
+
|
|
8
|
+
const transform = createLinguiMetroTransformer(expoTransformer);
|
|
9
|
+
|
|
10
|
+
export { transform };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const metroTransformer = require('../shared/metro-transformer.5b55be19.cjs');
|
|
4
|
+
const reactNativeTransformer = require('@react-native/metro-babel-transformer');
|
|
5
|
+
require('@lingui/conf');
|
|
6
|
+
require('@lingui/cli/api');
|
|
7
|
+
require('path');
|
|
8
|
+
require('memoize-one');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
11
|
+
|
|
12
|
+
const reactNativeTransformer__default = /*#__PURE__*/_interopDefaultCompat(reactNativeTransformer);
|
|
13
|
+
|
|
14
|
+
const transform = metroTransformer.createLinguiMetroTransformer(reactNativeTransformer__default);
|
|
15
|
+
|
|
16
|
+
exports.transform = transform;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { c as createLinguiMetroTransformer } from '../shared/metro-transformer.57627695.mjs';
|
|
2
|
+
import reactNativeTransformer from '@react-native/metro-babel-transformer';
|
|
3
|
+
import '@lingui/conf';
|
|
4
|
+
import '@lingui/cli/api';
|
|
5
|
+
import 'path';
|
|
6
|
+
import 'memoize-one';
|
|
7
|
+
|
|
8
|
+
const transform = createLinguiMetroTransformer(reactNativeTransformer);
|
|
9
|
+
|
|
10
|
+
export { transform };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { getConfig } from '@lingui/conf';
|
|
2
|
+
import { getCatalogForFile, createCompiledCatalog, getCatalogs } from '@lingui/cli/api';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import memoizeOne from 'memoize-one';
|
|
5
|
+
|
|
6
|
+
const createLinguiMetroTransformer = (upstreamTransformer) => {
|
|
7
|
+
return async function linguiMetroTransformer(params) {
|
|
8
|
+
if (!params.filename.endsWith(".po")) {
|
|
9
|
+
return upstreamTransformer.transform(params);
|
|
10
|
+
}
|
|
11
|
+
const jsSource = await transformFile(params);
|
|
12
|
+
return upstreamTransformer.transform({
|
|
13
|
+
...params,
|
|
14
|
+
src: jsSource
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const getCatalogList = async () => {
|
|
19
|
+
const config = getConfig();
|
|
20
|
+
const allCatalogs = await getCatalogs(config);
|
|
21
|
+
return {
|
|
22
|
+
config,
|
|
23
|
+
allCatalogs
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const memoizedGetCatalogList = memoizeOne(getCatalogList);
|
|
27
|
+
async function transformFile(params) {
|
|
28
|
+
const { config, allCatalogs } = await memoizedGetCatalogList();
|
|
29
|
+
const catalogPathRelativeToProjectRoot = params.filename;
|
|
30
|
+
const catalogPathRelativeToLinguiConfig = path.relative(
|
|
31
|
+
config.rootDir,
|
|
32
|
+
catalogPathRelativeToProjectRoot
|
|
33
|
+
);
|
|
34
|
+
const catalogFile = getCatalogForFile(
|
|
35
|
+
catalogPathRelativeToLinguiConfig,
|
|
36
|
+
allCatalogs
|
|
37
|
+
);
|
|
38
|
+
if (!catalogFile) {
|
|
39
|
+
const absolutePath = path.resolve(catalogPathRelativeToProjectRoot);
|
|
40
|
+
throw new Error(
|
|
41
|
+
`Requested resource ${catalogPathRelativeToProjectRoot} (absolute path: ${absolutePath}) is not matched to any of your catalogs paths specified in "lingui.config".
|
|
42
|
+
|
|
43
|
+
Your catalogs:
|
|
44
|
+
${config.catalogs.map((c) => c.path).join("\n")}
|
|
45
|
+
|
|
46
|
+
Working dir is:
|
|
47
|
+
${process.cwd()}
|
|
48
|
+
|
|
49
|
+
Please check that \`catalogs.path\` is filled properly and restart the Metro server.
|
|
50
|
+
`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
const { locale, catalog } = catalogFile;
|
|
54
|
+
const messages = await catalog.getTranslations(locale, {
|
|
55
|
+
fallbackLocales: config.fallbackLocales,
|
|
56
|
+
sourceLocale: config.sourceLocale
|
|
57
|
+
});
|
|
58
|
+
const strict = process.env.NODE_ENV !== "production";
|
|
59
|
+
return createCompiledCatalog(locale, messages, {
|
|
60
|
+
strict,
|
|
61
|
+
namespace: "es",
|
|
62
|
+
pseudoLocale: config.pseudoLocale
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { createLinguiMetroTransformer as c };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const conf = require('@lingui/conf');
|
|
4
|
+
const api = require('@lingui/cli/api');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const memoizeOne = require('memoize-one');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
9
|
+
|
|
10
|
+
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
11
|
+
const memoizeOne__default = /*#__PURE__*/_interopDefaultCompat(memoizeOne);
|
|
12
|
+
|
|
13
|
+
const createLinguiMetroTransformer = (upstreamTransformer) => {
|
|
14
|
+
return async function linguiMetroTransformer(params) {
|
|
15
|
+
if (!params.filename.endsWith(".po")) {
|
|
16
|
+
return upstreamTransformer.transform(params);
|
|
17
|
+
}
|
|
18
|
+
const jsSource = await transformFile(params);
|
|
19
|
+
return upstreamTransformer.transform({
|
|
20
|
+
...params,
|
|
21
|
+
src: jsSource
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const getCatalogList = async () => {
|
|
26
|
+
const config = conf.getConfig();
|
|
27
|
+
const allCatalogs = await api.getCatalogs(config);
|
|
28
|
+
return {
|
|
29
|
+
config,
|
|
30
|
+
allCatalogs
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const memoizedGetCatalogList = memoizeOne__default(getCatalogList);
|
|
34
|
+
async function transformFile(params) {
|
|
35
|
+
const { config, allCatalogs } = await memoizedGetCatalogList();
|
|
36
|
+
const catalogPathRelativeToProjectRoot = params.filename;
|
|
37
|
+
const catalogPathRelativeToLinguiConfig = path__default.relative(
|
|
38
|
+
config.rootDir,
|
|
39
|
+
catalogPathRelativeToProjectRoot
|
|
40
|
+
);
|
|
41
|
+
const catalogFile = api.getCatalogForFile(
|
|
42
|
+
catalogPathRelativeToLinguiConfig,
|
|
43
|
+
allCatalogs
|
|
44
|
+
);
|
|
45
|
+
if (!catalogFile) {
|
|
46
|
+
const absolutePath = path__default.resolve(catalogPathRelativeToProjectRoot);
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Requested resource ${catalogPathRelativeToProjectRoot} (absolute path: ${absolutePath}) is not matched to any of your catalogs paths specified in "lingui.config".
|
|
49
|
+
|
|
50
|
+
Your catalogs:
|
|
51
|
+
${config.catalogs.map((c) => c.path).join("\n")}
|
|
52
|
+
|
|
53
|
+
Working dir is:
|
|
54
|
+
${process.cwd()}
|
|
55
|
+
|
|
56
|
+
Please check that \`catalogs.path\` is filled properly and restart the Metro server.
|
|
57
|
+
`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
const { locale, catalog } = catalogFile;
|
|
61
|
+
const messages = await catalog.getTranslations(locale, {
|
|
62
|
+
fallbackLocales: config.fallbackLocales,
|
|
63
|
+
sourceLocale: config.sourceLocale
|
|
64
|
+
});
|
|
65
|
+
const strict = process.env.NODE_ENV !== "production";
|
|
66
|
+
return api.createCompiledCatalog(locale, messages, {
|
|
67
|
+
strict,
|
|
68
|
+
namespace: "es",
|
|
69
|
+
pseudoLocale: config.pseudoLocale
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
exports.createLinguiMetroTransformer = createLinguiMetroTransformer;
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lingui/metro-transformer",
|
|
3
|
+
"version": "4.12.0",
|
|
4
|
+
"description": "Metro bundler transformer for LinguiJS catalogs",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./expo": {
|
|
7
|
+
"require": "./dist/expo/index.cjs",
|
|
8
|
+
"import": "./dist/expo/index.mjs",
|
|
9
|
+
"types": "./dist/expo/index.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./react-native": {
|
|
12
|
+
"require": "./dist/react-native/index.cjs",
|
|
13
|
+
"import": "./dist/react-native/index.mjs",
|
|
14
|
+
"types": "./dist/react-native/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Vojtech Novak",
|
|
23
|
+
"email": "vonovak@gmail.com"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"metro",
|
|
28
|
+
"react native",
|
|
29
|
+
"metro bundler",
|
|
30
|
+
"i18n",
|
|
31
|
+
"internationalization",
|
|
32
|
+
"i10n",
|
|
33
|
+
"localization",
|
|
34
|
+
"i9n",
|
|
35
|
+
"translation",
|
|
36
|
+
"multilingual"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "rimraf ./dist && unbuild",
|
|
40
|
+
"stub": "unbuild --stub"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/lingui/js-lingui.git"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/lingui/js-lingui/issues"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=16.0.0"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"LICENSE",
|
|
54
|
+
"README.md",
|
|
55
|
+
"dist/"
|
|
56
|
+
],
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@babel/runtime": "^7.20.13",
|
|
59
|
+
"@lingui/cli": "4.11.2",
|
|
60
|
+
"@lingui/conf": "4.11.2",
|
|
61
|
+
"memoize-one": "^6.0.0"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@lingui/format-json": "4.11.2",
|
|
65
|
+
"rimraf": "^6.0.1",
|
|
66
|
+
"unbuild": "2.0.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"@expo/metro-config": "*",
|
|
70
|
+
"@react-native/metro-babel-transformer": "*",
|
|
71
|
+
"expo": ">=50.0.0",
|
|
72
|
+
"metro": "*",
|
|
73
|
+
"react-native": ">=0.73.0"
|
|
74
|
+
},
|
|
75
|
+
"peerDependenciesMeta": {
|
|
76
|
+
"@expo/metro-config": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"@react-native/metro-babel-transformer": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"expo": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"gitHead": "83a6ea03f22d6284bdcf067bde7b406c4e3520bc"
|
|
87
|
+
}
|