Coder Social home page Coder Social logo

torifat / format-message Goto Github PK

View Code? Open in Web Editor NEW

This project forked from format-message/format-message

0.0 3.0 0.0 905 KB

Internationalization Made Easy

Home Page: http://format-message.github.io/icu-message-format-for-translators/

License: MIT License

JavaScript 100.00%

format-message's Introduction

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.

format-message's People

Contributors

vanwagonet avatar greenkeeper[bot] avatar greenkeeperio-bot avatar brentropy avatar straker avatar bjohn465 avatar edwardscam avatar jamesplease avatar tsmmark avatar probertson avatar minimalmonkey avatar thorbenprimke avatar

Watchers

Rifat Nabi avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.