
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
messageformat-cli
Advanced tools
Parses and compiles the input JSON and .properties file(s) of MessageFormat strings into a JS module of corresponding hierarchical functions.
npm install messageformat@next messageformat-cli
messageformat
is a peer dependency of messageformat-cli
, and needs to be installed separately.
npx messageformat [options] [input]
or
./node_modules/.bin/messageformat [options] [input]
input
should consist of one or more files or directories, unless defined in a configuration file. Directories are recursively scanned for .json
and .properties
files. With multiple input files, shared parts of the start of their paths are dropped out of the generated module's structure.
In addition to defining options on the command line, options may also be set in the "messageformat"
object in your package.json
file, or in a messageformat.rc.json
configuration file, using the long-form option names as keys. Input files and directories may also be given as an "include"
array in a configuration file. Command-line options override configuration files.
-l lc, --locale=lc
The locale(s) lc
to include; if multiple, first is default and others are selected by matching message key. If not set or empty, path keys matching any locale code will set the active locale, starting with a default en
locale.
-n ns, --namespace=ns
By default, output is an ES6 module with a default export; set ns
to support other environments. If ns
does not contain a .
, the output follows an UMD pattern. For CommonJS module output, use --namespace=module.exports.
-o of, --outfile=of
Write output to the file of
. If unspecified or -
, prints to stdout.
--delimiters
Set of characters by which the file path is split into output object keys. [default: ._/
or ._\
depending on platform]
--disable-plural-key-checks
By default, messageformat throws an error when a statement uses a non-numerical key that will never be matched as a pluralization category for the current locale. Use this argument to disable the validation and allow unused plural keys. [default: false
]
--eslint-disable
Add an /* eslint-disable */
comment as the first line of the output, to silence ESLint warnings. [default: false
]
--extensions
Array or comma-separated list of file extensions to parse as source files. [default: ['.json', '.properties']
]
--simplify
Simplify the output object structure, by dropping intermediate keys when those keys are shared across all objects at that level, in addition to the default filtering-out of shared keys at the root of the object. [default: false
]
With messages/strings.json
, compile it into a node.js module using the default English locale:
npx messageformat messages/strings.json > messages/en.js
With messages/en.json
and messages/fr.json
, combine both into an ES6-compatible module, with the top-level keys en
and fr
containing functions that each use the correct language's pluralization rules:
npx messageformat --locale=en,fr messages/ > messages.js
Note: The locale
option could be left out here if is known that the data does not include any 2-3 letter keys matching other locales.
Same, but with this configuration in package.json
:
{
...,
"messageformat": {
"locale": ["en", "fr"],
"include": [
"messages/"
],
"outfile": "messages.js"
},
"scripts": {
...,
"build:messages": "messageformat"
}
}
npm run build:messages
FAQs
MessageFormat CLI
The npm package messageformat-cli receives a total of 1,343 weekly downloads. As such, messageformat-cli popularity was classified as popular.
We found that messageformat-cli demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.