2017-01-28 15:32:16 +01:00
|
|
|
If you like this project please show your support with a GitHub star. Much appreciated!
|
|
|
|
|
2017-03-07 15:56:26 +01:00
|
|
|
# ngx-translate-extract
|
|
|
|
Extract translatable (ngx-translate) strings and save as a JSON or Gettext pot file.
|
2016-12-20 16:02:56 +01:00
|
|
|
Merges with existing strings if the output file already exists.
|
2016-12-03 15:09:39 +01:00
|
|
|
|
2016-12-04 23:14:00 +01:00
|
|
|
## Usage
|
2016-12-20 16:02:56 +01:00
|
|
|
Install the package in your project:
|
2016-12-03 15:09:39 +01:00
|
|
|
|
2017-03-07 15:56:26 +01:00
|
|
|
`npm install @biesbjerg/ngx-translate-extract --save-dev`
|
2016-12-04 23:14:00 +01:00
|
|
|
|
2016-12-20 16:02:56 +01:00
|
|
|
Add an `extract` script to your project's `package.json`:
|
2016-12-04 23:14:00 +01:00
|
|
|
```
|
|
|
|
"scripts": {
|
2017-03-21 15:59:18 +01:00
|
|
|
"extract": "ngx-translate-extract --input ./src --output ./src/assets/i18n/*.json --clean --sort --format namespaced-json"
|
2016-12-04 23:14:00 +01:00
|
|
|
}
|
|
|
|
```
|
2017-03-21 15:59:18 +01:00
|
|
|
You can now run `npm run extract` to extract strings.
|
|
|
|
|
2017-03-29 14:20:01 +02:00
|
|
|
## Extract examples
|
2017-03-21 15:59:18 +01:00
|
|
|
|
|
|
|
**Extract from dir and save to file**
|
|
|
|
|
|
|
|
`ngx-translate-extract -i ./src -o ./src/i18n/strings.json`
|
|
|
|
|
|
|
|
**Extract from multiple dirs**
|
|
|
|
|
|
|
|
`ngx-translate-extract -i ./src/folder-a ./src/folder-b -o ./src/i18n/strings.json`
|
|
|
|
|
|
|
|
**Extract and save to multiple files**
|
|
|
|
|
|
|
|
`ngx-translate-extract -i ./src -o ./src/i18n/{da,en,fr}.json`
|
|
|
|
|
|
|
|
**or**
|
|
|
|
|
|
|
|
`ngx-translate-extract -i ./src -o ./src/i18n/da.json ./src/i18n/en.json ./src/i18n/fr.json`
|
|
|
|
|
|
|
|
**or (update only)**
|
|
|
|
|
|
|
|
`ngx-translate-extract -i ./src -o ./src/i18n/*.json`
|
|
|
|
|
2017-03-29 14:20:01 +02:00
|
|
|
**or (update only)**
|
|
|
|
|
|
|
|
## Custom indentation
|
|
|
|
By default, tabs are used for indentation when writing extracted strings to json formats:
|
|
|
|
|
|
|
|
`ngx-translate-extract -i ./src -o ./src/i18n/en.json --format-indentation $'\t'`
|
|
|
|
|
|
|
|
If you want to use spaces instead, you can do the following:
|
|
|
|
|
|
|
|
`ngx-translate-extract -i ./src -o ./src/i18n/en.json --format-indentation ' '`
|
|
|
|
|
2017-03-30 14:37:30 +02:00
|
|
|
## Mark strings for extraction using a marker function
|
|
|
|
If, for some reason, you want to extract strings not passed directly to TranslateService, you can wrap them in a custom marker function.
|
|
|
|
|
|
|
|
```ts
|
|
|
|
import { _ } from '@biesbjerg/ngx-translate-extract';
|
|
|
|
|
|
|
|
_('Extract me');
|
|
|
|
```
|
|
|
|
|
|
|
|
Add the `marker` argument when running the extract script:
|
|
|
|
|
|
|
|
`ngx-translate-extract ... -m _`
|
2016-12-04 23:14:00 +01:00
|
|
|
|
2016-12-04 23:22:00 +01:00
|
|
|
Modify the scripts arguments as required.
|
2016-12-04 23:14:00 +01:00
|
|
|
|
|
|
|
## Commandline arguments
|
|
|
|
```
|
|
|
|
Usage:
|
2017-03-21 15:59:18 +01:00
|
|
|
ngx-translate-extract [options]
|
2016-12-04 23:14:00 +01:00
|
|
|
|
|
|
|
Options:
|
2017-03-29 14:20:01 +02:00
|
|
|
--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] [default: current working path]
|
|
|
|
--patterns, -p Extract strings from the following file patterns
|
2017-03-21 15:59:18 +01:00
|
|
|
[array] [default: ["/**/*.html","/**/*.ts"]]
|
2017-03-29 14:20:01 +02:00
|
|
|
--output, -o Paths where you would like to save extracted
|
|
|
|
strings. You can use path expansion, glob patterns
|
|
|
|
and multiple paths [array] [required]
|
2017-03-30 14:42:03 +02:00
|
|
|
--marker, -m Extract strings passed to a marker function
|
|
|
|
[string] [default: false]
|
2017-03-29 14:20:01 +02:00
|
|
|
--format, -f Output format
|
2017-03-21 15:59:18 +01:00
|
|
|
[string] [choices: "json", "namespaced-json", "pot"] [default: "json"]
|
2017-03-29 14:20:01 +02:00
|
|
|
--format-indentation, --fi Output format indentation [string] [default: "\t"]
|
|
|
|
--replace, -r Replace the contents of output file if it exists
|
|
|
|
(Merges by default) [boolean] [default: false]
|
|
|
|
--sort, -s Sort strings in alphabetical order when saving
|
|
|
|
[boolean] [default: false]
|
|
|
|
--clean, -c Remove obsolete strings when merging
|
2017-03-21 15:59:18 +01:00
|
|
|
[boolean] [default: false]
|
2017-11-07 09:14:31 -05:00
|
|
|
--verbose, -vb If true, prints all processed file paths to console
|
|
|
|
[boolean] [default: true]
|