Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Node.js package providing i18n with variable interpolation & conjugation of words with respect to quantifiers, supporting all languages' conjugation rules.
A node.js package providing i18n with variable interpolation & conjugation of words with respect to quantifiers, supporting all languages' conjugation rules.
!include()
directivesYou can read the full documentation with examples there.
The key function provided is trans(key, interpolationParams = {})
There are two specifiers available for use:
:variableName
- simply replaces all such fields with the corresponding values supplied as Object properties in the second argument of trans
call:[quantityVarName, { zero: 'values', one: 'value', other: 'values' } ]
-import { Locales, LocaleHelper, Translation } from "i18n-plus";
// these will be the keys used in the dictionary to identify texts
const localeKeys = {
home: { welcome: "home.welcome" },
};
// this is the actual translation for a single language
const translationEN: Translation<typeof LocaleKeys> = {
home: {
welcome:
"Welcome, :user! You have :[messages, { zero: 'messages', one: 'message', other: 'messages' }]",
},
};
let localeHelper = new LocaleHelper(localeKeys, {
[Locales.en]: translationEN,
});
// here, you can do whatever you want with the translated & interpolated text, e.g. send it with an HTTP response, render it as a React or HTML component, log it to the console, etc.
let welcomeMessage = localeHelper.trans(localeKeys.home.welcome, {
user: "Elon Musk",
messages: 5,
});
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.
Considering the above example:
const localeKeys = {
home: { welcome: "home.welcome" },
};
can be re-written as:
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:
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
--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:
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:
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
home: !include(./home.yaml)
login: !include(./login.yaml)
home.yaml
- welcome
- mainPanel:
- text1
- text2
login.yaml
- heading
- buttons:
- signIn
- register
TS files generated by the CLI with compileKeys
are compatible with react-i18next.
This project uses jest
accompanied by ts-jest
for unit testing. You can run all tests using npm test
.
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"];
.
The changelog is available on github and is auto-generated by auto-changelog
, available as a script: npm run changelog
.
FAQs
Node.js package providing i18n with variable interpolation & conjugation of words with respect to quantifiers, supporting all languages' conjugation rules.
We found that i18n-plus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.