Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
babel-plugin-lingui-transform-js
Advanced tools
This plugin transforms messages written using
lingui-i18n
methods to static ICU message format.
The transformation speeds up translation at runtime while using helper methods allows to type-check messages.
npm install --save-dev babel-plugin-lingui-transform-js
# or
yarn add --dev babel-plugin-lingui-transform-js
.babelrc
(Recommended).babelrc
{
"plugins": ["lingui-transform-js"]
}
babel --plugins lingui-transform-js script.js
require("babel-core").transform("code", {
plugins: ["lingui-transform-js"]
})
Plugin performs following transformations:
i18n.t`Hello World`
// becomes
i18n.t({ id: "Hello World" })
i18n.t`Hi, my name is ${name}`
// becomes
i18n.t({ id: "Hi, my name is {name}", params: { name }})
Format is basically a function which receives a value
and format options. It's transformed to {variable, format, options}
form. The most common formats are plural
, select
and ordinal
:
i18n.plural({
value: count,
one: "# Book",
other: "# Books"
})
// becomes
i18n.t({
id: "{count, plural, one {# Book} other {# Books}}",
params: { count }
})
Number/date formats:
i18n.t`The answer is ${i18n.number(answer)}`
// becomes
i18n.t({
id: "The answer is {answer, number}",
params: { answer }
})
Custom formats:
const currency = {
style: 'currency',
currency: 'EUR'
}
i18n.t`The price is ${i18n.number(amount, currency)}`
// becomes
i18n.t({
id: "The price is {amount, number, currency}",
params: { answer },
formats: { currency }
})
i18n.select({
value: gender,
male: i18n.plural({
value: numOfGuests,
offset: 1,
0: `${host} doesn't invite any guests`,
1: `${host} invite ${guest} to his party`,
other: `${host} invite ${guest} and # other to his party`
}),
female: i18n.plural({ ... })
})
// becomes
i18n.t({
id: "{gender, select, male {{numOfGuests, plural, offset:1 =0 {...}}} female {...}}",
params: { gender, numOfGuests, host, guest }
})
FAQs
Transform lingui-i18n methods to ICU message format
The npm package babel-plugin-lingui-transform-js receives a total of 17 weekly downloads. As such, babel-plugin-lingui-transform-js popularity was classified as not popular.
We found that babel-plugin-lingui-transform-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.