Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jed

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jed

Gettext Style i18n for Modern JavaScript Apps

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
185K
decreased by-23.29%
Maintainers
1
Weekly downloads
 
Created

What is jed?

Jed is a JavaScript library for handling internationalization (i18n) and localization (l10n) in web applications. It provides tools for translating strings, handling plural forms, and formatting messages according to different locales.

What are jed's main functionalities?

Translation

Jed allows you to translate strings based on the provided locale data. In this example, 'Hello, world!' is translated to 'Hola, mundo!' using the locale data.

const Jed = require('jed');
const i18n = new Jed({
  locale_data: {
    messages: {
      '': {
        'domain': 'messages',
        'lang': 'en'
      },
      'Hello, world!': ['Hola, mundo!']
    }
  }
});
console.log(i18n.gettext('Hello, world!')); // Output: Hola, mundo!

Plural Forms

Jed supports plural forms, allowing you to provide different translations based on the number of items. In this example, the translation changes based on whether the count is 1 or more.

const Jed = require('jed');
const i18n = new Jed({
  locale_data: {
    messages: {
      '': {
        'domain': 'messages',
        'lang': 'en'
      },
      'One apple': ['Una manzana', 'Unas manzanas']
    }
  }
});
console.log(i18n.ngettext('One apple', '%d apples', 1)); // Output: Una manzana
console.log(i18n.ngettext('One apple', '%d apples', 2)); // Output: Unas manzanas

Contextual Translations

Jed allows for contextual translations, which means you can provide different translations for the same word based on the context. In this example, 'apple' is translated differently when it is in the context of 'fruit'.

const Jed = require('jed');
const i18n = new Jed({
  locale_data: {
    messages: {
      '': {
        'domain': 'messages',
        'lang': 'en'
      },
      'apple': ['manzana'],
      'fruit|apple': ['manzana (fruta)']
    }
  }
});
console.log(i18n.pgettext('fruit', 'apple')); // Output: manzana (fruta)
console.log(i18n.gettext('apple')); // Output: manzana

Other packages similar to jed

Keywords

FAQs

Package last updated on 22 Jul 2016

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