
Security News
pnpm 10.12 Introduces Global Virtual Store and Expanded Version Catalogs
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
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.
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
i18next is a popular internationalization framework for JavaScript. It provides a complete solution for translating strings, handling plural forms, and managing localization data. Compared to Jed, i18next offers more features and integrations, making it suitable for larger projects.
Globalize is a library for internationalization and localization in JavaScript. It provides tools for formatting numbers, dates, and messages according to different locales. While Jed focuses on string translations, Globalize offers a broader range of localization features.
React Intl is a library for internationalizing React applications. It provides components and APIs for formatting dates, numbers, and strings based on the user's locale. Compared to Jed, React Intl is specifically designed for use with React, making it a better choice for React-based projects.
Gettext Style i18n for Modern JavaScript Apps
For more info, please visit the docs site at http://slexaxton.github.com/Jed.
Jed is feature complete in my opinion. I am happy to fix bugs, but generally am not interested in adding more to the library.
I also maintain messageformat.js. If you don't specifically need a gettext implementation, I might suggest using MessageFormat instead, as it has better support for plurals/gender and has built-in locale data.
Jed doesn't include a Gettext file parser, but several third-party parsers exist that can have their output adapted for Jed.
Just search the npm repository, there are several PO and MO file parsers available.
Jed Gettext Parser is the only known browser MO file parser, and it also works in Node, and outputs Jed-compatible data directly.
gettext.js and Pomo.js both include browser-compatible PO file parsers.
Jed is a member project of the jQuery Foundation
You may use this software under the MIT License.
You may contribute to this software under the jQuery Foundation CLA - https://contribute.jquery.org/CLA/
A good chunk of sanity checking was done against the gettext.js tests. That was written by:
The sprintf implementation is from:
The name jed.js is an homage to Jed Schmidt (https://github.com/jed) the JavaScript community member who is a japanese translator by day, and a "hobbyist" JavaScript programmer by night. Give your kids three character names and they'll probably get software named after them too.
FAQs
Gettext Style i18n for Modern JavaScript Apps
The npm package jed receives a total of 209,517 weekly downloads. As such, jed popularity was classified as popular.
We found that jed 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.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.