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

Node.js package providing i18n with variable interpolation & conjugation of words with respect to quantifiers, supporting all languages' conjugation rules.

  • 2.0.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
40
increased by3900%
Maintainers
1
Weekly downloads
 
Created
Source

i18n-plus

GitHub issues GitHub forks GitHub stars GitHub license

A node.js package providing i18n with variable interpolation & conjugation of words with respect to quantifiers, supporting all languages' conjugation rules.

Features

  • Translating strings using user-defined dictionaries (key-value system)
  • Interpolation of strings with variables
  • User-defined conjugation (e.g. for pluralization, grammatical case conjugation, etc.) with respect to the quantity, passed in as a variable
  • Strongly typed with TypeScript

Documentation

You can read the full documentation with examples there.

Simple usage in a brief

The key function is trans(key, interpolationParams = {})

There are two specifiers available for you to 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
  2. Conjugation syntax :[quantityVarName, { zero: 'values', one: 'value', other: 'values' } ] -
import { Locales, LocaleHelper } 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 dictionary
const localeValues = {
	[Locales.en]: {
		[localeKeys.home.welcome]:
			"Welcome, :user! You have :[messages, { zero: 'messages', one: 'message', other: 'messages' }]"
	}
};

let localeHelper = new LocaleHelper(localeKeys, localeValues);

// 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
});

Running tests

You can run all tests using npm run test

Compiling documentation

This project uses jsdoc to compile documentation to HTML files to docs directory. You can run the process with npm run genDocs.

Keywords

FAQs

Package last updated on 23 Nov 2020

Did you know?

Socket

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.

Install

Related posts

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