@colisweb/res-react-intl
v1.0.10
Published
ReScript PPX generating ReactIntl id from defaultMessage
Readme
res-react-intl
ReScript PPX generating ReactIntl id (short MD5) from defaultMessage.
Example
Input:
// Demo.res
open ReactIntl
module Msg = {
@@intl.messages
let hello = {defaultMessage: "Hello"}
}
module Component1 = {
@react.component
let make = () => {
<FormattedMessage defaultMessage="Some default message" />
}
}Output:
// Demo.bs.js
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict'
let ReactIntl = require('react-intl')
let JsxRuntime = require('react/jsx-runtime')
let Msg_hello = {
id: '_8b1a9953',
defaultMessage: 'Hello',
}
let Msg = {
hello: Msg_hello,
}
function Demo$Component1(props) {
return JsxRuntime.jsx(ReactIntl.FormattedMessage, {
id: '_0beb880a',
defaultMessage: 'Some default message',
})
}
let Component1 = {
make: Demo$Component1,
}
exports.Msg = Msg
exports.Component1 = Component1Installation
With yarn or npm on ReScript projects
Install the PPX with yarn or npm
yarn add res-react-intl bs-react-intl
# Or
npm install res-react-intl bs-react-intlAnd add the PPX in your rescript.json (or bsconfig.json) file:
{
"bs-dependencies": ["bs-react-intl"],
"ppx-flags": ["res-react-intl/ppx"]
}Extract the messages:
res-react-intl-extract --allow-duplicates srcDeveloping
Setup (once)
opam switch create . 4.14.2 --no-install --yes
eval $(opam env --switch=.)
opam install -y dune reason ocaml-migrate-parsetree yojson
cd test/rescript && yarn install && cd ../..Building the PPX
eval $(opam env --switch=.)
dune buildThis produces _build/default/bin/Ppx.exe and _build/default/bin/Extract.exe.
Running the integration test
cd test/rescript
yarn build # compiles Demo.res through the PPX
git diff src/Demo.bs.js # should be empty (output matches committed snapshot)
yarn extract # runs Extract.exe --allow-duplicates srcDev loop
Edit lib/Mapper.re or lib/Extractor.re, then:
dune build && cd test/rescript && yarn build && git diff src/Demo.bs.jsReleasing
- Bump the version of the ppx in
esy.jsononmaster(we use semantic versioning) - Create and push a new tag
$ git checkout master
$ git tag vx.y.z
$ git push origin vx.y.z- Create detailed release notes for the new version, following the
Added/Changed/Fixed/Removedformat. Note that the new version of the PPX will automatically be pushed to NPM and a release will be created on GitHub.
