Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onComplete: function () {
console.log('Fastest is ' + this.filter('fastest').map('name').join(' or '))
console.log()
}
}
var suite = new Benchmark.Suite(name, suiteOptions)
Object.keys(cases).forEach(function (name) {
suite.add(name, cases[name])
})
suite.run()
}
pattern = 'Simple string with nothing special'
formatMessage(pattern, args, 'en') // prime cache
intlMF = new IntlMF(pattern, 'en').format
mf2 = new MessageFormat2('en').compile(pattern)
mf = new MessageFormat(pattern, 'en').format
BENCHMARK_PARSE && benchmark(
'Parse simple message', {
'intl-messageformat-parser': function () { return intlParse(pattern) },
'messageformat-parser': function () { return parse2(pattern) },
'format-message-parse': function () { return parse(pattern) }
}
)
benchmark(
'Format simple message', {
'intl-messageformat (reuse object)': function () { return intlMF(args) },
'messageformat (reuse object)': function () { return mf2(args) },
'message-format (reuse object)': function () { return mf(args) },
'format-message': function () { return formatMessage(pattern, args, 'en') },
'format-message (inlined)': function () { return formatMessage('Simple string with nothing special', args, 'en') }
function _formatIcuMessage(locale, icuMessageId, icuMessage, values) {
const localeMessages = LOCALES[locale];
const localeMessage = localeMessages[icuMessageId] && localeMessages[icuMessageId].message;
// fallback to the original english message if we couldn't find a message in the specified locale
// better to have an english message than no message at all, in some number cases it won't even matter
const messageForMessageFormat = localeMessage || icuMessage;
// when using accented english, force the use of a different locale for number formatting
const localeForMessageFormat = locale === 'en-XA' ? 'de-DE' : locale;
// pre-process values for the message format like KB and milliseconds
const valuesForMessageFormat = _preprocessMessageValues(icuMessage, values);
const formatter = new MessageFormat(messageForMessageFormat, localeForMessageFormat, formats);
const formattedString = formatter.format(valuesForMessageFormat);
return {formattedString, icuMessage: messageForMessageFormat};
}
other {#th}
} banana today, which makes {
numBananas, plural,
=0 {no bananas}
=1 {a banana}
other {lots of bananas}
} total.`
args = {
date: new Date(),
name: 'Curious George',
gender: 'male',
numBananas: 300,
nth: 3
}
formatMessage(pattern, args, 'en') // prime cache
intlMF = new IntlMF(pattern, 'en').format
mf2 = new MessageFormat2('en').compile(pattern)
mf = new MessageFormat(pattern, 'en').format
BENCHMARK_PARSE && benchmark(
'Parse complex message (no numbers or dates)', {
'intl-messageformat-parser': function () { return intlParse(pattern) },
'messageformat-parser': function () { return parse2(pattern) },
'format-message-parse': function () { return parse(pattern) }
}
)
benchmark(
'Format complex message (no numbers or dates)', {
'intl-messageformat (reuse object)': function () { return intlMF(args) },
'messageformat (reuse object)': function () { return mf2(args) },
'message-format (reuse object)': function () { return mf(args) },
'format-message': function () { return formatMessage(pattern, args) },
'format-message (inlined)': function () {
}
)
benchmark(
'Format simple message', {
'intl-messageformat (reuse object)': function () { return intlMF(args) },
'messageformat (reuse object)': function () { return mf2(args) },
'message-format (reuse object)': function () { return mf(args) },
'format-message': function () { return formatMessage(pattern, args, 'en') },
'format-message (inlined)': function () { return formatMessage('Simple string with nothing special', args, 'en') }
}
)
pattern = 'Simple string with { placeholder }.'
args = { placeholder: 'replaced value' }
formatMessage(pattern, args, 'en') // prime cache
intlMF = new IntlMF(pattern, 'en').format
mf2 = new MessageFormat2('en').compile(pattern)
mf = new MessageFormat(pattern, 'en').format
BENCHMARK_PARSE && benchmark(
'Parse common one arg message', {
'intl-messageformat-parser': function () { return intlParse(pattern) },
'messageformat-parser': function () { return parse2(pattern) },
'format-message-parse': function () { return parse(pattern) }
}
)
benchmark(
'Format common one arg message', {
'intl-messageformat (reuse object)': function () { return intlMF(args) },
'messageformat (reuse object)': function () { return mf2(args) },
'message-format (reuse object)': function () { return mf(args) },
'format-message': function () { return formatMessage(pattern, args, 'en') },
'format-message (inlined)': function () { return formatMessage('Simple string with { placeholder }.', { placeholder: 'replaced value' }, 'en') }
I18N.prototype.get = function (str, args) {
var msg = lodashGet(this.__data__, str);
if (!msg) {
msg = lodashGet(this.__metas__['zh-CN'], str, str);
}
if (args) {
try {
msg = new intl_messageformat_1.default(msg, this.__lang__);
msg = msg.format(args);
return msg;
}
catch (err) {
console.warn("kiwi-intl format message failed for key='" + str + "'", err);
return '';
}
}
else {
return msg;
}
};
return I18N;
I18n.prototype.formatMessage = function (key, vars) {
if (vars === void 0) { vars = {}; }
var message = this.messages[key] || key;
return new intl_messageformat_1["default"](message, this.locale, this.formats).format(vars);
};
return I18n;
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import IntlObj from 'intl';
import IntlMessageFormatObj from 'intl-messageformat';
import IntlRelativeFormatObj from 'intl-relativeformat';
import createFormatCacheObj from 'intl-format-cache';
import i18nJson from 'i18nJson';
/*
Intl libs are using out dated transpailer from ecmascript6.
* TODO: As soon as they fix it, remove this assignments!!!
* */
var Intl = window.Intl || IntlObj.default,
IntlMessageFormat = IntlMessageFormatObj.default,
IntlRelativeFormat = IntlRelativeFormatObj.default,
createFormatCache = createFormatCacheObj.default;
/*extract locale*/
var _locale = window.localStorage && localStorage.getItem('user_locale');
if (!_locale) {
if (window.navigator) {
_locale = navigator.language || navigator.userLanguage;
//For now removing the dashes from the language.
let indexOfDash = _locale.indexOf('-');
if (-1 !== indexOfDash) {
_locale = _locale.substr(0, indexOfDash);
}
}
if (!_locale) {