Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
,, ,, ,,
`7MM db `7MM mm
MM MM MM
,M""bMM `7MM ,6"Yb. MM .gP"Ya ,p6"bo mmMMmm
,AP MM MM 8) MM MM ,M' Yb 6M' OO MM
8MI MM MM ,pm9MM MM 8M"""""" 8M MM
`Mb MM MM 8M MM MM YM. , YM. , MM
`Wbmd"MML..JMML.`Moo9^Yo..JMML.`Mbmmd' YMbmd' `Mbmo
Dialect is a painless nodejs module that deals with i18n, and L10n.
This module is under construction.
Currently dialect just supports MongoDB, so, you need to install it or fork your own storage solution .
npm install dialect
var dialect = require('dialect').dialect({
path:'./dictionaries',
base_locale: 'en',
});
// change our locale to Spanish
dialect.config('locale', 'es');
// Configs and open the storage connection
require('dialect').store(
{store: 'mongodb', database: 'translations'},
function (error, store) {
dialect.config('store', store);
dialect.getTranslation('Hello World!');
}
);
Dialect stores automatically all the strings pending to be translated. Once your translate the strings, they will be cached on a JSON file for every machine that needs the translations. The JSON will be loaded to memory, so you will acces the translations from memory.
Dialect supports counts and contexts.
A counts are params that allow you to output a string using singular or plural. You need to provide an array with the singular, plural and the number.
[1, 2, 3].forEach(function (i) {
dialect.getTranslation([
'Hello World',
'Hello Worlds',
{count: i}
]);
});
// => 'Hola Mundo'
// => 'Hola Mundos'
// => 'Hola Mundos'
A context is a param that allows you to give a special meaning about a sentence. It helps the translator and it may generate diferent translations depending on the context.
['female', 'male'].forEach(function (gender) {
dialect.getTranslation([
'My friends',
gender
]);
});
// => 'Mis amigas'
// => 'Mis amigos'
You can put any param you want on the translation strings surrounded by moustaches {}. Remember that count and context have special meanings although they can be used with interpolations.
[1, 2].forEach(function (count) {
['female', 'male'].forEach(function (gender) {
dialect.getTranslation([
'You have {count} friend called {name}',
'You have {count} friends called {name}',
{count: count, context: context, name: 'Anna'}
]);
});
});
// => 'Tienes 1 amiga que se llama Anna'
// => 'Tienes 1 amigo que se llama Anna'
// => 'Tienes 2 amigas que se llaman Anna'
// => 'Tienes 2 amigos que se llaman Anna'
To store a new translation, use the method setTranslation.
dialect.setTranslation(
{original: 'I love gazpacho', locale: 'es'},
'Me encanta el gazpacho',
function () {
// :)
}
);
Dialect is heavily tested using a mix of Vows and node asserts module.
make test
Dialect should not add an overhead to your application on getting translations. Please run/add benchmarks to ensure that this module performance rocks.
node benchmakrs/app.js
Have fun!
FAQs
Translations manager for nodejs
The npm package dialect receives a total of 5 weekly downloads. As such, dialect popularity was classified as not popular.
We found that dialect 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.