GithubHelp home page GithubHelp logo

hhy5277 / ngx-translate-extract Goto Github PK

View Code? Open in Web Editor NEW

This project forked from biesbjerg/ngx-translate-extract

0.0 2.0 0.0 334 KB

Extract translatable (using ngx-translate) strings and save as a JSON or Gettext pot file

License: MIT License

TypeScript 99.92% JavaScript 0.08%

ngx-translate-extract's Introduction

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": {
  "extract-i18n": "ngx-translate-extract --input ./src --output ./src/assets/i18n/ --clean --sort --format namespaced-json"
}
...

You can now run npm run extract-i18n 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/template.json

Extract from multiple dirs

ngx-translate-extract --input ./src-a ./src-b --output ./src/assets/i18n/template.json

Extract and save to multiple files using path expansion

Note: This method does not work on Windows!

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

On Windows you must specify each output destination individually:

ngx-translate-extract --input ./src --output ./src/i18n/da.json ./src/i18n/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]

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] [default: current working path]
     [array] [required] [default: current working path]
  --patterns, -p               Extract strings from the following file patterns
                                    [array] [default: ["/**/*.html","/**/*.ts"]]
  --output, -o                 Paths where you would like to save extracted
                               strings. You can use path expansion, glob
                               patterns and multiple paths    [array] [required]
  --format, -f                 Output format
          [string] [choices: "json", "namespaced-json", "pot"] [default: "json"]
  --format-indentation, --fi   Output format indentation  [string] [default: "	"]
  --replace, -r                Replace the contents of output file if it exists
                               (Merges by default)                     [boolean]
  --sort, -s                   Sort strings in alphabetical order when saving
                                                                       [boolean]
  --clean, -c                  Remove obsolete strings when merging    [boolean]
  --key-as-default-value, -k   Use key as default value for translations
                                                                       [boolean]
  --null-as-default-value, -n  Use null as default value for translations
                                                                       [boolean]

ngx-translate-extract's People

Contributors

biesbjerg avatar dominikhb avatar gustav-dahl avatar haakondr avatar ocombe avatar seangwright avatar sliekens avatar tiagodws avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.