How to use intl-locales-supported - 10 common examples

To help you get started, we’ve selected a few intl-locales-supported 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 mozilla / addons-frontend / tests / setup.js View on Github external
key(index) {
    const keys = Object.keys(this.store);
    return keys[index] || null;
  }

  get length() {
    return Object.keys(this.store).length;
  }
}
global.localStorage = new LocalStorageMock();

const localesMyAppSupports = ['de', 'fr'];

if (global.Intl) {
  // Determine if the built-in `Intl` has the locale data we need.
  if (!areIntlLocalesSupported(localesMyAppSupports)) {
    // `Intl` exists, but it doesn't have the data we need, so load the
    // polyfill and patch the constructors we need with the polyfill's.
    // eslint-disable-next-line global-require
    const IntlPolyfill = require('intl');
    Intl.NumberFormat = IntlPolyfill.NumberFormat;
    Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
  }
} else {
  // No `Intl`, so use and load the polyfill.
  // eslint-disable-next-line global-require
  global.Intl = require('intl');
}

// Patch missing console.debug in node.
// eslint-disable-next-line no-console
console.debug = console.log;
github sebastian-software / edge / packages / edge-core / src / common / Intl.js View on Github external
export function requiresIntlPolyfill(locale) {
  // Determine if the built-in `Intl` has the locale data we need.
  if (PREFER_NATIVE && global.Intl && areIntlLocalesSupported([ locale ])) {
    return false
  }

  // By default Node only ships with basic English locale data. You can however build a
  // Node binary with all locale data. We recommend doing this if you control the container
  // your Node app runs in, otherwise you'll want to polyfill Intl in Node.
  // Via: https://github.com/yahoo/react-intl/wiki#i18n-in-javascript
  if (PREFER_NATIVE === false && process.env.TARGET === "node")
  {
    /* eslint-disable no-console */
    console.warn("Your NodeJS installation does not include full ICU locale data! Fallback to polyfill!")
    console.warn("See also: https://github.com/nodejs/node/wiki/Intl")
  }

  return true
}
github slidewiki / slidewiki-platform / client.js View on Github external
function loadLocaleData(locale) {
    const hasIntl = isIntlLocaleSupported(locale);

    // Make sure ReactIntl is in the global scope: this is required for adding locale-data
    // Since ReactIntl needs the `Intl` polyfill to be required (sic) we must place
    // this require here, when loadIntlPolyfill is supposed to be present
    //require('expose?ReactIntl!react-intl');

    return new Promise( (resolve) => {

        switch (locale) {

            // english
            case 'en':

                if (!hasIntl) {

                    require.ensure([
github sebastian-software / vue-locale / src / VueLocale.js View on Github external
*/

import IntlMessageFormat from "intl-messageformat"
import IntlRelativeFormat from "intl-relativeformat"
import areLocalesSupported from "intl-locales-supported"

import createFormatCache from "intl-format-cache"

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
github catamphetamine / webapp / frontend / code / international / loader.js View on Github external
function load_intl_polyfill(locale)
{
	if (window.Intl && is_intl_locale_supported(locale))
	{
		// `Intl` is in the global scope and the locale data is available
		return Promise.resolve()
	}

	debug(`Intl${window.Intl ? ' locale data' : ''} for "${locale}" not available, downloading the polyfill...`)

	return Promise.all
	([
		import(/* webpackChunkName: "intl" */ 'intl'),
		load_language_specific_intl_data(locale)
	])
}
github ch-apptitude / goomi / project-base / src / server / serverIntlPolyfill.js View on Github external
import areIntlLocalesSupported from 'intl-locales-supported';

import config from 'appConfig';

if (global.Intl) {
  // Determine if the built-in `Intl` has the locale data we need.
  if (!areIntlLocalesSupported(config.locale)) {
    // `Intl` exists, but it doesn't have the data we need, so load the
    // polyfill and replace the constructors with need with the polyfill's.
    const IntlPolyfill = require('intl'); // eslint-disable-line global-require

    Intl.NumberFormat = IntlPolyfill.NumberFormat;
    Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
  }
} else {
  // No `Intl`, so use and load the polyfill.
  global.Intl = require('intl'); // eslint-disable-line global-require
}
github catamphetamine / webapp / code / page-server / main.js View on Github external
preferred_locales.push(preferred_locale)
		preferred_locales.push('en-US')

		// Choose an appropriate locale and load the corresponding messages 
		// (prefer locales from the `preferred_locales` list)
		let { locale, messages } = await load_locale_data(preferred_locales, { force_reload: _development_ })

		// Store the locale in Redux store
		store.dispatch({ type: 'locale', locale })

		// Check if the Intl object supports the chosen locale.
		// If not then load Intl polyfill instead.
		if (global.Intl)
		{
			// Determine if the built-in `Intl` has the locale data we need.
			if (!is_intl_locale_supported(locale))
			{
				// `Intl` exists, but it doesn't have the data we need, so load the
				// polyfill and patch the constructors we need with the polyfill's.
				const Intl_polyfill = require('intl')
				Intl.NumberFormat   = Intl_polyfill.NumberFormat
				Intl.DateTimeFormat = Intl_polyfill.DateTimeFormat
			}
		}
		else
		{
			// No `Intl`, so use and load the polyfill.
			global.Intl = require('intl')
		}

		// These variables will be passed down 
		// as `props` for the `markup_wrapper` React component
github meedan / check-web / src / app / components / task / DatetimeRespondTask.js View on Github external
}
          primary
          onClick={this.handlePressButton.bind(this)}
          disabled={this.state.taskAnswerDisabled}
        />
      <p></p>
    );

    const locale = this.getLocale();
    let DateTimeFormat;

    if (areIntlLocalesSupported(['en', 'pt', 'ar', 'fr'])) {
      ({ DateTimeFormat } = global.Intl.DateTimeFormat);
    } else {
      ({ DateTimeFormat } = IntlPolyfill.DateTimeFormat);
      require('intl/locale-data/jsonp/pt'); // eslint-disable-line global-require
      require('intl/locale-data/jsonp/en'); // eslint-disable-line global-require
      require('intl/locale-data/jsonp/ar'); // eslint-disable-line global-require
      require('intl/locale-data/jsonp/fr'); // eslint-disable-line global-require
      require('intl/locale-data/jsonp/es'); // eslint-disable-line global-require
    }

    return (
      <div>
        
          
          </div>
github catamphetamine / webapp / code / client / international / loader.js View on Github external
load_polyfill(locale)
	{
		if (window.Intl && is_intl_locale_supported(locale))
		{
			// all fine: Intl is in the global scope and the locale data is available
			return Promise.resolve()
		}

		return new Promise((resolve) =>
		{
			debug(`Intl or locale data for "${locale}" not available, downloading the polyfill...`)

			// When building: create a intl chunk with webpack
			// When executing: run the callback once the chunk has been download.
			require.ensure(['intl'], (require) =>
			{
				// apply the polyfill
				require('intl')
				debug(`Intl polyfill for "${locale}" has been loaded`)
github nuitcoder / neubbs / src / main / webapp / src / utils / intl.js View on Github external
export const polyfill = () => {
  const context = (typeof window !== 'undefined' && window) || global

  if (!context.Intl || !areIntlLocalesSupported(locales)) {
    if (!context.Intl) {
      context.Intl = intl
    } else if (!areIntlLocalesSupported) {
      context.Intl.NumberFormat = intl.NumberFormat
      context.Intl.DateTimeFormat = intl.DateTimeFormat
    }
  }
}

intl-locales-supported

Utility to help you polyfill the Node.js runtime when the Intl APIs are missing, or if the built-in Intl is missing locale data that you need.

BSD-3-Clause
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis

Popular intl-locales-supported functions