Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@vendure/ngx-translate-extract
Advanced tools
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:
npm install @vendure/ngx-translate-extract --save-dev
# or
yarn 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
:
"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.
Extract from dir and save to file
ngx-translate-extract --input ./src --output ./src/assets/i18n/strings.json
Extract from multiple dirs
ngx-translate-extract --input ./src-a ./src-b --output ./src/assets/i18n/strings.json
Extract and save to multiple files using path expansion
ngx-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
ngx-translate-extract --input ./src --output ./src/i18n/{da,en}.json --strip-prefix 'PREFIX.'
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:
ngx-translate-extract --input ./src --output ./src/i18n/en.json --format-indentation ' '
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.
npm install @colsen1991/ngx-translate-extract-marker
See @colsen1991/ngx-translate-extract-marker documentation for more information.
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]
--strip-prefix, -sp Strip prefix from key [string]
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"
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.
FAQs
Extract strings from projects using ngx-translate
The npm package @vendure/ngx-translate-extract receives a total of 14,751 weekly downloads. As such, @vendure/ngx-translate-extract popularity was classified as popular.
We found that @vendure/ngx-translate-extract demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.