https://github.com/trigensoftware/localer
Locales collector from js sources.
https://github.com/trigensoftware/localer
i18n i18n-node json locales-collector
Last synced: 2 months ago
JSON representation
Locales collector from js sources.
- Host: GitHub
- URL: https://github.com/trigensoftware/localer
- Owner: TrigenSoftware
- License: mit
- Created: 2016-06-30T10:53:37.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-11-02T02:04:54.000Z (over 5 years ago)
- Last Synced: 2024-12-22T04:57:15.507Z (5 months ago)
- Topics: i18n, i18n-node, json, locales-collector
- Language: JavaScript
- Size: 51.8 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://nodei.co/npm/localer/)
# Localer
Locales collector from js sources.
# Global usage
```
localer [...glob patterns to js source] [--strings to show code frames only for strings] [--html to generate html] [--summary to show list of added and unused locales] [--compare [...glob patterns to json] to show difference] [--exclude [...glob patterns to json] to exclude locales]
```# Examples
For example, you have this code:
```js
const translate = __`Translate me!`;
const withoutTranslation = __`Without translation`;
```and JSON file with translations:
```json
{
"Translate me!": "Переведи меня!",
"Unused translation": "Неиспользованный перевод"
}
```If you execute next command:
```bash
localer main.js --summary --compare ru.json
```you'll get:
```bashSummary:
Added:
Without translationUnused (maybe):
Unused translationFile: main.js
String: Without translation
1 | const translate = __`Translate me!`;
> 2 | const withoutTranslation = __`Without translation`;
| ^```
Also you can create `.localerrc.js` file and define default parameters. Defaults:
```js
module.exports = {
sources: [],
transformers: [],
exclude: [],
compare: [],
summary: false,
html: false,
strings: false
};
```# API
## `class Locales(Array|Locales fromLocalesOrLocales, Array fromUnused)`
### Properties:
#### `Array tags = ['__', '__n']`
Tagged literals.
#### `Array fns = ['__', '__n', '__mf', '__l', '__h']`
Functions with one argument.
#### `Array fns2 = ['__n']`
Functions with few argument.
#### `Convert convert`
ANSI to HTML instance.
#### `Object babylonOptions`
Babylon parser options.
#### `Array transformers = []`
Code transformers.
#### `Array locales = []`
Locales soruces.
#### `Array unused = []`
Unused locales.
### Methods:
#### `Locales from(Locales locales)`
Import data from other instance.
#### `Locales copy()`
Create copy of this.
#### `Locales fromCode(String code, String file)`
Collect locales from source code.
#### `Promise fromFiles(String maskOrMasks)`
Collect locales from JavaScript source files by glob pattern.
#### `Locales exclude(Array|Object arrayOrObjectToExlcude)`
Exclude given locales from `locales` and `unused`.
#### `Promise excludeFiles(String|Array maskOrMasks)`
Exclude locales getted from JSON files from `locales` and `unused`.
#### `Locales diff(Array|Object arrayOrObjectBase)`
Get difference between locales parsed from JavaScript sources and locales.
#### `Promise diffFiles(String|Array maskOrMasks)`
Get difference between locales parsed from JavaScript sources and locales from JSON files.
#### `String terminalReport(Boolean withSummary = false)`
Generate report for terminal.
#### `String htmlReport(Boolean withSummary = false)`
Generate report as html.
## `class LocaleSource(String|LocaleSource fileOrLocaleSource, String code, Node node, String fn, String string)`
### Properties:
#### `String file`
Path to file.
#### `String type`
Type of node.
#### `Number line`
Line of token.
#### `Number column`
Column of token.
#### `String fn`
Function name.
#### `String string`
Locale string.
#### `String codeFrame`
Code frame.
### Methods:
#### `Locales from(LocaleSource localeSource)`
Import data from other instance.
#### `LocaleSource copy()`
Create copy of this.