How to use the intl-messageformat.formats function in intl-messageformat

To help you get started, we’ve selected a few intl-messageformat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sebastian-software / vue-locale / src / VueLocale.js View on Github external
import { kebabCase, isPlainObject, isString, isNumber, isDate, each, clamp } from "lodash"

// Be sure to import the Polyfill
// TODO: Figure out if there is a ES2015 way to conditional load this
import "intl"

// NodeJS by default to not offer full ICU support and therefor break the unit tests
if (!areLocalesSupported([ "en", "de", "fr", "es" ]))
{
  /* global IntlPolyfill */
  Intl.NumberFormat = IntlPolyfill.NumberFormat
  Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat
}

const formats = IntlMessageFormat.formats

const getCachedNumberFormat = createFormatCache(Intl.NumberFormat)
const getCachedDateTimeFormat = createFormatCache(Intl.DateTimeFormat)
const getCachedMessageFormat = createFormatCache(IntlMessageFormat)
const getCachedRelativeFormat = createFormatCache(IntlRelativeFormat)

// A constant defined by the standard Intl.NumberFormat
// const maximumFractionDigits = 20;
// Unfortunately through formatting issues of percent values in IE
// we have to use a small value here, because IE (as of v11) seems to
// account the percent symbol + optional space to the fraction digits.
// See also: https://github.com/sebastian-software/vue-locale/issues/1#issuecomment-215396481
const maximumFractionDigits = 18;


function install(Vue, options)
github xpepermint / translatedjs / src / index.ts View on Github external
constructor ({
    locale = 'en-US',
    messages = {},
    formats = {}
  }: {
    locale: string,
    messages?: any,
    formats?: any
  }) {
    this.locale = locale;
    this.messages = messages;
    this.formats = merge(MessageFormat.formats, defaultFormats, formats);
  }
github formatjs / react-intl / src / formatters / message.ts View on Github external
function deepMergeFormatsAndSetTimeZone(
  f1: CustomFormats,
  timeZone?: string
): CustomFormats {
  if (!timeZone) {
    return f1;
  }
  const mfFormats = IntlMessageFormat.formats;
  return {
    ...mfFormats,
    ...f1,
    date: deepMergeOptions(
      setTimeZoneInOptions(mfFormats.date, timeZone),
      setTimeZoneInOptions(f1.date || {}, timeZone)
    ),
    time: deepMergeOptions(
      setTimeZoneInOptions(mfFormats.time, timeZone),
      setTimeZoneInOptions(f1.time || {}, timeZone)
    ),
  };
}

intl-messageformat

Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.

BSD-3-Clause
Latest version published 4 days ago

Package Health Score

100 / 100
Full package analysis