@lingui/vite-plugin 3.16.1
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 +50 -0
- package/build/LICENSE +21 -0
- package/build/index.d.ts +8 -0
- package/build/index.js +41 -0
- package/build/index.js.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[![License][badge-license]][license]
|
|
2
|
+
[![Version][badge-version]][package]
|
|
3
|
+
[![Downloads][badge-downloads]][package]
|
|
4
|
+
|
|
5
|
+
# @lingui/vite-plugin
|
|
6
|
+
|
|
7
|
+
> Vite plugin which compiles on the fly the .po files for auto-refreshing. In summary, `lingui compile` command isn't required when using this plugin
|
|
8
|
+
|
|
9
|
+
`@lingui/vite-plugin` 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/vite-plugin
|
|
15
|
+
# yarn add --dev @lingui/vite-plugin
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Via `vite.config.ts`
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { UserConfig } from 'vite';
|
|
24
|
+
import lingui from '@lingui/vite-plugin'
|
|
25
|
+
|
|
26
|
+
const config: UserConfig = {
|
|
27
|
+
plugins: [lingui()]
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Then in Vite-processed code:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const { messages } = await import(`./locales/${language}.po`);
|
|
35
|
+
```
|
|
36
|
+
> See Vite's official documentation for more info about Vite dynamic imports
|
|
37
|
+
> https://vitejs.dev/guide/features.html#dynamic-import
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
[MIT][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/
|
|
47
|
+
[package]: https://www.npmjs.com/package/@lingui/vite-plugin
|
|
48
|
+
[badge-downloads]: https://img.shields.io/npm/dw/@lingui/vite-plugin.svg
|
|
49
|
+
[badge-version]: https://img.shields.io/npm/v/@lingui/vite-plugin.svg
|
|
50
|
+
[badge-license]: https://img.shields.io/npm/l/@lingui/vite-plugin.svg
|
package/build/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/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const conf_1 = require("@lingui/conf");
|
|
7
|
+
const api_1 = require("@lingui/cli/api");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fileRegex = /\.(po)$/;
|
|
10
|
+
function lingui(linguiConfig = {}) {
|
|
11
|
+
const config = conf_1.getConfig(linguiConfig);
|
|
12
|
+
return {
|
|
13
|
+
name: 'vite-plugin-lingui',
|
|
14
|
+
transform(src, id) {
|
|
15
|
+
if (fileRegex.test(id)) {
|
|
16
|
+
const catalogRelativePath = path_1.default.relative(config.rootDir, id);
|
|
17
|
+
const fileCatalog = api_1.getCatalogForFile(catalogRelativePath, api_1.getCatalogs(config));
|
|
18
|
+
const { locale, catalog } = fileCatalog;
|
|
19
|
+
const catalogs = catalog.readAll();
|
|
20
|
+
const messages = Object.keys(catalogs[locale]).reduce((acc, key) => {
|
|
21
|
+
acc[key] = catalog.getTranslation(catalogs, locale, key, {
|
|
22
|
+
fallbackLocales: config.fallbackLocales,
|
|
23
|
+
sourceLocale: config.sourceLocale,
|
|
24
|
+
});
|
|
25
|
+
return acc;
|
|
26
|
+
}, {});
|
|
27
|
+
const compiled = api_1.createCompiledCatalog(locale, messages, {
|
|
28
|
+
strict: false,
|
|
29
|
+
namespace: 'es',
|
|
30
|
+
pseudoLocale: config.pseudoLocale,
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
code: compiled,
|
|
34
|
+
map: null,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
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D,MAAM,EAAE,KAAK;oBACb,SAAS,EAAE,IAAI;oBACf,YAAY,EAAE,MAAM,CAAC,YAAY;iBAClC,CAAC,CAAC;gBAEH,OAAO;oBACL,IAAI,EAAE,QAAQ;oBACd,GAAG,EAAE,IAAI;iBACV,CAAC;aACH;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAxCD,yBAwCC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lingui/vite-plugin",
|
|
3
|
+
"version": "3.16.1",
|
|
4
|
+
"description": "Vite plugin for Lingui message catalogs",
|
|
5
|
+
"main": "./build/index.js",
|
|
6
|
+
"types": "./build/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"vite-plugin",
|
|
10
|
+
"i18n",
|
|
11
|
+
"vite",
|
|
12
|
+
"linguijs",
|
|
13
|
+
"internationalization",
|
|
14
|
+
"i10n",
|
|
15
|
+
"localization",
|
|
16
|
+
"i9n",
|
|
17
|
+
"translation"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rimraf ./build && tsc"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/lingui/js-lingui.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/lingui/js-lingui/issues"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=14.0.0"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"README.md",
|
|
35
|
+
"build/"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@lingui/cli": "^3.16.1",
|
|
39
|
+
"@lingui/conf": "^3.16.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"vite": "3.2.4"
|
|
43
|
+
}
|
|
44
|
+
}
|