
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@novigi/i18n
Advanced tools
A versatile library for seamless string translation utilizing custom language files.
A versatile library for seamless string translation utilizing custom language files.
npm install @novigi/i18n
const lib = require('@novigi/i18n');
Represents an internationalization (i18n) module.
This library provides methods for translating a string using a JSON file that contains translated versions of words or sentences.
The language file should be a flat JSON file.
The content of the sample file used in the following usage example is as follows ( si-LK.json ) :
{
"hello": "හෙලෝ",
"world": "ලෝකය",
"Hello World":"හෙලෝ ලෝකය"
}
Translation can be implemented as follows:
const I18n = require('@novigi/i18n')
const i18n = new I18n('/path/to/si-LK.json')
const translatedText = i18n.translate('Hello World')
console.log(translatedText);
const translatedSentence = i18n.translateBySentence('Hello World')
console.log(translatedSentence);
//"හෙලෝ ලෝකය"
//"හෙලෝ ලෝකය"
stringstringRepresents an Internationalization (i18n) utility class for translating strings.
Kind: inner class of i18n
stringstringConstructs a new instance of the I18n class.
Returns: I18n - A new instance of the I18n object.
Throws:
I18nParameterError - When the filePath is not provided or an empty string.I18nParameterError - When the filePath is not an absolute path.| Param | Type | Default | Description |
|---|---|---|---|
| filePath | string | The file path of the translation source file. | |
| [options] | object | { removeUnavailable: false,removePunctuation: false,skip: [],defaultValue: null } | Optional parameters for customizing the translation. |
| [options.removeUnavailable] | boolean | false | Determines whether to remove or keep words that don't have a translation in the language file. |
| [options.removePunctuation] | boolean | false | Determines whether to remove or keep punctuation marks. Punctuation marks include: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { |
| [options.skip] | Array.<string> | [] | An array of words that should be skipped during translation. |
| [options.defaultValue] | string | "''" | The default value to be returned when there is no mapping for a word. |
Example
// Create an instance of I18n with the absolute source file path
const i18n = new I18n('/path/to/language-file.json')
// Create an instance of I18n with the absolute source file path and optional parameter options
const i18n = new I18n('/path/to/language-file.json', options)
stringTranslates the given text using the specified translation options.
Kind: instance property of I18n
Returns: string - The translated text.
Throws:
I18nTranslateError - If the text is not a string.| Param | Type | Default | Description |
|---|---|---|---|
| text | string | The text to be translated. | |
| [translateOptions] | object | {removeUnavailable: false,removePunctuation: false,skip: []} | The translation options specify the configuration settings for the translation process. These options are similar to the class-level options, but they are scoped to the functional level, providing flexibility for individual translation operations. |
| [options.removeUnavailable] | boolean | false | Determines whether to remove or keep words that don't have a translation in the language file. |
| [options.removePunctuation] | boolean | false | Determines whether to remove or keep punctuation marks. Punctuation marks include: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { |
| [options.skip] | Array.<string> | [] | An array of words that should be skipped during translation. |
Example
// Translate a string
const translatedText = i18n.translate('Hello')
// Translate a string with optional parameter options
const translatedText = i18n.translate('Hello', options)
stringTranslates a sentence using the provided translation dictionary.
Kind: instance property of I18n
Returns: string - The translated sentence if available in the dictionary, otherwise returns
the original sentence or an empty string if the sentence is falsy.
Throws:
I18nTranslateError When the sentence is not a string.| Param | Type | Description |
|---|---|---|
| sentence | string | The sentence to translate. |
Example
// Translate a sentence
const translatedSentence = i18n.translateBySentence("Hello, how are you?");
This is an auto generated file. Please don't make changes manually
FAQs
A versatile library for seamless string translation utilizing custom language files.
We found that @novigi/i18n demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.