# @colsen1991/ngx-translate-extract

> Extract strings from projects using ngx-translate

Latest version **8.0.8** (published 2023-09-01) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @colsen1991/ngx-translate-extract
pnpm add @colsen1991/ngx-translate-extract
yarn add @colsen1991/ngx-translate-extract
bun add @colsen1991/ngx-translate-extract
```

Provides the command `ngx-translate-extract`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 8.0.8 |
| Published | 2023-09-01 |
| First published | 2023-01-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 10 |
| Unpacked size | 99.2 KB |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Kim Biesbjerg |
| Maintainers | colsen91 |
| Keywords | angular, ionic, ngx-translate, extract, extractor, translate, translation, i18n, gettext |

## Links

- npm: https://www.npmjs.com/package/@colsen1991/ngx-translate-extract
- Repository: https://github.com/colsen1991/ngx-translate-extract
- Issues: https://github.com/colsen1991/ngx-translate-extract/issues
- npm.io page: https://npm.io/package/@colsen1991/ngx-translate-extract

## Dependencies (10)

- [flat](https://npm.io/package/flat.md) ^5.0.2
- [glob](https://npm.io/package/glob.md) ^7.2.0
- [path](https://npm.io/package/path.md) ^0.12.7
- [boxen](https://npm.io/package/boxen.md) ^6.2.1
- [yargs](https://npm.io/package/yargs.md) ^17.5.1
- [colorette](https://npm.io/package/colorette.md) ^2.0.16
- [terminal-link](https://npm.io/package/terminal-link.md) ^3.0.0
- [gettext-parser](https://npm.io/package/gettext-parser.md) ^4.2.0
- [@angular/compiler](https://npm.io/package/@angular/compiler.md) ^13.1.2
- [@phenomnomnominal/tsquery](https://npm.io/package/@phenomnomnominal/tsquery.md) ^6.1.3

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 8.0.8 (latest) — 2023-09-01
- 8.0.7 — 2023-02-06
- 8.0.6 — 2023-01-20
- 8.0.5 — 2023-01-19
- 8.0.4 — 2023-01-19

## README

# ngx-translate-extract

> Angular translations extractor (plugin for [@ngx-translate](https://github.com/ngx-translate/core))

> ✓ _Angular 14, Ivy and Angular Universal (SSR) compatible_

Extract translatable (ngx-translate) strings and save as a JSON or Gettext pot file.
Merges with existing strings if the output file already exists.

## History

This project was originally created by [Kim Biesbjerg](https://github.com/biesbjerg/ngx-translate-extract).
Unfortunately he was unable to continue to maintain it so the Vendure team agreed to take over maintenance of a fork.
This is a fork of the latter for experimentation and to cater to some personal modifications.

## Install

Install the package in your project:

```bash
npm install @colsen1991/ngx-translate-extract --save-dev
```

Choose the version corresponding to your Angular version:

| Angular    | ngx-translate-extract                                                                      |
|------------|--------------------------------------------------------------------------------------------|
| 14         | 8.0.5+                                                                                     |
| 13         | 8.0.5+                                                                                     |
| 8.x – 12.x | [@biesbjerg/ngx-translate-extract](https://github.com/biesbjerg/ngx-translate-extract) 7.x |

Add a script to your project's `package.json`:

```json
...
"scripts": {
  "i18n:init": "ngx-translate-extract --input ./src --output ./src/assets/i18n/template.json --key-as-default-value --replace --format json",
  "i18n:extract": "ngx-translate-extract --input ./src --output ./src/assets/i18n/{en,da,de,fi,nb,nl,sv}.json --clean --format json"
}
...
```

You can now run `npm run i18n:extract` and it will extract strings from your project.

## Usage

**Extract from dir and save to file**

```bash
ngx-translate-extract --input ./src --output ./src/assets/i18n/strings.json
```

**Extract from multiple dirs**

```bash
ngx-translate-extract --input ./src-a ./src-b --output ./src/assets/i18n/strings.json
```

**Extract and save to multiple files using path expansion**

```bash
ngx-translate-extract --input ./src --output ./src/i18n/{da,en}.json
```

### JSON indentation

Tabs are used by default for indentation when saving extracted strings in json formats:

If you want to use spaces instead, you can do the following:

```bash
ngx-translate-extract --input ./src --output ./src/i18n/en.json --format-indentation ' '
```

### Marker function

If you want to extract strings that are not passed directly to `NgxTranslate.TranslateService`'s
`get()`/`instant()`/`stream()` methods, or its `translate` pipe or directive, you can wrap them
in a marker function/pipe/directive to let `ngx-translate-extract` know you want to extract them.

```bash
npm install @colsen1991/ngx-translate-extract-marker
```

See [@colsen1991/ngx-translate-extract-marker](https://github.com/colsen1991/ngx-translate-extract-marker/blob/master/README.md) documentation for more information.

### Commandline arguments

```
Usage:
ngx-translate-extract [options]

Output
  --format, -f                Format        [string] [choices: "json", "namespaced-json", "pot"] [default: "json"]
  --format-indentation, --fi  Format indentation (JSON/Namedspaced JSON)                  [string] [default: "\t"]
  --sort, -s                  Sort strings in alphabetical order                                         [boolean]
  --clean, -c                 Remove obsolete strings after merge                                        [boolean]
  --replace, -r               Replace the contents of output file if it exists (Merges by default)       [boolean]

Extracted key value (defaults to empty string)
  --key-as-default-value, -k     Use key as default value                                                [boolean]
  --null-as-default-value, -n    Use null as default value                                               [boolean]
  --string-as-default-value, -d  Use string as default value                                              [string]

Options:
  --version, -v  Show version number                                                                     [boolean]
  --help, -h     Show help                                                                               [boolean]
  --input, -i    Paths you would like to extract strings from. You can use path expansion, glob patterns and
                 multiple paths                                               [array] [required] [default: ["./"]]
  --output, -o   Paths where you would like to save extracted strings. You can use path expansion, glob
                 patterns and multiple paths                                                    [array] [required]
  --marker, -m   Custom marker function name                                                              [string]

Examples:
  ngx-translate-extract -i ./src-a/ -i ./src-b/ -o strings.json             Extract (ts, html) from multiple paths
  ngx-translate-extract -i './{src-a,src-b}/' -o strings.json               Extract (ts, html) from multiple paths using brace expansion
  ngx-translate-extract -i ./src/ -o ./i18n/da.json -o ./i18n/en.json       Extract (ts, html) and save to da.json and en.json
  ngx-translate-extract -i ./src/ -o './i18n/{en,da}.json'                  Extract (ts, html) and save to da.json and en.json using brace expansion
  ngx-translate-extract -i './src/**/*.{ts,tsx,html}' -o strings.json       Extract from ts, tsx and html
  ngx-translate-extract -i './src/**/!(*.spec).{ts,html}' -o strings.json   Extract from ts, html, excluding files with ".spec"
```

## Note for GetText users

Please pay attention of which version of `gettext-parser` you actually use in your project. 
For instance, `gettext-parser:1.2.2` does not support HTML tags in translation keys.

## Credits

- Original library, idea and code: [Kim Biesbjerg](https://github.com/biesbjerg/ngx-translate-extract) ❤️
- Further updates and improvements were then made by [bartholomej](https://github.com/bartholomej) ❤️
- Further updates and improvements were then made by [michaelbromley](https://github.com/michaelbromley)/[vendure-ecommerce](https://github.com/vendure-ecommerce) ❤️
- Further updates and improvements were made by [P4's](https://github.com/P4) ❤️

---
_Source: https://npm.io/package/@colsen1991/ngx-translate-extract · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
