🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

format-message-loader

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

format-message-loader

Write default messages inline. Transpile translations with webpack.

latest
Source
npmnpm
Version
2.4.1
Version published
Maintainers
1
Created
Source

format-message-loader

Write i18n messages inline. Transpile translations with webpack.

npm Version Dependency Status JS Standard Style

a webpack loader for format-message

install

$ npm install format-message-loader --save-dev

api

formatMessage

in your webpack.config.js

These are the same as options that are passed to formatMessage.setup() See format-message for more information

module.exports = [ "en", "pt", "de" ].map(function(locale) {
  entry: "path/to/entry.js",
  output: {
    path: "path/to/output/",
    filename: "bundle.js"
  },
  module: {
    loaders: [
      {
        test:   /\.js$/,
        loader: "message-format"
      }
    ]
  },
  formatMessage: {
    functionName: "formatMessage", // identifier of function to inline
    locale: locale, // default locale
    translate: function(pattern, locales) {
      // from call formatMessage(pattern, args, locales)
      // if no locales were passed to format, locales will be the default locale (specified above)
      return require("path/to/translations/" + locale + ".json")[pattern];
    },
    translations: { // or rather than a translate function, lookup from an object
      pt: { ... },
      de: { ... }
    },
    keyType: "underscored_crc32", // or "underscored", "normalized", or "literal", default is "underscored_crc32"
    missingTranslation: "warning", // warn instead of fatal error, default is "error", can also be "ignore"
    missingReplacement: "!!NOT TRANSLATED!!" // use this when no translation found, default is the original pattern
  }
});

in your js file:

var formatMessage = require('format-message')
formatMessage('Welcome {name}!', { name:'Bob' })

License

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

Keywords

i18n

FAQs

Package last updated on 06 Jul 2015

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