New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

i18n-plus

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18n-plus - npm Package Compare versions

Comparing version 3.0.1 to 3.1.1

scripts/cli.js

73

CHANGELOG.md

@@ -10,2 +10,10 @@ # Changelog

## [v3.1.1](https://github.com/artus9033/i18n-plus/compare/v3.0.1...v3.1.1) - 2021-08-21
### Commits
- Added statically-typed locale keys compilation standard based off YAML with modifications & added compiler script; added extensive unit tests [`9c2f1ce`](https://github.com/artus9033/i18n-plus/commit/9c2f1ce9c54af0ce3be876f7483fd87cc793028f)
- Updated README & incremented project version [`8575108`](https://github.com/artus9033/i18n-plus/commit/857510800ea93c5a14f33db5917d13da3f6e921f)
- Updated changelog to include all previous versions [`2e14ba3`](https://github.com/artus9033/i18n-plus/commit/2e14ba35b1dfa3c9b974e85b616c8381444c1c18)
## [v3.0.1](https://github.com/artus9033/i18n-plus/compare/v3.0.0...v3.0.1) - 2021-08-20

@@ -19,8 +27,67 @@

## v3.0.0 - 2021-08-20
## [v3.0.0](https://github.com/artus9033/i18n-plus/compare/v2.0.3...v3.0.0) - 2021-08-20
### Commits
- Re-written tests in typescript; migrated from mocha to jest & ts-jest; added GH workflow to test compilation & run unit tests; created separate tsconfigs for development & building [`79a5170`](https://github.com/artus9033/i18n-plus/commit/79a517081cb2145d9e0244d87c115f73518ee4b6)
- Added a proper test workflow [`26be40d`](https://github.com/artus9033/i18n-plus/commit/26be40dacbeeaa0408c546b7d1a5fbf81e72c3ac)
- Fixed tsc compilation failing with unresolved @types dependencies [`13e53b3`](https://github.com/artus9033/i18n-plus/commit/13e53b3579e379f3efaecad548994c38315db27d)
## [v2.0.3](https://github.com/artus9033/i18n-plus/compare/v2.0.2...v2.0.3) - 2020-09-26
### Commits
- Updated dependencies [`d460f81`](https://github.com/artus9033/i18n-plus/commit/d460f810913ab57e8ddd63b331190299894f6c82)
- Changed github action indent style [`79593bb`](https://github.com/artus9033/i18n-plus/commit/79593bb275abd641ba87adbc41e9c5f2239764fe)
- Fixed compilation bugs [`5d08036`](https://github.com/artus9033/i18n-plus/commit/5d08036eecb5a6d5dd880678878197bb7a9e4b4a)
## [v2.0.2](https://github.com/artus9033/i18n-plus/compare/v2.0.1...v2.0.2) - 2020-09-26
### Commits
- Generated docs; new version - 2.0.2 [`d2beebd`](https://github.com/artus9033/i18n-plus/commit/d2beebd5223bce8aaee0844abcb3e1955b781a77)
- Fixed include paths for tsconfig.json; added a Github action workflow for test build; fixed docs body height [`f9ef4f6`](https://github.com/artus9033/i18n-plus/commit/f9ef4f6a4596d1878f8a3e8d08d2858c215e2da2)
- Fixed docs index.html structure [`b6ffcb7`](https://github.com/artus9033/i18n-plus/commit/b6ffcb70a2e16a9d79d01136aca7fe533128d61d)
## [v2.0.1](https://github.com/artus9033/i18n-plus/compare/v2.0.0...v2.0.1) - 2020-03-28
### Commits
- Added keywords to package.json [`1c30812`](https://github.com/artus9033/i18n-plus/commit/1c308129c4368127ac2b7a6002f15ad236f8cf7a)
- Fixed docs version picker list [`e4243d9`](https://github.com/artus9033/i18n-plus/commit/e4243d95a56128a9be70c58861a888499f68f5b5)
## [v2.0.0](https://github.com/artus9033/i18n-plus/compare/v1.0.4...v2.0.0) - 2020-03-28
### Commits
- [2.0.0] Moved to TypeScript; added compilation scripts; breaking import [`309b8b0`](https://github.com/artus9033/i18n-plus/commit/309b8b06cecf711d0710c4354704f6047f820170)
- Removed optional chaining operator due to lack of support yet [`b4f1b38`](https://github.com/artus9033/i18n-plus/commit/b4f1b38ffc443df0ec7a6eec1e4299d0eed1dc8d)
## [v1.0.4](https://github.com/artus9033/i18n-plus/compare/v1.0.3...v1.0.4) - 2020-02-21
### Commits
- Incremented version [`ad37142`](https://github.com/artus9033/i18n-plus/commit/ad371422a8c93a862a4d44a6e9a021ee509ac951)
- Fix fatal if interpolation value does not implement toString [`2cf83e6`](https://github.com/artus9033/i18n-plus/commit/2cf83e6d71557b96516a21220e83cb82ddb60878)
## [v1.0.3](https://github.com/artus9033/i18n-plus/compare/v1.0.2...v1.0.3) - 2020-02-18
### Commits
- Moved to ESM instead of babel [`c2e6598`](https://github.com/artus9033/i18n-plus/commit/c2e65983acc3244d9b23efc1240854be2f6271c2)
- Incremented patch version [`140e65a`](https://github.com/artus9033/i18n-plus/commit/140e65aaa6ec0a8716965e44f2358d49bea6f387)
## [v1.0.2](https://github.com/artus9033/i18n-plus/compare/v1.0.0...v1.0.2) - 2020-02-18
### Commits
- Finished documentation [`1e4e127`](https://github.com/artus9033/i18n-plus/commit/1e4e12725d21675a317ca13e4c38e5278bc4d6e8)
- [2.0.0] Moved to TypeScript; added compilation scripts; breaking import [`309b8b0`](https://github.com/artus9033/i18n-plus/commit/309b8b06cecf711d0710c4354704f6047f820170)
- Generated docs; new version - 2.0.2 [`d2beebd`](https://github.com/artus9033/i18n-plus/commit/d2beebd5223bce8aaee0844abcb3e1955b781a77)
- Updated tests; fixed _cutString & _injectString in LocaleHelper [`eeeac3d`](https://github.com/artus9033/i18n-plus/commit/eeeac3d22fc83c5dd92ba69f69ffe1688a7c6544)
- Fixed index.js exports [`7cc0d1d`](https://github.com/artus9033/i18n-plus/commit/7cc0d1d8acff24c153849941293e2df1cb417745)
## v1.0.0 - 2020-02-17
### Commits
- Initial commit [`8cc1b6b`](https://github.com/artus9033/i18n-plus/commit/8cc1b6b355a7bac54d650be86e5073ab872141b3)
- Added a readme [`1fe8d98`](https://github.com/artus9033/i18n-plus/commit/1fe8d98272305eb7c727f65766b97e7d1456b824)

14

package.json
{
"name": "i18n-plus",
"version": "3.0.1",
"version": "3.1.1",
"description": "Node.js package providing i18n with variable interpolation & conjugation of words with respect to quantifiers, supporting all languages' conjugation rules.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
"i18n-plus": "./scripts/cli.js"
},
"scripts": {

@@ -21,5 +24,5 @@ "build": "tsc --project tsconfig.build.json",

"esm": "^3.2.25",
"jest": "^27.0.6",
"jsdoc": "^3.6.7",
"minami": "^1.2.3",
"jest": "^27.0.6",
"ts-jest": "^27.0.5",

@@ -30,3 +33,8 @@ "ts-node": "^10.2.1",

"peerDependencies": {
"lodash": "^4.17.21"
"chokidar": "^3.5.2",
"json5": "^2.2.0",
"lodash": "^4.17.21",
"signale": "^1.4.0",
"yaml": "^1.10.2",
"yargs": "^17.1.1"
},

@@ -33,0 +41,0 @@ "homepage": "https://artus9033.github.io/i18n-plus/",

@@ -16,3 +16,7 @@ # i18n-plus

- Strongly typed with TypeScript
- Transpilation of YAML-defined translation key dictionaries into statically-typed, importable TypeScript code
- Supports splitting key dictionaries into multiple files with `!include()` directives
---
## Documentation

@@ -22,8 +26,12 @@

## Simple usage in a brief
---
The key function is `trans(key, interpolationParams = {})`
## Usage
There are two specifiers available for you to use:
### Basic usage in a brief
The key function provided is `trans(key, interpolationParams = {})`
There are two specifiers available for use:
1. Interpolation syntax `:variableName` - simply replaces all such fields with the corresponding values supplied as Object properties in the second argument of `trans` call

@@ -37,3 +45,3 @@ 2. Conjugation syntax `:[quantityVarName, { zero: 'values', one: 'value', other: 'values' } ]` -

const localeKeys = {
home: { welcome: "home.welcome" }
home: { welcome: "home.welcome" },
};

@@ -45,4 +53,4 @@

[localeKeys.home.welcome]:
"Welcome, :user! You have :[messages, { zero: 'messages', one: 'message', other: 'messages' }]"
}
"Welcome, :user! You have :[messages, { zero: 'messages', one: 'message', other: 'messages' }]",
},
};

@@ -56,12 +64,115 @@

user: "Elon Musk",
messages: 5
messages: 5,
});
```
## Running tests
### Advanced usage - defining
You can run all tests using `npm run test`
What makes this library special is the integrated CLI that enables developers to define their translation keys in a ligthweight, clean manner, by placing them in YAML with support for additional directives.
## Compiling documentation
Considering the above example:
This project uses `jsdoc` to compile documentation to HTML files to `docs` directory. You can run the process with `npm run genDocs`.
```javascript
const localeKeys = {
home: { welcome: "home.welcome" },
};
```
can be re-written as:
```yaml
home:
- welcome
```
which is transpiled by the CLI to just the TS code above which can be imported right into the actual project code. To do so, the project supports two scenarios:
- single-time compilation, e.g. in a buildscript: `i18n-plus compileKeys keys/entrypoint.yaml i18n/LocaleKeys.ts`, which would compile `keys/entrypoint.yaml` into TS and output the bundle to `i18n/LocaleKeys.ts`
- development compilation with watching, e.g. in a development script, which does the same as the above scenario, but also watches for changes in all files referenced by the entrypoint and the entrypoint itself, recompiling & rebuilding file dependency tree on file changes. The command is the same, all that is needed is just appending the `--dev` (or short `-d`) switch: `i18n-plus compileKeys keys/entrypoint.yaml i18n/LocaleKeys.ts --dev`
You can easily access the documentation of the tool by running `i18n-plus -?`, `i18n-plus -h`, or just failing to provide a valid command syntax, which will trigger help automatically and describe the problem on the bottom, e.g. running `i18n-plus compileKeys keys/entrypoint.yaml` (please note the missing output path) will print the following:
```bash
compileI18n compileKeys <input> <output>
compile I18n yaml files to importable TS bundle
Positionals:
input root YAML input file path [string] [required]
output output TS bundle file path [string] [required]
Options:
--version Show version number [boolean]
-d, --dev [boolean] [default: false]
-?, -h, --help Show help [boolean]
Not enough non-option arguments: got 1, need at least 2
```
Moreover, for the sake of larger projects, keys can be split into multiple files. Consider the example:
```javascript
const localeKeys = {
home: {
welcome: "home.welcome",
mainPanel: {
text1: "home.mainPanel.text1",
text2: "home.mainPanel.text2",
},
},
login: {
heading: "login.heading",
buttons: {
signIn: "login.buttons.signIn",
register: "login.buttons.register",
},
},
};
```
To simplify the definition and maintain readability, the structure can be split into three files:
_entrypoint.yaml_
```yaml
home: !include(./home.yaml)
login: !include(./login.yaml)
```
_home.yaml_
```yaml
- welcome
- mainPanel:
- text1
- text2
```
_login.yaml_
```yaml
- heading
- buttons:
- signIn
- register
```
---
## Compatibility
TS files generated by the CLI with `compileKeys` are compatible with [react-i18next](https://react.i18next.com/).
---
## Unit tests
This project uses `jest` accompanied by `ts-jest` for unit testing. You can run all tests using `npm test`.
## Documentation
This project uses `jsdoc` to compile documentation to HTML files to `docs` directory. You can run the process with `npm run genDocs`. The docs will be written to `docs/i18n-plus/X.X.X`, and the only manual requirement is to put a proper entry to line $10$ in `docs/index.html`: `const VERSIONS = [..., "X.X.X"];`.
## Changelog
The changelog is available on [github](https://github.com/artus9033/i18n-plus/blob/master/CHANGELOG.md) and is auto-generated by `auto-changelog`, available as a script: `npm run changelog`.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc