@leancodepl/intl 9.4.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/CHANGELOG.md +42 -0
- package/README.md +154 -0
- package/package.json +25 -0
- package/src/TranslationsServiceClient.d.ts +13 -0
- package/src/TranslationsServiceClient.js +3 -0
- package/src/TranslationsServiceClient.js.map +1 -0
- package/src/bin.d.ts +2 -0
- package/src/bin.js +129 -0
- package/src/bin.js.map +1 -0
- package/src/commands/diff.d.ts +9 -0
- package/src/commands/diff.js +35 -0
- package/src/commands/diff.js.map +1 -0
- package/src/commands/download.d.ts +10 -0
- package/src/commands/download.js +39 -0
- package/src/commands/download.js.map +1 -0
- package/src/commands/local.d.ts +11 -0
- package/src/commands/local.js +117 -0
- package/src/commands/local.js.map +1 -0
- package/src/commands/sync.d.ts +12 -0
- package/src/commands/sync.js +34 -0
- package/src/commands/sync.js.map +1 -0
- package/src/commands/upload.d.ts +10 -0
- package/src/commands/upload.js +32 -0
- package/src/commands/upload.js.map +1 -0
- package/src/formatjs.d.ts +21 -0
- package/src/formatjs.js +60 -0
- package/src/formatjs.js.map +1 -0
- package/src/index.d.ts +6 -0
- package/src/index.js +16 -0
- package/src/index.js.map +1 -0
- package/src/mergeWithEnv.d.ts +7 -0
- package/src/mergeWithEnv.js +14 -0
- package/src/mergeWithEnv.js.map +1 -0
- package/src/mkTranslationsServiceClient.d.ts +5 -0
- package/src/mkTranslationsServiceClient.js +14 -0
- package/src/mkTranslationsServiceClient.js.map +1 -0
- package/src/poeditor/POEditorClient.d.ts +19 -0
- package/src/poeditor/POEditorClient.js +88 -0
- package/src/poeditor/POEditorClient.js.map +1 -0
- package/src/poeditor/api.generated/api.d.ts +2570 -0
- package/src/poeditor/api.generated/api.js +2586 -0
- package/src/poeditor/api.generated/api.js.map +1 -0
- package/src/poeditor/api.generated/base.d.ts +66 -0
- package/src/poeditor/api.generated/base.js +70 -0
- package/src/poeditor/api.generated/base.js.map +1 -0
- package/src/poeditor/api.generated/common.d.ts +65 -0
- package/src/poeditor/api.generated/common.js +146 -0
- package/src/poeditor/api.generated/common.js.map +1 -0
- package/src/poeditor/api.generated/configuration.d.ts +91 -0
- package/src/poeditor/api.generated/configuration.js +100 -0
- package/src/poeditor/api.generated/configuration.js.map +1 -0
- package/src/poeditor/api.generated/index.d.ts +13 -0
- package/src/poeditor/api.generated/index.js +18 -0
- package/src/poeditor/api.generated/index.js.map +1 -0
- package/src/poeditor/generatePoeditorClient.d.ts +1 -0
- package/src/poeditor/generatePoeditorClient.js +54 -0
- package/src/poeditor/generatePoeditorClient.js.map +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See
|
|
4
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [9.4.0](https://github.com/leancodepl/js_corelibrary/compare/v9.3.0...v9.4.0) (2025-08-04)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- add missing newlines
|
|
11
|
+
([bb92465](https://github.com/leancodepl/js_corelibrary/commit/bb9246509b83c2d1ba2f0a120d93bdd72ef34184))
|
|
12
|
+
- add newline in intl project.json
|
|
13
|
+
([a18bdb1](https://github.com/leancodepl/js_corelibrary/commit/a18bdb1a6855b1ba3c2c5234391368f5305830c8))
|
|
14
|
+
- add newline to intl package .gitignore in the end of file
|
|
15
|
+
([c426fdf](https://github.com/leancodepl/js_corelibrary/commit/c426fdf3dbe172539a576b085b091729b4d7be83))
|
|
16
|
+
- generating poeditor client target
|
|
17
|
+
([4c83d51](https://github.com/leancodepl/js_corelibrary/commit/4c83d51985ae8515a5f35889ed09f7d00ae7de0e))
|
|
18
|
+
- package-lock.json including local registry
|
|
19
|
+
([630b3e5](https://github.com/leancodepl/js_corelibrary/commit/630b3e5296004801189636954331b991521dcea6))
|
|
20
|
+
- poeditor api token option naming
|
|
21
|
+
([785d7dc](https://github.com/leancodepl/js_corelibrary/commit/785d7dcd2a3d8c2f33bd549faf244c8af6bbce3b))
|
|
22
|
+
- remove redundant console logging in diff command
|
|
23
|
+
([2aa68aa](https://github.com/leancodepl/js_corelibrary/commit/2aa68aaebfe5d632c85301e6c10fe379de618c2e))
|
|
24
|
+
- remove redundant properties typing in POEditorClient
|
|
25
|
+
([004416a](https://github.com/leancodepl/js_corelibrary/commit/004416a9f9224c9e244193a5ef7ec7d9be938133))
|
|
26
|
+
- remove unnecessary check for module in generate POE client script
|
|
27
|
+
([904c282](https://github.com/leancodepl/js_corelibrary/commit/904c2823adb226da864d9a8bc0cedda92696a912))
|
|
28
|
+
- use undefined instead of null
|
|
29
|
+
([7392123](https://github.com/leancodepl/js_corelibrary/commit/73921230b3a5cbb67afdc0970a7a5cf55bf6fe6a))
|
|
30
|
+
- zod version for intl package
|
|
31
|
+
([a8dee10](https://github.com/leancodepl/js_corelibrary/commit/a8dee1045502a516e3bd41c551bdf5194358294c))
|
|
32
|
+
|
|
33
|
+
### Features
|
|
34
|
+
|
|
35
|
+
- add intl package
|
|
36
|
+
([5b6d3f5](https://github.com/leancodepl/js_corelibrary/commit/5b6d3f5848f957a0bdb13890eb13080e931cef96))
|
|
37
|
+
- add zod schemas to options
|
|
38
|
+
([9bdc2b3](https://github.com/leancodepl/js_corelibrary/commit/9bdc2b377ff0acc959afe4fb4bc33f757067fc1c))
|
|
39
|
+
- remove logging terms used locally but not in remote
|
|
40
|
+
([61399ed](https://github.com/leancodepl/js_corelibrary/commit/61399ed6f53cdbdf8f920d655aa9bedfdd917166))
|
|
41
|
+
- rework local command
|
|
42
|
+
([e4820db](https://github.com/leancodepl/js_corelibrary/commit/e4820dbeccf01163aa216a7e271be9383f9314e4))
|
package/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# @leancodepl/intl
|
|
2
|
+
|
|
3
|
+
A command-line tool for managing FormatJS translations with POEditor integration. Extracts messages from TypeScript/React source files, uploads terms to POEditor, downloads translations, and compiles them for use in internationalized applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install -D @leancodepl/intl
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npx @leancodepl/intl <command> [options]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
|
|
19
|
+
Configure POEditor credentials using environment variables:
|
|
20
|
+
|
|
21
|
+
- `POEDITOR_API_TOKEN` - POEditor API token (required for upload, download, sync, and diff commands)
|
|
22
|
+
- `POEDITOR_PROJECT_ID` - POEditor project ID (required for upload, download, sync, and diff commands)
|
|
23
|
+
|
|
24
|
+
## Commands
|
|
25
|
+
|
|
26
|
+
### `local`
|
|
27
|
+
|
|
28
|
+
Extracts FormatJS messages from source files. When POEditor credentials are provided, merges extracted messages with downloaded translations for default language.
|
|
29
|
+
Downloaded translations are not overridden - only new terms added during development are added to translations file.
|
|
30
|
+
Use this command during development to fix build errors after adding new term in code.
|
|
31
|
+
|
|
32
|
+
**Usage:**
|
|
33
|
+
```sh
|
|
34
|
+
npx @leancodepl/intl local [options]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Options:**
|
|
38
|
+
- `-s, --src-pattern <pattern>` - Source file pattern for extraction (default: `"src/**/*.{ts,tsx}"`)
|
|
39
|
+
- `-o, --output-dir <dir>` - Output directory for compiled translations (default: `"lang"`)
|
|
40
|
+
- `-d, --default-language <lang>` - Default language for translations (required when using POEditor integration)
|
|
41
|
+
- `-t, --poeditor-api-token <token>` - POEditor API token (overrides `POEDITOR_API_TOKEN` env var)
|
|
42
|
+
- `-p, --poeditor-project-id <id>` - POEditor project ID (overrides `POEDITOR_PROJECT_ID` env var)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### `upload`
|
|
47
|
+
|
|
48
|
+
Extracts FormatJS messages from source files and uploads both terms and default language translations to POEditor.
|
|
49
|
+
|
|
50
|
+
**Usage:**
|
|
51
|
+
```sh
|
|
52
|
+
npx @leancodepl/intl upload [options]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Options:**
|
|
56
|
+
- `-s, --src-pattern <pattern>` - Source file pattern for extraction (default: `"src/**/*.{ts,tsx}"`)
|
|
57
|
+
- `-d, --default-language <lang>` - Default language for translations (required)
|
|
58
|
+
- `-t, --poeditor-api-token <token>` - POEditor API token (overrides `POEDITOR_API_TOKEN` env var, required)
|
|
59
|
+
- `-p, --poeditor-project-id <id>` - POEditor project ID (overrides `POEDITOR_PROJECT_ID` env var, required)
|
|
60
|
+
|
|
61
|
+
### `download`
|
|
62
|
+
|
|
63
|
+
Downloads translations from POEditor for specified languages and compiles them to JSON files.
|
|
64
|
+
|
|
65
|
+
**Usage:**
|
|
66
|
+
```sh
|
|
67
|
+
npx @leancodepl/intl download [options]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Options:**
|
|
71
|
+
- `-o, --output-dir <dir>` - Output directory for compiled translations (default: `"lang"`)
|
|
72
|
+
- `-l, --languages <langs...>` - Languages to download (space-separated list, required)
|
|
73
|
+
- `-t, --poeditor-api-token <token>` - POEditor API token (overrides `POEDITOR_API_TOKEN` env var, required)
|
|
74
|
+
- `-p, --poeditor-project-id <id>` - POEditor project ID (overrides `POEDITOR_PROJECT_ID` env var, required)
|
|
75
|
+
|
|
76
|
+
### `sync`
|
|
77
|
+
|
|
78
|
+
Combines upload and download operations. Uploads extracted terms and default language translations to POEditor, then downloads and compiles translations for specified languages.
|
|
79
|
+
|
|
80
|
+
**Usage:**
|
|
81
|
+
```sh
|
|
82
|
+
npx @leancodepl/intl sync [options]
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Options:**
|
|
86
|
+
- `-s, --src-pattern <pattern>` - Source file pattern for extraction (default: `"src/**/*.{ts,tsx}"`)
|
|
87
|
+
- `-o, --output-dir <dir>` - Output directory for compiled translations (default: `"lang"`)
|
|
88
|
+
- `-l, --languages <langs...>` - Languages to download (space-separated list, required)
|
|
89
|
+
- `-d, --default-language <lang>` - Default language for translations (required)
|
|
90
|
+
- `-t, --poeditor-api-token <token>` - POEditor API token (overrides `POEDITOR_API_TOKEN` env var, required)
|
|
91
|
+
- `-p, --poeditor-project-id <id>` - POEditor project ID (overrides `POEDITOR_PROJECT_ID` env var, required)
|
|
92
|
+
|
|
93
|
+
### `diff`
|
|
94
|
+
|
|
95
|
+
Compares locally extracted terms with POEditor terms to identify unused terms in the translation service. Helps maintain clean translation projects by finding orphaned entries.
|
|
96
|
+
|
|
97
|
+
**Usage:**
|
|
98
|
+
```sh
|
|
99
|
+
npx @leancodepl/intl diff [options]
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Options:**
|
|
103
|
+
- `-s, --src-pattern <pattern>` - Source file pattern for extraction (default: `"src/**/*.{ts,tsx}"`)
|
|
104
|
+
- `-t, --poeditor-api-token <token>` - POEditor API token (overrides `POEDITOR_API_TOKEN` env var, required)
|
|
105
|
+
- `-p, --poeditor-project-id <id>` - POEditor project ID (overrides `POEDITOR_PROJECT_ID` env var, required)
|
|
106
|
+
|
|
107
|
+
## Nx Configuration
|
|
108
|
+
|
|
109
|
+
Configure intl commands as Nx target in your `project.json`. Example configuration:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
"intl": {
|
|
113
|
+
"executor": "nx:run-commands",
|
|
114
|
+
"defaultConfiguration": "local",
|
|
115
|
+
"configurations": {
|
|
116
|
+
"local": {
|
|
117
|
+
"command": "npx @leancodepl/intl local --src-pattern 'src/**/*.{ts,tsx}' --output-dir '{projectRoot}/lang' --default-language pl --poeditor-project-id 123456"
|
|
118
|
+
},
|
|
119
|
+
"download": {
|
|
120
|
+
"command": "npx @leancodepl/intl download --output-dir '{projectRoot}/lang' --languages pl en --poeditor-project-id 123456"
|
|
121
|
+
},
|
|
122
|
+
"diff": {
|
|
123
|
+
"command": "npx @leancodepl/intl diff --src-pattern 'src/**/*.{ts,tsx}' --poeditor-project-id 123456"
|
|
124
|
+
},
|
|
125
|
+
"upload": {
|
|
126
|
+
"command": "npx @leancodepl/intl upload --src-pattern 'src/**/*.{ts,tsx}' --default-language pl --poeditor-project-id 123456"
|
|
127
|
+
},
|
|
128
|
+
"sync": {
|
|
129
|
+
"command": "npx @leancodepl/intl sync --src-pattern 'src/**/*.{ts,tsx}' --output-dir '{projectRoot}/lang' --languages pl en --default-language pl --poeditor-project-id 123456"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Local Development
|
|
136
|
+
|
|
137
|
+
To simplify local development tests can be used with real POEditor integration.
|
|
138
|
+
|
|
139
|
+
### Running Tests
|
|
140
|
+
|
|
141
|
+
#### Run tests with POEditor integration
|
|
142
|
+
Set the following environment variables:
|
|
143
|
+
|
|
144
|
+
- `POEDITOR_API_TOKEN`: Your POEditor API token
|
|
145
|
+
- `POEDITOR_PROJECT_ID`: Your POEditor project ID
|
|
146
|
+
|
|
147
|
+
To run specific command run only test for that command. Example for `local` command:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
POEDITOR_API_TOKEN=your_token POEDITOR_PROJECT_ID=your_project_id npx nx test intl -- local.spec.ts
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Tests will use predefined test project for extracting example messages and will save outputs in `/__tests__/testProject/lang`.
|
|
154
|
+
Be careful with running `sync` and `upload` commands. Terms extracted from example project will be added to your POEditor project!
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leancodepl/intl",
|
|
3
|
+
"version": "9.4.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"bin": {
|
|
6
|
+
"intl": "src/bin.js"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@formatjs/cli": "^6.2.15",
|
|
10
|
+
"axios": "^1.7.9",
|
|
11
|
+
"commander": "^12.0.0",
|
|
12
|
+
"lodash": "^4.17.21",
|
|
13
|
+
"tslib": "^2.8.1",
|
|
14
|
+
"zod": "^4.0.5"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@openapitools/openapi-generator-cli": "^2.15.0",
|
|
18
|
+
"@types/lodash": "^4.17.20",
|
|
19
|
+
"react": "^18.0.0",
|
|
20
|
+
"react-intl": "^6.0.0"
|
|
21
|
+
},
|
|
22
|
+
"types": "./src/index.d.ts",
|
|
23
|
+
"main": "./src/index.js",
|
|
24
|
+
"type": "commonjs"
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ExtractedMessages } from "./formatjs";
|
|
2
|
+
export interface Term {
|
|
3
|
+
term: string;
|
|
4
|
+
context?: string;
|
|
5
|
+
reference?: string;
|
|
6
|
+
comment?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TranslationsServiceClient {
|
|
9
|
+
downloadTranslations(language: string): Promise<Record<string, string>>;
|
|
10
|
+
uploadTerms(messages: ExtractedMessages): Promise<void>;
|
|
11
|
+
uploadTranslations(messages: ExtractedMessages, language: string): Promise<void>;
|
|
12
|
+
downloadTerms(): Promise<Term[]>;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TranslationsServiceClient.js","sourceRoot":"","sources":["../../../../packages/intl/src/TranslationsServiceClient.ts"],"names":[],"mappings":""}
|
package/src/bin.d.ts
ADDED
package/src/bin.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const v4_1 = require("zod/v4");
|
|
6
|
+
const diff_1 = require("./commands/diff");
|
|
7
|
+
const download_1 = require("./commands/download");
|
|
8
|
+
const local_1 = require("./commands/local");
|
|
9
|
+
const sync_1 = require("./commands/sync");
|
|
10
|
+
const upload_1 = require("./commands/upload");
|
|
11
|
+
const mergeWithEnv_1 = require("./mergeWithEnv");
|
|
12
|
+
const mkTranslationsServiceClient_1 = require("./mkTranslationsServiceClient");
|
|
13
|
+
const translationsServiceOptionsSchema = v4_1.z.object({
|
|
14
|
+
poeditorApiToken: v4_1.z.string().optional(),
|
|
15
|
+
poeditorProjectId: v4_1.z.number().optional(),
|
|
16
|
+
});
|
|
17
|
+
commander_1.program.name("intl").description("CLI tool for managing formatjs translations with translation services");
|
|
18
|
+
commander_1.program
|
|
19
|
+
.command("local")
|
|
20
|
+
.description("Extract, download from translation service, and compile formatjs translations locally")
|
|
21
|
+
.option("-s, --src-pattern <pattern>", "Source file pattern for extraction", "src/**/*.{ts,tsx}")
|
|
22
|
+
.option("-o, --output-dir <dir>", "Output directory for compiled translations", "lang")
|
|
23
|
+
.option("-d, --default-language <lang>", "Default language for translations")
|
|
24
|
+
.option("-t, --poeditor-api-token <token>", "POEditor API token (can also use POEDITOR_API_TOKEN env var)")
|
|
25
|
+
.option("-p, --poeditor-project-id <id>", "POEditor project ID", value => parseInt(value, 10))
|
|
26
|
+
.action(async (options) => {
|
|
27
|
+
const parsedOptions = local_1.localCommandOptionsSchema.extend(translationsServiceOptionsSchema.shape).parse(options);
|
|
28
|
+
const config = (0, mergeWithEnv_1.mergeWithEnv)(parsedOptions);
|
|
29
|
+
const translationsServiceClient = config.poeditorApiToken && config.poeditorProjectId
|
|
30
|
+
? (0, mkTranslationsServiceClient_1.mkTranslationsServiceClient)({
|
|
31
|
+
poeditorApiToken: config.poeditorApiToken,
|
|
32
|
+
poeditorProjectId: config.poeditorProjectId,
|
|
33
|
+
})
|
|
34
|
+
: undefined;
|
|
35
|
+
await (0, local_1.local)({
|
|
36
|
+
srcPattern: config.srcPattern,
|
|
37
|
+
outputDir: config.outputDir,
|
|
38
|
+
defaultLanguage: config.defaultLanguage,
|
|
39
|
+
translationsServiceClient,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
commander_1.program
|
|
43
|
+
.command("upload")
|
|
44
|
+
.description("Extract terms and upload to translation service")
|
|
45
|
+
.option("-s, --src-pattern <pattern>", "Source file pattern for extraction", "src/**/*.{ts,tsx}")
|
|
46
|
+
.option("-t, --poeditor-api-token <token>", "POEditor API token (can also use POEDITOR_API_TOKEN env var)")
|
|
47
|
+
.option("-p, --poeditor-project-id <id>", "POEditor project ID", value => parseInt(value, 10))
|
|
48
|
+
.option("-d, --default-language <lang>", "Default language for translations")
|
|
49
|
+
.action(async (options) => {
|
|
50
|
+
const parsedOptions = upload_1.uploadCommandOptionsSchema.extend(translationsServiceOptionsSchema.shape).parse(options);
|
|
51
|
+
const config = (0, mergeWithEnv_1.mergeWithEnv)(parsedOptions);
|
|
52
|
+
if (!config.poeditorApiToken || !config.poeditorProjectId) {
|
|
53
|
+
console.error("Translation service API token and project ID are required for upload command");
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
const translationsServiceClient = (0, mkTranslationsServiceClient_1.mkTranslationsServiceClient)({
|
|
57
|
+
poeditorApiToken: config.poeditorApiToken,
|
|
58
|
+
poeditorProjectId: config.poeditorProjectId,
|
|
59
|
+
});
|
|
60
|
+
await (0, upload_1.upload)({
|
|
61
|
+
srcPattern: config.srcPattern,
|
|
62
|
+
translationsServiceClient,
|
|
63
|
+
defaultLanguage: config.defaultLanguage,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
commander_1.program
|
|
67
|
+
.command("download")
|
|
68
|
+
.description("Download translations from translation service and compile them")
|
|
69
|
+
.option("-o, --output-dir <dir>", "Output directory for compiled translations", "lang")
|
|
70
|
+
.option("-l, --languages <langs...>", "Languages to download")
|
|
71
|
+
.option("-t, --poeditor-api-token <token>", "POEditor API token (can also use POEDITOR_API_TOKEN env var)")
|
|
72
|
+
.option("-p, --poeditor-project-id <id>", "POEditor project ID", value => parseInt(value, 10))
|
|
73
|
+
.action(async (options) => {
|
|
74
|
+
const parsedOptions = download_1.downloadCommandOptionsSchema.extend(translationsServiceOptionsSchema.shape).parse(options);
|
|
75
|
+
const config = (0, mergeWithEnv_1.mergeWithEnv)(parsedOptions);
|
|
76
|
+
const translationsServiceClient = (0, mkTranslationsServiceClient_1.mkTranslationsServiceClient)({
|
|
77
|
+
poeditorApiToken: config.poeditorApiToken,
|
|
78
|
+
poeditorProjectId: config.poeditorProjectId,
|
|
79
|
+
});
|
|
80
|
+
await (0, download_1.download)({
|
|
81
|
+
outputDir: config.outputDir,
|
|
82
|
+
languages: config.languages,
|
|
83
|
+
translationsServiceClient,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
commander_1.program
|
|
87
|
+
.command("sync")
|
|
88
|
+
.description("Upload local changes and download updated translations")
|
|
89
|
+
.option("-s, --src-pattern <pattern>", "Source file pattern for extraction", "src/**/*.{ts,tsx}")
|
|
90
|
+
.option("-o, --output-dir <dir>", "Output directory for compiled translations", "lang")
|
|
91
|
+
.option("-l, --languages <langs...>", "Languages to download")
|
|
92
|
+
.option("-t, --poeditor-api-token <token>", "POEditor API token (can also use POEDITOR_API_TOKEN env var)")
|
|
93
|
+
.option("-p, --poeditor-project-id <id>", "POEditor project ID", value => parseInt(value, 10))
|
|
94
|
+
.option("-d, --default-language <lang>", "Default language for translations")
|
|
95
|
+
.action(async (options) => {
|
|
96
|
+
const parsedOptions = sync_1.syncCommandOptionsSchema.extend(translationsServiceOptionsSchema.shape).parse(options);
|
|
97
|
+
const config = (0, mergeWithEnv_1.mergeWithEnv)(parsedOptions);
|
|
98
|
+
const translationsServiceClient = (0, mkTranslationsServiceClient_1.mkTranslationsServiceClient)({
|
|
99
|
+
poeditorApiToken: config.poeditorApiToken,
|
|
100
|
+
poeditorProjectId: config.poeditorProjectId,
|
|
101
|
+
});
|
|
102
|
+
await (0, sync_1.sync)({
|
|
103
|
+
srcPattern: config.srcPattern,
|
|
104
|
+
outputDir: config.outputDir,
|
|
105
|
+
languages: config.languages,
|
|
106
|
+
translationsServiceClient,
|
|
107
|
+
defaultLanguage: config.defaultLanguage,
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
commander_1.program
|
|
111
|
+
.command("diff")
|
|
112
|
+
.description("Compare local terms with translation service to find unused terms")
|
|
113
|
+
.option("-s, --src-pattern <pattern>", "Source file pattern for extraction", "src/**/*.{ts,tsx}")
|
|
114
|
+
.option("-t, --poeditor-api-token <token>", "POEditor API token (can also use POEDITOR_API_TOKEN env var)")
|
|
115
|
+
.option("-p, --poeditor-project-id <id>", "POEditor project ID", value => parseInt(value, 10))
|
|
116
|
+
.action(async (options) => {
|
|
117
|
+
const parsedOptions = diff_1.diffCommandOptionsSchema.extend(translationsServiceOptionsSchema.shape).parse(options);
|
|
118
|
+
const config = (0, mergeWithEnv_1.mergeWithEnv)(parsedOptions);
|
|
119
|
+
const translationsServiceClient = (0, mkTranslationsServiceClient_1.mkTranslationsServiceClient)({
|
|
120
|
+
poeditorApiToken: config.poeditorApiToken,
|
|
121
|
+
poeditorProjectId: config.poeditorProjectId,
|
|
122
|
+
});
|
|
123
|
+
await (0, diff_1.diff)({
|
|
124
|
+
srcPattern: config.srcPattern,
|
|
125
|
+
translationsServiceClient,
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
commander_1.program.parse();
|
|
129
|
+
//# sourceMappingURL=bin.js.map
|
package/src/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../../../../packages/intl/src/bin.ts"],"names":[],"mappings":";;;AAEA,yCAAmC;AACnC,+BAA0B;AAC1B,0CAAgE;AAChE,kDAA4E;AAC5E,4CAAmE;AACnE,0CAAgE;AAChE,8CAAsE;AACtE,iDAA6C;AAC7C,+EAA2E;AAE3E,MAAM,gCAAgC,GAAG,MAAC,CAAC,MAAM,CAAC;IAChD,gBAAgB,EAAE,MAAC,CAAC,MAAM,EAAE,CAAC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AAC,iBAAiB;KAC5C,CAAC,CAAA;IAEF,MAAM,IAAA,WAAI,EAAC;QACT,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,yBAAyB;KAC1B,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEJ,mBAAO,CAAC,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import type { TranslationsServiceClient } from "../TranslationsServiceClient";
|
|
3
|
+
export declare const diffCommandOptionsSchema: z.ZodObject<{
|
|
4
|
+
srcPattern: z.ZodString;
|
|
5
|
+
}, z.core.$strip>;
|
|
6
|
+
export type DiffCommandOptions = z.infer<typeof diffCommandOptionsSchema> & {
|
|
7
|
+
translationsServiceClient: TranslationsServiceClient;
|
|
8
|
+
};
|
|
9
|
+
export declare function diff({ srcPattern, translationsServiceClient }: DiffCommandOptions): Promise<void>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.diffCommandOptionsSchema = void 0;
|
|
4
|
+
exports.diff = diff;
|
|
5
|
+
const v4_1 = require("zod/v4");
|
|
6
|
+
const formatjs_1 = require("../formatjs");
|
|
7
|
+
exports.diffCommandOptionsSchema = v4_1.z.object({
|
|
8
|
+
srcPattern: v4_1.z.string(),
|
|
9
|
+
});
|
|
10
|
+
async function diff({ srcPattern, translationsServiceClient }) {
|
|
11
|
+
try {
|
|
12
|
+
console.log("Analyzing differences between local and remote translations...");
|
|
13
|
+
console.log("Extracting local messages...");
|
|
14
|
+
const localMessages = (0, formatjs_1.extractMessages)(srcPattern);
|
|
15
|
+
const localTerms = new Set(Object.keys(localMessages));
|
|
16
|
+
console.log("Fetching remote terms...");
|
|
17
|
+
const remoteTerms = await translationsServiceClient.downloadTerms();
|
|
18
|
+
const remoteTermSet = new Set(remoteTerms.map(term => term.term));
|
|
19
|
+
const unusedInLocal = [...remoteTermSet].filter(term => !localTerms.has(term));
|
|
20
|
+
if (unusedInLocal.length > 0) {
|
|
21
|
+
console.log(`\nTerms in remote but not used locally (${unusedInLocal.length}):`);
|
|
22
|
+
unusedInLocal.forEach(term => {
|
|
23
|
+
console.log(` - ${term}`);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
console.log("\nNo unused terms found in remote");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error("Error in diff command:", error);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../../../../packages/intl/src/commands/diff.ts"],"names":[],"mappings":";;;AAYA,oBAyBC;AArCD,+BAA0B;AAC1B,0CAA6C;AAGhC,QAAA,wBAAwB,GAAG,MAAC,CAAC,MAAM,CAAC;IAC/C,UAAU,EAAE,MAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAA;AAMK,KAAK,UAAU,IAAI,CAAC,EAAE,UAAU,EAAE,yBAAyB,EAAsB;IACtF,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,gEAAgE,CAAC,CAAA;QAE7E,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAA;QAC3C,MAAM,aAAa,GAAG,IAAA,0BAAe,EAAC,UAAU,CAAC,CAAA;QACjD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAA;QAEtD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA;QACvC,MAAM,WAAW,GAAG,MAAM,yBAAyB,CAAC,aAAa,EAAE,CAAA;QACnE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QAEjE,MAAM,aAAa,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;QAC9E,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,2CAA2C,aAAa,CAAC,MAAM,IAAI,CAAC,CAAA;YAChF,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBAC3B,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAA;YAC5B,CAAC,CAAC,CAAA;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAA;QAClD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAA;QAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import type { TranslationsServiceClient } from "../TranslationsServiceClient";
|
|
3
|
+
export declare const downloadCommandOptionsSchema: z.ZodObject<{
|
|
4
|
+
outputDir: z.ZodString;
|
|
5
|
+
languages: z.ZodArray<z.ZodString>;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
export type DownloadCommandOptions = z.infer<typeof downloadCommandOptionsSchema> & {
|
|
8
|
+
translationsServiceClient: TranslationsServiceClient;
|
|
9
|
+
};
|
|
10
|
+
export declare function download({ outputDir, languages, translationsServiceClient }: DownloadCommandOptions): Promise<void>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.downloadCommandOptionsSchema = void 0;
|
|
4
|
+
exports.download = download;
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const v4_1 = require("zod/v4");
|
|
7
|
+
const formatjs_1 = require("../formatjs");
|
|
8
|
+
exports.downloadCommandOptionsSchema = v4_1.z.object({
|
|
9
|
+
outputDir: v4_1.z.string(),
|
|
10
|
+
languages: v4_1.z.array(v4_1.z.string()),
|
|
11
|
+
});
|
|
12
|
+
async function download({ outputDir, languages, translationsServiceClient }) {
|
|
13
|
+
try {
|
|
14
|
+
console.log("Starting download from translation service...");
|
|
15
|
+
console.log(`Downloading translations for languages: ${languages.join(", ")}`);
|
|
16
|
+
const tempDir = (0, formatjs_1.createTranslationsTempDir)("download-");
|
|
17
|
+
try {
|
|
18
|
+
for (const language of languages) {
|
|
19
|
+
console.log(`Downloading ${language} translations...`);
|
|
20
|
+
const translations = await translationsServiceClient.downloadTranslations(language);
|
|
21
|
+
(0, formatjs_1.writeTranslationsToTempDir)({ translations, language, tempDir });
|
|
22
|
+
const translationCount = Object.keys(translations).length;
|
|
23
|
+
console.log(`Downloaded ${translationCount} translations for ${language}`);
|
|
24
|
+
}
|
|
25
|
+
console.log("Compiling translations...");
|
|
26
|
+
(0, fs_1.mkdirSync)(outputDir, { recursive: true });
|
|
27
|
+
(0, formatjs_1.compileTranslations)({ inputDir: tempDir, outputDir });
|
|
28
|
+
console.log(`Compiled translations saved to ${outputDir}`);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
(0, fs_1.rmSync)(tempDir, { recursive: true, force: true });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error("Error in download command:", error);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","sourceRoot":"","sources":["../../../../../packages/intl/src/commands/download.ts"],"names":[],"mappings":";;;AAcA,4BAiC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AC,GAAG,CAAC,kCAAkC,SAAS,EAAE,CAAC,CAAA;QAC5D,CAAC;gBAAS,CAAC;YACT,IAAA,WAAM,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QACnD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAA;QAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import type { TranslationsServiceClient } from "../TranslationsServiceClient";
|
|
3
|
+
export declare const localCommandOptionsSchema: z.ZodObject<{
|
|
4
|
+
srcPattern: z.ZodString;
|
|
5
|
+
outputDir: z.ZodString;
|
|
6
|
+
defaultLanguage: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
export type LocalCommandOptions = z.infer<typeof localCommandOptionsSchema> & {
|
|
9
|
+
translationsServiceClient?: TranslationsServiceClient;
|
|
10
|
+
};
|
|
11
|
+
export declare function local({ defaultLanguage, outputDir, srcPattern, translationsServiceClient, }: LocalCommandOptions): Promise<void>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.localCommandOptionsSchema = void 0;
|
|
4
|
+
exports.local = local;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const v4_1 = require("zod/v4");
|
|
10
|
+
const formatjs_1 = require("../formatjs");
|
|
11
|
+
exports.localCommandOptionsSchema = v4_1.z.object({
|
|
12
|
+
srcPattern: v4_1.z.string(),
|
|
13
|
+
outputDir: v4_1.z.string(),
|
|
14
|
+
defaultLanguage: v4_1.z.string(),
|
|
15
|
+
});
|
|
16
|
+
async function local({ defaultLanguage, outputDir, srcPattern, translationsServiceClient, }) {
|
|
17
|
+
try {
|
|
18
|
+
const extractedTranslations = extractAndCompile({ srcPattern, defaultLanguage });
|
|
19
|
+
const downloadedTranslations = translationsServiceClient
|
|
20
|
+
? await downloadAndCompile({ defaultLanguage, client: translationsServiceClient })
|
|
21
|
+
: undefined;
|
|
22
|
+
const translations = mergeTranslations({ extractedTranslations, downloadedTranslations });
|
|
23
|
+
save({ translations, outputDir, defaultLanguage });
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error("Error in local command:", error);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function extractAndCompile({ srcPattern, defaultLanguage, }) {
|
|
31
|
+
console.log("Extracting messages from source files...");
|
|
32
|
+
const messages = (0, formatjs_1.extractMessages)(srcPattern);
|
|
33
|
+
const messageCount = Object.keys(messages).length;
|
|
34
|
+
console.log(`Extracted ${messageCount} messages`);
|
|
35
|
+
if (messageCount === 0) {
|
|
36
|
+
console.log("No messages found. Make sure your source files contain formatjs messages.");
|
|
37
|
+
throw new Error("No messages found");
|
|
38
|
+
}
|
|
39
|
+
const tempDir = (0, formatjs_1.createTranslationsTempDir)("local-");
|
|
40
|
+
try {
|
|
41
|
+
const extractedTranslations = {};
|
|
42
|
+
for (const [id, details] of Object.entries(messages)) {
|
|
43
|
+
extractedTranslations[id] = details.defaultMessage;
|
|
44
|
+
}
|
|
45
|
+
(0, formatjs_1.writeTranslationsToTempDir)({ translations: extractedTranslations, language: defaultLanguage, tempDir });
|
|
46
|
+
console.log("Compiling extracted translations...");
|
|
47
|
+
const tempOutputDir = (0, formatjs_1.createTranslationsTempDir)("compiled-");
|
|
48
|
+
try {
|
|
49
|
+
(0, formatjs_1.compileTranslations)({ inputDir: tempDir, outputDir: tempOutputDir });
|
|
50
|
+
const compiledFilePath = (0, path_1.join)(tempOutputDir, `${defaultLanguage}.json`);
|
|
51
|
+
const compiledContent = (0, fs_1.readFileSync)(compiledFilePath, "utf-8");
|
|
52
|
+
return JSON.parse(compiledContent);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
(0, fs_1.rmSync)(tempOutputDir, { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
(0, fs_1.rmSync)(tempDir, { recursive: true, force: true });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function downloadAndCompile({ defaultLanguage, client, }) {
|
|
63
|
+
try {
|
|
64
|
+
console.log(`Downloading ${defaultLanguage} translations...`);
|
|
65
|
+
const downloadedTranslations = await client.downloadTranslations(defaultLanguage);
|
|
66
|
+
const downloadedCount = Object.keys(downloadedTranslations).length;
|
|
67
|
+
console.log(`Downloaded ${downloadedCount} translations`);
|
|
68
|
+
if (downloadedCount === 0) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const downloadTempDir = (0, formatjs_1.createTranslationsTempDir)("download-");
|
|
72
|
+
try {
|
|
73
|
+
(0, formatjs_1.writeTranslationsToTempDir)({
|
|
74
|
+
translations: downloadedTranslations,
|
|
75
|
+
language: defaultLanguage,
|
|
76
|
+
tempDir: downloadTempDir,
|
|
77
|
+
});
|
|
78
|
+
console.log("Compiling downloaded translations...");
|
|
79
|
+
const downloadTempOutputDir = (0, formatjs_1.createTranslationsTempDir)("download-compiled-");
|
|
80
|
+
try {
|
|
81
|
+
(0, formatjs_1.compileTranslations)({ inputDir: downloadTempDir, outputDir: downloadTempOutputDir });
|
|
82
|
+
const downloadedCompiledFilePath = (0, path_1.join)(downloadTempOutputDir, `${defaultLanguage}.json`);
|
|
83
|
+
const downloadedCompiledContent = (0, fs_1.readFileSync)(downloadedCompiledFilePath, "utf-8");
|
|
84
|
+
return JSON.parse(downloadedCompiledContent);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
(0, fs_1.rmSync)(downloadTempOutputDir, { recursive: true, force: true });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
(0, fs_1.rmSync)(downloadTempDir, { recursive: true, force: true });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.warn(`Failed to download translations from translation service: ${error}`);
|
|
96
|
+
console.log("Using extracted translations only");
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function mergeTranslations({ extractedTranslations, downloadedTranslations, }) {
|
|
101
|
+
if (!downloadedTranslations) {
|
|
102
|
+
return extractedTranslations;
|
|
103
|
+
}
|
|
104
|
+
const finalTranslations = { ...extractedTranslations, ...downloadedTranslations };
|
|
105
|
+
const newTranslationsCount = Object.keys(extractedTranslations).filter(key => !(key in downloadedTranslations)).length;
|
|
106
|
+
const downloadedTranslationsCount = Object.keys(downloadedTranslations).length;
|
|
107
|
+
console.log(`Merged ${newTranslationsCount} extracted terms with ${downloadedTranslationsCount} downloaded translations`);
|
|
108
|
+
return finalTranslations;
|
|
109
|
+
}
|
|
110
|
+
function save({ translations, outputDir, defaultLanguage, }) {
|
|
111
|
+
(0, fs_1.mkdirSync)(outputDir, { recursive: true });
|
|
112
|
+
const sortedTranslations = (0, lodash_1.default)(translations).toPairs().sortBy(0).fromPairs().value();
|
|
113
|
+
const finalFilePath = (0, path_1.join)(outputDir, `${defaultLanguage}.json`);
|
|
114
|
+
(0, fs_1.writeFileSync)(finalFilePath, JSON.stringify(sortedTranslations, null, 2));
|
|
115
|
+
console.log(`Merged translations saved to ${outputDir}`);
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../../../../packages/intl/src/commands/local.ts"],"names":[],"mappings":";;;AAsBA,sBAoBC;;AA1CD,2BAAm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