Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
@formatjs/intl-displaynames
Advanced tools
@formatjs/intl-displaynames is a JavaScript library that provides a way to display names of various international entities such as languages, regions, scripts, and currencies in a localized manner. It leverages the Internationalization API to format these names according to the specified locale.
Display Language Names
This feature allows you to display the name of a language in a localized format. In this example, the name of the French language is displayed in English.
const { DisplayNames } = require('@formatjs/intl-displaynames');
const displayNames = new DisplayNames(['en'], { type: 'language' });
console.log(displayNames.of('fr')); // Output: French
Display Region Names
This feature allows you to display the name of a region in a localized format. In this example, the name of the United States is displayed in English.
const { DisplayNames } = require('@formatjs/intl-displaynames');
const displayNames = new DisplayNames(['en'], { type: 'region' });
console.log(displayNames.of('US')); // Output: United States
Display Script Names
This feature allows you to display the name of a script in a localized format. In this example, the name of the Latin script is displayed in English.
const { DisplayNames } = require('@formatjs/intl-displaynames');
const displayNames = new DisplayNames(['en'], { type: 'script' });
console.log(displayNames.of('Latn')); // Output: Latin
Display Currency Names
This feature allows you to display the name of a currency in a localized format. In this example, the name of the US Dollar is displayed in English.
const { DisplayNames } = require('@formatjs/intl-displaynames');
const displayNames = new DisplayNames(['en'], { type: 'currency' });
console.log(displayNames.of('USD')); // Output: US Dollar
Globalize is a library for internationalization and localization in JavaScript. It provides functionalities for formatting and parsing dates, numbers, and currencies, as well as message translation. Compared to @formatjs/intl-displaynames, Globalize offers a broader range of internationalization features but may require more configuration.
i18next is a popular internationalization framework for JavaScript. It supports translation, formatting, and pluralization. While it does not specifically focus on displaying names of languages, regions, scripts, and currencies, it provides a comprehensive solution for managing translations and localization in web applications.
The intl package is a polyfill for the ECMAScript Internationalization API, which includes functionalities for formatting dates, numbers, and currencies. It provides a lower-level API compared to @formatjs/intl-displaynames but can be used to achieve similar results with more manual effort.
intl-displaynames
A ponyfill/polyfill for intl-displaynames
.
intl-displaynames
is beta quality software that hasn't been tested thoroughly.
npm install @formatjs/intl-displaynames
Everything in https://github.com/tc39/proposal-intl-displaynames.
To use the ponyfill, import it along with its data:
import {DisplayNames} from '@formatjs/intl-displaynames';
DisplayNames.__addLocaleData(
require('@formatjs/intl-displaynames/dist/locale-data/en.json') // locale-data for en
);
DisplayNames.__addLocaleData(
require('@formatjs/intl-displaynames/dist/locale-data/zh.json') // locale-data for zh
);
new DisplayNames('zh', {type: 'currency'}).of('USD'); //=> "美元"
To use this as a polyfill, override Intl.DisplayNames
as below:
import '@formatjs/intl-displaynames/polyfill';
import '@formatjs/intl-displaynames/dist/locale-data/en'; // locale-data for en
import '@formatjs/intl-displaynames/dist/locale-data/zh'; // locale-data for zh
new Intl.DisplayNames('en').of('zh-Hans'); //=> "Simplified Chinese"
new Intl.DisplayNames('zh', {type: 'currency'}).of('USD'); //=> "美元"
FAQs
Polyfill for: https://tc39.es/proposal-intl-displaynames
The npm package @formatjs/intl-displaynames receives a total of 1,379,827 weekly downloads. As such, @formatjs/intl-displaynames popularity was classified as popular.
We found that @formatjs/intl-displaynames demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.