npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@slargemain/ngx-translate-extract

v1.0.7

Published

Extract strings from projects using ngx-translate

Downloads

4

Readme

If this tool saves you time, please consider making a donation towards the continued maintainence and development: https://donate.biesbjerg.com

Donate

ngx-translate-extract

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

Install

Install the package in your project:

npm install @biesbjerg/ngx-translate-extract --save-dev

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.

Usage

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

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:

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 TranslateService's get()/instant()/stream() methods, you can wrap them in a marker function to let ngx-translate-extract know you want to extract them.

Install marker function: npm install @biesbjerg/ngx-translate-extract-marker

import { marker } from '@biesbjerg/ngx-translate-extract-marker';

marker('Extract me');

You can alias the marker function if needed:

import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';

_('Extract me');

Note: ngx-translate-extract will automatically detect the import name

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: "	"]
  --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: ["/Users/kim/apps/ngx-translate-extract"]]
  --output, -o   Paths where you would like to save extracted strings. You can use path expansion, glob
                 patterns and multiple paths                                                [array] [required]

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              Extract from ts, html, excluding files with ".spec"
  strings.json

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.