Socket
Socket
Sign inDemoInstall

@ladjs/i18n

Package Overview
Dependencies
Maintainers
2
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ladjs/i18n

i18n wrapper and Koa middleware for Lad


Version published
Weekly downloads
111K
decreased by-22.18%
Maintainers
2
Weekly downloads
 
Created

What is @ladjs/i18n?

@ladjs/i18n is a comprehensive internationalization (i18n) library for Node.js. It provides robust support for translating applications into multiple languages, managing locale data, and handling various localization needs. The package is designed to be flexible and easy to integrate into existing projects.

What are @ladjs/i18n's main functionalities?

Basic Translation

This feature allows you to set up basic translations for different locales. You can add translations for specific keys and retrieve the translated messages based on the current locale.

const I18n = require('@ladjs/i18n');
const i18n = new I18n();

// Set the locale
i18n.setLocale('en');

// Add translations
i18n.addTranslations('en', {
  greeting: 'Hello'
});

// Translate a message
console.log(i18n.translate('greeting')); // Output: Hello

Dynamic Locale Switching

This feature demonstrates how to switch between different locales dynamically. You can add translations for multiple languages and change the locale at runtime to get the appropriate translations.

const I18n = require('@ladjs/i18n');
const i18n = new I18n();

// Add translations for multiple locales
i18n.addTranslations('en', { greeting: 'Hello' });
i18n.addTranslations('es', { greeting: 'Hola' });

// Switch locale dynamically
i18n.setLocale('es');
console.log(i18n.translate('greeting')); // Output: Hola

i18n.setLocale('en');
console.log(i18n.translate('greeting')); // Output: Hello

Pluralization Support

This feature shows how to handle pluralization in translations. You can define different messages for singular and plural forms and use the `count` variable to get the correct translation.

const I18n = require('@ladjs/i18n');
const i18n = new I18n();

// Add translations with pluralization
i18n.addTranslations('en', {
  apple: {
    one: 'one apple',
    other: '{{count}} apples'
  }
});

// Translate with pluralization
console.log(i18n.translate('apple', { count: 1 })); // Output: one apple
console.log(i18n.translate('apple', { count: 5 })); // Output: 5 apples

Other packages similar to @ladjs/i18n

Keywords

FAQs

Package last updated on 03 May 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