Gathering detailed insights and metrics for @vendure/ngx-translate-extract
Gathering detailed insights and metrics for @vendure/ngx-translate-extract
Gathering detailed insights and metrics for @vendure/ngx-translate-extract
Gathering detailed insights and metrics for @vendure/ngx-translate-extract
Extract translatable (using ngx-translate) strings and save as a JSON or Gettext pot file
npm install @vendure/ngx-translate-extract
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
51 Stars
365 Commits
19 Forks
5 Watching
1 Branches
2 Contributors
Updated on 21 Nov 2024
TypeScript (99.97%)
JavaScript (0.03%)
Cumulative downloads
Total Downloads
Last day
4.1%
3,932
Compared to previous day
Last week
10%
20,389
Compared to previous week
Last month
14.2%
78,107
Compared to previous month
Last year
411.8%
533,394
Compared to previous year
2
Angular translations extractor (plugin for @ngx-translate)
✓ 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.
This project was originally created by Kim Biesbjerg. Unfortunately he was unable to continue to maintain it so the Vendure team agreed to take over maintenance of this fork.
Install the package in your project:
1npm install @vendure/ngx-translate-extract --save-dev 2# or 3yarn add @vendure/ngx-translate-extract --dev
Choose the version corresponding to your Angular version:
Angular | ngx-translate-extract |
---|---|
>=17 | 9.x |
13 – 16 | 8.x |
8 – 12 | @biesbjerg/ngx-translate-extract 7.x |
Add a script to your project's package.json
:
1"scripts": { 2 "i18n:init": "ngx-translate-extract --input ./src --output ./src/assets/i18n/template.json --key-as-default-value --replace --format json", 3 "i18n:extract": "ngx-translate-extract --input ./src --output ./src/assets/i18n/{en,da,de,fi,nb,nl,sv}.json --clean --format json" 4}
You can now run npm run i18n:extract
and it will extract strings from your project.
Extract from dir and save to file
1ngx-translate-extract --input ./src --output ./src/assets/i18n/strings.json
Extract from multiple dirs
1ngx-translate-extract --input ./src-a ./src-b --output ./src/assets/i18n/strings.json
Extract and save to multiple files using path expansion
1ngx-translate-extract --input ./src --output ./src/i18n/{da,en}.json
Strip prefix from the generated json keys
Useful when loading multiple translation files in the same application and prefixing them automatically
1ngx-translate-extract --input ./src --output ./src/i18n/{da,en}.json --strip-prefix 'PREFIX.'
Cache for consecutive runs
If your project grows rather large, runs can take seconds. With this cache, unchanged files don't need to be parsed again, keeping consecutive runs under .5 seconds.
1ngx-translate-extract --cache-file node_modules/.i18n-cache/my-cache-file --input ./src --output ./src/i18n/{da,en}.json
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:
1ngx-translate-extract --input ./src --output ./src/i18n/en.json --format-indentation ' '
Extracted keys are by default not sorted. You can enable sorting by using the --sort
or -s
flag.
If sorting is enabled, the keys will be sorted using the default variant sort sensitivity. Other sort sensitivity options are also available using the --sort-sensitivity
or -ss
flag:
base
: Strings that differ in base letters are unequal. For example a !== b
, a === á
, a === A
accent
: Strings that differ in base letters and accents are unequal. For example a !== b
, a !== á
, a === A
case
: Strings that differ in base letters or casing are unequal. For example a !== b
, a === á
, a !== A
variant
: Strings that differ in base letters, accents, or casing are unequal. For example a !== b
, a !== á
, a !== A
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.
1npm install @colsen1991/ngx-translate-extract-marker
See @colsen1991/ngx-translate-extract-marker documentation for more information.
1Usage: 2ngx-translate-extract [options] 3 4Output 5 --format, -f Format [string] [choices: "json", "namespaced-json", "pot"] [default: "json"] 6 --format-indentation, --fi Format indentation (JSON/Namedspaced JSON) [string] [default: "\t"] 7 --sort, -s Sort strings in alphabetical order [boolean] 8 --sort-sensitivity, -ss Sensitivity when sorting strings (only when sort is enabled) [string] 9 --clean, -c Remove obsolete strings after merge [boolean] 10 --replace, -r Replace the contents of output file if it exists (Merges by default) [boolean] 11 --strip-prefix, -sp Strip prefix from key [string] 12 13Extracted key value (defaults to empty string) 14 --key-as-default-value, -k Use key as default value [boolean] 15 --key-as-initial-default-value, -ki Use key as initial default value [boolean] 16 --null-as-default-value, -n Use null as default value [boolean] 17 --string-as-default-value, -d Use string as default value [string] 18 19Options: 20 --version, -v Show version number [boolean] 21 --help, -h Show help [boolean] 22 --input, -i Paths you would like to extract strings from. You can use path expansion, glob patterns and 23 multiple paths [array] [required] [default: ["./"]] 24 --output, -o Paths where you would like to save extracted strings. You can use path expansion, glob 25 patterns and multiple paths [array] [required] 26 --cache-file Cache parse results to speed up consecutive runs [string] 27 --marker, -m Custom marker function name [string] 28 29Examples: 30 ngx-translate-extract -i ./src-a/ -i ./src-b/ -o strings.json Extract (ts, html) from multiple paths 31 ngx-translate-extract -i './{src-a,src-b}/' -o strings.json Extract (ts, html) from multiple paths using brace expansion 32 ngx-translate-extract -i ./src/ -o ./i18n/da.json -o ./i18n/en.json Extract (ts, html) and save to da.json and en.json 33 ngx-translate-extract -i ./src/ -o './i18n/{en,da}.json' Extract (ts, html) and save to da.json and en.json using brace expansion 34 ngx-translate-extract -i './src/**/*.{ts,tsx,html}' -o strings.json Extract from ts, tsx and html 35 ngx-translate-extract -i './src/**/!(*.spec).{ts,html}' -o strings.json Extract from ts, html, excluding files with ".spec" 36 ngx-translate-extract -i './src/' -o strings.json -sp 'PREFIX.' Strip the prefix "PREFIX." from the json keys
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.
No vulnerabilities found.
No security vulnerabilities found.