6.2.4 • Published 2 years ago

format-message-estree-util v6.2.4

Weekly downloads
6,084
License
MIT
Repository
github
Last release
2 years ago

format-message

Internationalize text, numbers, and dates using ICU Message Format.

npm Version Build Status Greenkeeper badge

JS Standard Style MIT License

Internationalization Made Easy

Start simple. Wrap any user-facing message with formatMessage(). Don't forget to import/require format-message.

var formatMessage = require('format-message');
// ...
formatMessage('My Account Preferences')

Don't concatenate message pieces, use placeholders instead.

formatMessage('Hello, { name }!', { name: user.name })

You can even pick plural and gender forms with placeholders.

formatMessage(`{
  gender, select,
    male {His inbox}
  female {Her inbox}
   other {Their inbox}
 }`, { gender: user.gender })

 formatMessage(`{
   count, plural,
      =0 {No unread messages}
     one {# unread message}
   other {# unread messages}
 }`, { count: messages.unreadCount })

Need to provide extra information to translators? Add a message description. Need 2 translations to the same English message? Add a message id.

formatMessage({
  id: 'update_action_button',
  default: 'Update',
  description: 'Text displayed on the update resource button to trigger the update process'
})
formatMessage({
  id: 'update_label',
  default: 'Update',
  description: 'Label on each item that is an update to another item'
})

Extract all of the messages you've used in your source code.

$ npm i format-message-cli
$ format-message extract "src/**/*.js" > ./locales/en/messages.json

Check that the translators preserved placeholders and proper message formatting.

$ format-message lint -t ./locales/index.js "src/**/*.js"

Use the translations at runtime.

formatMessage.setup({
  generateId: require('format-message-generate-id/underscored_crc32'),
  translations: require('./locales'),
  locale: 'pt'
})

Make a locale-specific build.

$ format-message transform --inline --locale pt "src/**/*.js" > bundle.pt.js

Need more details?

Check out the many ways you can use format-message in your project:

License

This software is free to use under the MIT license. See the LICENSE-MIT file for license text and copyright information.

6.2.4

2 years ago

6.1.0

6 years ago

6.0.4

6 years ago

6.0.0

6 years ago

6.0.0-alpha.2

6 years ago

6.0.0-alpha.1

6 years ago

6.0.0-alpha.0

6 years ago

5.2.3

6 years ago

5.2.1

6 years ago

5.1.3

7 years ago

5.1.2

7 years ago

5.1.0

7 years ago

5.0.0

8 years ago

5.0.0-beta.10

8 years ago

5.0.0-beta.9

8 years ago

5.0.0-beta.8

8 years ago

5.0.0-beta.6

8 years ago

5.0.0-beta.3

8 years ago

5.0.0-beta.0

8 years ago