Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
i18n-dialect
Advanced tools
dialect
is a library to support runtime i18n functions.
dialect
exports a controller class called TranslationController
, which should be instantiated in your application. Controller's constructor has following configurational parameters:
require
when running on server side, or asynchronous file load with fetch
or other asynchronous request library.%N
substitution is failed; may be undefined.The TranslationController
object also has a setLocale
method to update internal dictionary - once this is done, the changes are applied to all subsequent calls of translation functions. Notice that setLocale
method is asynchronous, so updating your user interface should not be done right after it's call: you should wait until everything is loaded and parsed.
dialect
exports four simple translation functions:
_tGen
for simple translations_ptGen
for contextual translations_ntGen
for plural translations_nptGen
for contextual plural translationsThese functions are function generators (higher order functions), and before using them in your project you should parameterize them with TranslationController
instance, like this:
import { TranslationController, _tGen, _ptGen, _ntGen, _nptGen } from 'i18n-dialect';
let controller = new TranslationController(...);
export const _t = _tGen(controller);
export const _pt = _ptGen(controller);
export const _nt = _ntGen(controller);
export const _npt = _nptGen(controller);
In some other file:
import { _t, _pt, _nt, _npt } from '...';
// now you can use _t, _pt, etc.
Make sure that names of your created functions are strictly equal to _t
, _nt
, _pt
and _npt
, and you use these functions with these names only in your code; otherwise your translations will not be parsed successfully with i18n-stex
parser.
dialect
also exports a single class called TranslationProvider
, which simplifies interaction with library for a bit. You should instantiate it once and then just pass it into your other files and components. Example:
import { TranslationController, TranslationProvider } from 'i18n-dialect';
let controller = new TranslationController(...);
export const i18n = new TranslationProvider(controller);
In some other file:
import { i18n } from '...';
// now you can use i18n._t, i18n._pt, etc.
i18n-dialect uses github-flow to accept & merge fixes and improvements. Basic process is:
npm run test
and make sure nothing is brokennpm run build
to build pure-js distribution files.Pull requests with failing tests will not be accepted. Also, if you add or modify packages to package.json
, make sure you use yarn
and update yarn.lock
.
FAQs
Internationalization support library
We found that i18n-dialect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 10 open source maintainers 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.