https://github.com/m90/linguas-file
A library to handle LINGUAS files
https://github.com/m90/linguas-file
Last synced: about 2 months ago
JSON representation
A library to handle LINGUAS files
- Host: GitHub
- URL: https://github.com/m90/linguas-file
- Owner: m90
- License: mpl-2.0
- Created: 2021-04-05T08:34:32.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-27T12:14:55.000Z (over 3 years ago)
- Last Synced: 2025-04-02T22:40:29.094Z (about 2 months ago)
- Language: JavaScript
- Size: 89.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# linguas-file
A library to handle LINGUAS filesThis library helps you handle LINGUAS files (used in gettext based i18n workflows) as specified in https://www.gnu.org/software/gettext/manual/html_node/po_002fLINGUAS.html
## Installation
Install from npm:
```
npm i linguas-file
```## API
The module exposes two functions:
### `parse(input)`
This method takes a string or a buffer representing the content of a LINGUAS file and returns an Array of strings, containing the language tokens.
#### Example
```js
const fs = require('fs')
const linguasFile = require('linguas-file')/* content of ./LINGUAS:
# languages we support
fr pt
es de*/
fs.readFile('./LINGUAS', 'utf-8', function (err, data) {
const tokens = linguasFile.parse(data) // => ['fr', 'pt', 'es', 'de']
})
```### `serialize(tokens, [comment])`
This method takes an Array of tokens and an optional comment and returns a valid LINGUAS file.
#### Example
```js
const fs = require('fs')
const linguasFile = require('linguas-file')const languages = ['pt', 'fr', 'es', 'de']
const file = linguasFile.serialize(
languages, 'we are planning to support more of these'
)fs.writeFileSync('./LINGUAS', file)
/* Content of ./LINGUAS after write:
# we are planning to support more of these
pt fr es de*/
```## License
Copyright 2021 Frederik Ring - Available under the Mozilla Public License 2.0