New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

intl-message

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intl-message

Simple Intl message translation

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

intl-message

NPM Version

Simple intl message translation

Install

npm i intl-message
# or
yarn add intl-message

Usage

See hello world example

Add command line tool to package.json

{
  //...
  "script": {
    "intl:extract": "intl-extract"
  }
  //...
}

Extracting Messages from Source Code

yarn intl:extract

Source Code

intl.js

import { Intl } from 'intl-message';
const intl = new Intl({
  en: require('./locales/en.json'),
  'zh-cn': require('./locales/zh-cn.json'),
});
export default intl;
export const __ = (...params) => intl.formatMessage(...params);

app.js

import intl, { __ } from './intl';
console.log(__({ id: 'hello', defaultMessage: 'Hello, World!' }));
// Hello, World!
intl.language = 'zh-cn';
console.log(__({ id: 'hello' }));
// [en]Hello, World!

Update Dictionary

Edit locales/zh-ch.json

{
  "hello": "你好,世界!"
}

Run app.js again:

Hello, World!
你好,世界!

Licence

MIT

Keywords

intl

FAQs

Package last updated on 14 Nov 2019

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