Releases: alibaba/react-intl-universal
2.3.1
Update intl-messageformat@8 for Number Skeletons.
Multiple Instance
react-intl-universal
is singleton by default. However, if you would like to have multiple react-intl-universal
instance, you could instantiate it on demand.
import intl from 'react-intl-universal'; // singleton instance
It's equalivent to:
import { ReactIntlUniversal } from 'react-intl-universal';
const intl = new ReactIntlUniversal();
localStorage's key to determine current key
If there's a item lang=en-US
in localStorage, you could determine currentLocale
as the following code.
intl.determineLocale( {localStorageLocaleKey: 'lang'} );
Remove Network Dependency for Downloading Common Locale Data
Support fallbackLocale option
Support fallbackLocale
option to use if a key is not found in the currentLocale
. #91
Add escapeHtml option to disable escaping html
To prevent XSS attack, escaping Html is enabled by default.
However, if you would like to disable escaping Html in some cases, use escapeHtml
option.
See the test case for example.
Support Message with Brace
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"
Custom Common Locale Data URL
The Common Locale Data is now hosted in //g.alicdn.com
, however some users in private network may not able to access the internet. This release make the common locale data URL optional. #76, #68, #63, #71
intl.init({
// ...
commonLocaleDataUrls: {
en: "https://g.alicdn.com/react-intl-universal/locale-data/1.0.0/en.js",
zh: "https://g.alicdn.com/react-intl-universal/locale-data/1.0.0/zh.js",
}
});
Moreover, if you encounter the following error, this options make supporting more languages possible. #51
Language "${lang}" is not supported.
Custom Warning Handler
Whenever a default message is missing or having error for formatting a message, react-intl-universal
will log warning message like this react-intl-universal key "not-exist-key" not defined in en-US
.
If you would like to log these messages using third party services or even turn off the message, here is a chance to add custom warning handler in init
function.
const locales = {...};
const currentLocale = "en-US";
const warningHandler = (message, detail) => {...}; // Define your custom warning handler
intl.init({
locales,
currentLocale,
warningHandler
})
Support Electron
Electron environment is treated as Node.js environment now.
In Electron, react-intl-universal
will not fetch locale files via CDN. You can bundle locale files on demand.
This release fixes #56.