https://github.com/othree/po-writer
A simple gettext Po file writer.
https://github.com/othree/po-writer
gettext po
Last synced: over 1 year ago
JSON representation
A simple gettext Po file writer.
- Host: GitHub
- URL: https://github.com/othree/po-writer
- Owner: othree
- License: mit
- Created: 2018-01-16T08:59:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-03-31T03:09:28.000Z (about 6 years ago)
- Last Synced: 2025-02-24T21:18:12.162Z (over 1 year ago)
- Topics: gettext, po
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/po-writer
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# po-writer
A simple [gettext](https://www.gnu.org/software/gettext/) Po file writer.
## Usage
Create instance
```js
import Po from 'po-writer';
let po = new Po();
```
Add translations:
```js
po.add({
id: 'hello world',
str: '夜露死苦'
})
```
Create write stream and write to file:
```js
let stream = fs.createWriteStream(targetFilePath);
po.writeToStream(stream);
```
## API
### `constructor(headers)`
`headers` is an object contains file header. Current support header fields and default values:
* Project-Id-Version: 'PACKAGE VERSION',
* POT-Creation-Date: now,
* PO-Revision-Date: now,
* Last-Translator: '',
* Language-Team: 'none',
* MIME-Version: '1.0',
* Content-Type: 'text/plain; charset=UTF-8',
* Content-Transfer-Encoding: '8bit',
* Plural-Forms: 'nplurals=INTEGER; plural=EXPRESSION;'
### `add(msg|msg[])`
Add a translated [message](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html) to Po.
`msg` support attributes:
* translatorComments
* extractedComments
* reference
* flag
* context
* id
* plural
* str (string|string[])
### `remove(id|id[])`
Remove translation message from Po. `id` is a msg id or msg object.
### `writeToStream(stream)`
Write the content of Po file to writable stream.