https://github.com/lukasgeiter/gettext-extractor
A flexible and powerful Gettext message extractor with support for JavaScript, TypeScript, JSX and HTML.
https://github.com/lukasgeiter/gettext-extractor
extractor gettext i18n l10n po-files translation typescript
Last synced: 2 months ago
JSON representation
A flexible and powerful Gettext message extractor with support for JavaScript, TypeScript, JSX and HTML.
- Host: GitHub
- URL: https://github.com/lukasgeiter/gettext-extractor
- Owner: lukasgeiter
- License: mit
- Created: 2017-03-17T16:05:39.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-07-15T11:42:59.000Z (almost 2 years ago)
- Last Synced: 2024-10-29T11:19:05.878Z (8 months ago)
- Topics: extractor, gettext, i18n, l10n, po-files, translation, typescript
- Language: TypeScript
- Homepage:
- Size: 333 KB
- Stars: 98
- Watchers: 4
- Forks: 21
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Gettext Extractor [![Tests Status][status-tests-badge]][status-tests-link]
*A flexible and powerful Gettext message extractor with support for JavaScript, TypeScript, JSX and HTML*
It works by running your files through a parser and then uses the AST (Abstract Syntax Tree) to find and extract translatable strings from your source code. All extracted strings can then be saved as `.pot` file to act as template for translation files.
Unlike many of the alternatives, this library is highly configurable and is designed to work with most existing setups.
For the full documentation check out the [Github Wiki][wiki].
## Installation
> **Note:** This package requires Node.js version 6 or higher.
#### Yarn
```text
yarn add gettext-extractor
```#### NPM
```text
npm install gettext-extractor
```## Getting Started
Let's start with a code example:
```javascript
const { GettextExtractor, JsExtractors, HtmlExtractors } = require('gettext-extractor');let extractor = new GettextExtractor();
extractor
.createJsParser([
JsExtractors.callExpression('getText', {
arguments: {
text: 0,
context: 1
}
}),
JsExtractors.callExpression('getPlural', {
arguments: {
text: 1,
textPlural: 2,
context: 3
}
})
])
.parseFilesGlob('./src/**/*.@(ts|js|tsx|jsx)');extractor
.createHtmlParser([
HtmlExtractors.elementContent('translate, [translate]')
])
.parseFilesGlob('./src/**/*.html');extractor.savePotFile('./messages.pot');
extractor.printStats();
```A detailed explanation of this code example and much more can be found in the [Github Wiki][wiki-introduction].
## Contributing
From reporting a bug to submitting a pull request: every contribution is appreciated and welcome.
Report bugs, ask questions and request features using [Github issues][github-issues].
If you want to contribute to the code of this project, please read the [Contribution Guidelines][contributing].[status-tests-badge]: https://github.com/lukasgeiter/gettext-extractor/actions/workflows/tests.yml/badge.svg
[status-tests-link]: https://github.com/lukasgeiter/gettext-extractor/actions/workflows/tests.yml
[wiki]: https://github.com/lukasgeiter/gettext-extractor/wiki
[wiki-introduction]: https://github.com/lukasgeiter/gettext-extractor/wiki/Introduction
[github-issues]: https://github.com/lukasgeiter/gettext-extractor/issues
[contributing]: CONTRIBUTING.md