Skip to content

Support Message with Brace

Compare
Choose a tag to compare
@cwtuan cwtuan released this 12 Sep 16:47
· 172 commits to master since this release

In ICU standard, brace in message is treated as variable. An object is supposed to be passed as second parameter in the intl.get("key", object) function. Otherwise, react-intl-universal could not format the message, resulting in returning empty string.

// en-US.js
module.exports = ({
  "BRACE": "The format is {var}",
});

intl.get("BRACE"); // Before this release, it return empty string ""

However, in some case, brace is just a part of the sentence. It's better to be return the original message instead of empty string. This release fixes this issue. Here is the result:

intl.get("BRACE"); // "The format is {var}"
intl.get("BRACE", {var: "x.y.z"}); // "The format is x.y.z"