Skip to content

Commit 6fad106

Browse files
authored
[localize] Split localize CLI into extract and build commands (lit#1668)
Previously the lit-localize CLI always does both extraction and project building. It's nice to separate these steps, in particular because of the next PR, which directly exposes locale transformers for use with @rollup/plugin-typescript (or other tools). With this change, running lit-localize extract will generate XLIFF files (translation requests), and then building is done either with lit-localize build or from within a Rollup configuration.
1 parent 63d007e commit 6fad106

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1447
-210
lines changed

packages/localize/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
msg(str`Hello ${name}`);
3333
```
3434

35+
- **[BREAKING]** The `lit-localize` CLI now must always take one of two
36+
commands: `extract` or `build`. Previously, both of these steps were always
37+
performed.
38+
3539
## [0.6.1] - 2020-12-09
3640

3741
### Fixed

packages/localize/README.md

+13-23
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ lit-localize supports two output modes: _transform_ and _runtime_.
153153
}
154154
```
155155

156-
5. Run the `lit-localize` CLI:
156+
5. Run the `lit-localize` CLI with the `extract` command:
157157

158158
```bash
159-
npx lit-localize
159+
npx lit-localize extract
160160
```
161161

162162
6. Take a look at the generated XLIFF file `xliff/es-419.xlf`. Note that we have
@@ -181,10 +181,10 @@ lit-localize supports two output modes: _transform_ and _runtime_.
181181
</trans-unit>
182182
```
183183

184-
8. Run `lit-localize` again:
184+
8. Run the `lit-localize` CLI with the `build` command:
185185

186186
```bash
187-
npx lit-localize
187+
npx lit-localize build
188188
```
189189

190190
9. Now take a look at the generated file `es-419/index.js`:
@@ -511,30 +511,20 @@ In transform mode, applications of the `Localized` mixin are removed.
511511

512512
## CLI
513513

514-
Running the `lit-localize` command-line program does the following:
514+
### Usage
515515

516-
1. Reads your [config file](#config-file) according to the `--config` flag.
517-
518-
2. Analyzes all TypeScript files covered by your `tsconfig.json`, and discovers
519-
all calls to the `msg` function.
520-
521-
3. Creates or updates an XLIFF (`.xlf`) file for each of your target locales,
522-
with a `<source>` tag corresponding to each `msg` call.
523-
524-
4. Reads existing `<target>` tags from existing XLIFF files for each `msg` call.
525-
526-
5. When in _transform_ mode, compiles your TypeScript project for each locale,
527-
where all `msg` calls are replaced with the corresponding static, localized
528-
version from that locale's XLIFF file.
529-
530-
6. When in _runtime_ mode, generates a `<locale>.ts` file for each locale, which
531-
can be dynamically loaded by the `@lit/localize` module.
516+
```sh
517+
lit-localize command [--flags]
518+
```
532519

533-
It takes the following flags:
520+
| Command | Description |
521+
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
522+
| `extract` | Extract templates from `msg()` calls across all source files included by your `tsconfig.json`, and create or update XLIFF (`.xlf`) files containing translation requests. |
523+
| `build` | Read translations and build the project according to the configured mode.<br><br>In _transform_ mode, compile your TypeScript project for each locale, replacing `msg` calls with localized templates.<br><br>In _runtime_ mode, generate a `<locale>.ts` file for each locale, which can be dynamically loaded by the `@lit/localize` module. |
534524

535525
| Flag | Description |
536526
| ---------- | --------------------------------------------------------------------------- |
537-
| `--help` | Display this list of flags. |
527+
| `--help` | Display help about usage. |
538528
| `--config` | Path to JSON [config file](#config-file). Defaults to `./lit-localize.json` |
539529

540530
## Config file

packages/localize/examples/runtime/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ This package demonstrates an application that uses [lit-localize](https://github
1818
## Setup
1919

2020
```bash
21-
git clone https://github.com/PolymerLabs/lit-localize.git
22-
cd lit-localize/examples/runtime
21+
git clone https://github.com/Polymer/lit-next.git
22+
cd lit-next/packages/localize/examples/transform
2323
npm install
24-
npx lit-localize
24+
npx lit-localize build
2525
npx tsc
2626
npx es-dev-server --node-resolve
2727
```

packages/localize/examples/runtime/package-lock.json

+7-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/localize/examples/runtime/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "1.0.0",
55
"private": true,
66
"scripts": {
7-
"build": "rm -rf lib/* && lit-localize && tsc",
7+
"build": "rm -rf lib/* && lit-localize build && tsc",
88
"serve": "es-dev-server --node-resolve --preserve-symlinks"
99
},
1010
"dependencies": {

packages/localize/examples/transform/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ mode.
1313
## Setup
1414

1515
```bash
16-
git clone https://github.com/PolymerLabs/lit-localize.git
17-
cd lit-localize/examples/transform
16+
git clone https://github.com/Polymer/lit-next.git
17+
cd lit-next/packages/localize/examples/transform
1818
npm install
19-
npx lit-localize
19+
npx lit-localize build
2020
npx es-dev-server --node-resolve
2121
```
2222

packages/localize/examples/transform/package-lock.json

+7-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/localize/examples/transform/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "1.0.0",
55
"private": true,
66
"scripts": {
7-
"build": "rm -rf lib/* && lit-localize",
7+
"build": "rm -rf lib/* && lit-localize build",
88
"serve": "es-dev-server --node-resolve --preserve-symlinks"
99
},
1010
"dependencies": {

0 commit comments

Comments
 (0)