Socket
Socket
Sign inDemoInstall

@react-aria/i18n

Package Overview
Dependencies
Maintainers
1
Versions
767
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/i18n - npm Package Compare versions

Comparing version 3.0.0-rc.2 to 3.0.0-rc.3

dist/main.js.map

267

dist/main.js

@@ -0,1 +1,3 @@

var _intlMessageformat = $parcel$interopDefault(require("intl-messageformat"));
var _react2 = require("react");

@@ -5,10 +7,8 @@

var useContext = _react2.useContext;
var useEffect = _react2.useEffect;
var useState = _react2.useState;
var {
useEffect,
useState,
useContext
} = _react2;
var _babelRuntimeHelpersSlicedToArray = $parcel$interopDefault(require("@babel/runtime/helpers/slicedToArray"));
var _intlMessageformat = $parcel$interopDefault(require("intl-messageformat"));
function $parcel$interopDefault(a) {

@@ -18,22 +18,67 @@ return a && a.__esModule ? a.default : a;

function $e742a9645f33fbd785650baae63e$export$getDefaultLocale() {
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
// https://en.wikipedia.org/wiki/Right-to-left
const $dbb62b32f79d03a795a46f9fbec514c$var$RTL_SCRIPTS = new Set(['Arab', 'Syrc', 'Samr', 'Mand', 'Thaa', 'Mend', 'Nkoo', 'Adlm', 'Rohg', 'Hebr']);
const $dbb62b32f79d03a795a46f9fbec514c$var$RTL_LANGS = new Set(['ae', 'ar', 'arc', 'bcc', 'bqi', 'ckb', 'dv', 'fa', 'glk', 'he', 'ku', 'mzn', 'nqo', 'pnb', 'ps', 'sd', 'ug', 'ur', 'yi']);
function $dbb62b32f79d03a795a46f9fbec514c$export$isRTL(locale) {
// If the Intl.Locale API is available, use it to get the script for the locale.
// This is more accurate than guessing by language, since languages can be written in multiple scripts.
// @ts-ignore
return typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage) || 'en-US';
if (Intl.Locale) {
// @ts-ignore
let script = new Intl.Locale(locale).maximize().script;
return $dbb62b32f79d03a795a46f9fbec514c$var$RTL_SCRIPTS.has(script);
} // If not, just guess by the language (first part of the locale)
let lang = locale.split('-')[0];
return $dbb62b32f79d03a795a46f9fbec514c$var$RTL_LANGS.has(lang);
}
function $c53c7d716f930bd5da78e9efb99e3e$export$getDefaultLocale() {
// @ts-ignore
let locale = typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage) || 'en-US';
return {
locale,
direction: $dbb62b32f79d03a795a46f9fbec514c$export$isRTL(locale) ? 'rtl' : 'ltr'
};
}
let $c53c7d716f930bd5da78e9efb99e3e$var$currentLocale = $c53c7d716f930bd5da78e9efb99e3e$export$getDefaultLocale();
let $c53c7d716f930bd5da78e9efb99e3e$var$listeners = new Set();
function $c53c7d716f930bd5da78e9efb99e3e$var$updateLocale() {
$c53c7d716f930bd5da78e9efb99e3e$var$currentLocale = $c53c7d716f930bd5da78e9efb99e3e$export$getDefaultLocale();
for (let listener of $c53c7d716f930bd5da78e9efb99e3e$var$listeners) {
listener($c53c7d716f930bd5da78e9efb99e3e$var$currentLocale);
}
} // Returns the current browser/system language, and updates when it changes.
function $e742a9645f33fbd785650baae63e$export$useDefaultLocale() {
var _useState = useState($e742a9645f33fbd785650baae63e$export$getDefaultLocale()),
_useState2 = _babelRuntimeHelpersSlicedToArray(_useState, 2),
defaultLocale = _useState2[0],
setDefaultLocale = _useState2[1];
function $c53c7d716f930bd5da78e9efb99e3e$export$useDefaultLocale() {
let [defaultLocale, setDefaultLocale] = useState($c53c7d716f930bd5da78e9efb99e3e$var$currentLocale);
useEffect(() => {
if ($c53c7d716f930bd5da78e9efb99e3e$var$listeners.size === 0) {
window.addEventListener('languagechange', $c53c7d716f930bd5da78e9efb99e3e$var$updateLocale);
}
useEffect(function () {
var updateLocale = function updateLocale() {
setDefaultLocale($e742a9645f33fbd785650baae63e$export$getDefaultLocale());
};
$c53c7d716f930bd5da78e9efb99e3e$var$listeners.add(setDefaultLocale);
return () => {
$c53c7d716f930bd5da78e9efb99e3e$var$listeners.delete(setDefaultLocale);
window.addEventListener('languagechange', updateLocale);
return function () {
window.removeEventListener('languagechange', updateLocale);
if ($c53c7d716f930bd5da78e9efb99e3e$var$listeners.size === 0) {
window.removeEventListener('languagechange', $c53c7d716f930bd5da78e9efb99e3e$var$updateLocale);
}
};

@@ -44,21 +89,19 @@ }, []);

var $a34e7f3f5235bb4eb2df4880cecc26$var$I18nContext = _react.createContext({
locale: 'en-US',
direction: 'ltr'
});
const $aa95c2b730b505b265f124d9aec67193$var$I18nContext = _react.createContext(null);
/**
* Provides the locale for the application to all child components.
*/
function Provider(props) {
var locale = props.locale,
children = props.children;
var defaultLocale = $e742a9645f33fbd785650baae63e$export$useDefaultLocale();
if (!locale) {
locale = defaultLocale;
}
var value = {
locale: locale,
direction: $a34e7f3f5235bb4eb2df4880cecc26$var$isRTL(locale) ? 'rtl' : 'ltr'
};
return (/*#__PURE__*/_react.createElement($a34e7f3f5235bb4eb2df4880cecc26$var$I18nContext.Provider, {
function I18nProvider(props) {
let {
locale,
children
} = props;
let defaultLocale = $c53c7d716f930bd5da78e9efb99e3e$export$useDefaultLocale();
let value = locale ? {
locale,
direction: $dbb62b32f79d03a795a46f9fbec514c$export$isRTL(locale) ? 'rtl' : 'ltr'
} : defaultLocale;
return (/*#__PURE__*/_react.createElement($aa95c2b730b505b265f124d9aec67193$var$I18nContext.Provider, {
value: value

@@ -68,38 +111,30 @@ }, children)

}
/**
* Returns the current locale and layout direction.
*/
exports.Provider = Provider;
exports.I18nProvider = I18nProvider;
function useLocale() {
return useContext($a34e7f3f5235bb4eb2df4880cecc26$var$I18nContext);
} // https://en.wikipedia.org/wiki/Right-to-left
let defaultLocale = $c53c7d716f930bd5da78e9efb99e3e$export$useDefaultLocale();
let context = useContext($aa95c2b730b505b265f124d9aec67193$var$I18nContext);
return context || defaultLocale;
}
exports.useLocale = useLocale;
var $a34e7f3f5235bb4eb2df4880cecc26$var$RTL_SCRIPTS = new Set(['Arab', 'Syrc', 'Samr', 'Mand', 'Thaa', 'Mend', 'Nkoo', 'Adlm', 'Rohg', 'Hebr']);
var $a34e7f3f5235bb4eb2df4880cecc26$var$RTL_LANGS = new Set(['ae', 'ar', 'arc', 'bcc', 'bqi', 'ckb', 'dv', 'fa', 'glk', 'he', 'ku', 'mzn', 'nqo', 'pnb', 'ps', 'sd', 'ug', 'ur', 'yi']);
const $a5aefbc9b72193c190dce301e0eb39$var$formatterCache = new Map();
/**
* Handles formatting ICU Message strings to create localized strings for the current locale.
* Automatically updates when the locale changes, and handles caching of messages for performance.
* @param strings - a mapping of languages to strings by key
*/
function $a34e7f3f5235bb4eb2df4880cecc26$var$isRTL(locale) {
// If the Intl.Locale API is available, use it to get the script for the locale.
// This is more accurate than guessing by language, since languages can be written in multiple scripts.
// @ts-ignore
if (Intl.Locale) {
// @ts-ignore
var script = new Intl.Locale(locale).maximize().script;
return $a34e7f3f5235bb4eb2df4880cecc26$var$RTL_SCRIPTS.has(script);
} // If not, just guess by the language (first part of the locale)
var lang = locale.split('-')[0];
return $a34e7f3f5235bb4eb2df4880cecc26$var$RTL_LANGS.has(lang);
}
var $f548ef53bf293fb4b5dee223bd82e70a$var$formatterCache = new Map();
function useMessageFormatter(strings) {
var _useLocale = useLocale(),
currentLocale = _useLocale.locale; // Check the cache
let {
locale: currentLocale
} = useLocale(); // Check the cache
let localeCache = $a5aefbc9b72193c190dce301e0eb39$var$formatterCache.get(strings);
var localeCache = $f548ef53bf293fb4b5dee223bd82e70a$var$formatterCache.get(strings);
if (localeCache && localeCache.has(currentLocale)) {

@@ -112,21 +147,21 @@ return localeCache.get(currentLocale);

localeCache = new Map();
$f548ef53bf293fb4b5dee223bd82e70a$var$formatterCache.set(strings, localeCache);
$a5aefbc9b72193c190dce301e0eb39$var$formatterCache.set(strings, localeCache);
} // Get the strings for the current locale
var localeStrings = $f548ef53bf293fb4b5dee223bd82e70a$var$selectLocale(strings, currentLocale); // Create a new message formatter
let localeStrings = $a5aefbc9b72193c190dce301e0eb39$var$selectLocale(strings, currentLocale); // Create a new message formatter
var cache = {};
let cache = {};
var formatMessage = function formatMessage(key, variables, formats) {
var message = cache[key + '.' + currentLocale];
let formatMessage = (key, variables) => {
let message = cache[key + '.' + currentLocale];
if (!message) {
var msg = localeStrings[key];
let msg = localeStrings[key];
if (!msg) {
throw new Error("Could not find intl message ".concat(key, " in ").concat(currentLocale, " locale"));
throw new Error("Could not find intl message " + key + " in " + currentLocale + " locale");
}
message = new _intlMessageformat(msg, currentLocale, formats);
message = new _intlMessageformat(msg, currentLocale);
cache[key] = message;

@@ -144,3 +179,3 @@ }

function $f548ef53bf293fb4b5dee223bd82e70a$var$selectLocale(strings, locale) {
function $a5aefbc9b72193c190dce301e0eb39$var$selectLocale(strings, locale) {
// If there is an exact match, use it.

@@ -154,5 +189,5 @@ if (strings[locale]) {

var language = $f548ef53bf293fb4b5dee223bd82e70a$var$getLanguage(locale);
let language = $a5aefbc9b72193c190dce301e0eb39$var$getLanguage(locale);
for (var key in strings) {
for (let key in strings) {
if (key.startsWith(language + '-')) {

@@ -167,3 +202,3 @@ return strings[key];

function $f548ef53bf293fb4b5dee223bd82e70a$var$getLanguage(locale) {
function $a5aefbc9b72193c190dce301e0eb39$var$getLanguage(locale) {
// @ts-ignore

@@ -178,18 +213,21 @@ if (Intl.Locale) {

var $aaeb363b6aa03da8a97a316ff78529$var$formatterCache = new Map();
let $bdeee39f835a1e28966186127db96579$var$formatterCache = new Map();
/**
* Provides localized date formatting for the current locale. Automatically updates when the locale changes,
* and handles caching of the date formatter for performance.
* @param options - formatting options
*/
function useDateFormatter(options) {
var _useLocale = useLocale(),
locale = _useLocale.locale;
let {
locale
} = useLocale();
let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');
var cacheKey = locale + (options ? Object.entries(options).sort(function (a, b) {
return a[0] < b[0] ? -1 : 1;
}).join() : '');
if ($aaeb363b6aa03da8a97a316ff78529$var$formatterCache.has(cacheKey)) {
return $aaeb363b6aa03da8a97a316ff78529$var$formatterCache.get(cacheKey);
if ($bdeee39f835a1e28966186127db96579$var$formatterCache.has(cacheKey)) {
return $bdeee39f835a1e28966186127db96579$var$formatterCache.get(cacheKey);
}
var formatter = new Intl.DateTimeFormat(locale, options);
$aaeb363b6aa03da8a97a316ff78529$var$formatterCache.set(cacheKey, formatter);
let formatter = new Intl.DateTimeFormat(locale, options);
$bdeee39f835a1e28966186127db96579$var$formatterCache.set(cacheKey, formatter);
return formatter;

@@ -199,18 +237,21 @@ }

exports.useDateFormatter = useDateFormatter;
var $a1843970358d834976576c60b4708df$var$formatterCache = new Map();
let $fa77db1482937b6cdb6683d9d7eb896$var$formatterCache = new Map();
/**
* Provides localized number formatting for the current locale. Automatically updates when the locale changes,
* and handles caching of the number formatter for performance.
* @param options - formatting options
*/
function useNumberFormatter(options) {
var _useLocale = useLocale(),
locale = _useLocale.locale;
let {
locale
} = useLocale();
let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');
var cacheKey = locale + (options ? Object.entries(options).sort(function (a, b) {
return a[0] < b[0] ? -1 : 1;
}).join() : '');
if ($a1843970358d834976576c60b4708df$var$formatterCache.has(cacheKey)) {
return $a1843970358d834976576c60b4708df$var$formatterCache.get(cacheKey);
if ($fa77db1482937b6cdb6683d9d7eb896$var$formatterCache.has(cacheKey)) {
return $fa77db1482937b6cdb6683d9d7eb896$var$formatterCache.get(cacheKey);
}
var numberFormatter = new Intl.NumberFormat(locale, options);
$a1843970358d834976576c60b4708df$var$formatterCache.set(cacheKey, numberFormatter);
let numberFormatter = new Intl.NumberFormat(locale, options);
$fa77db1482937b6cdb6683d9d7eb896$var$formatterCache.set(cacheKey, numberFormatter);
return numberFormatter;

@@ -220,21 +261,25 @@ }

exports.useNumberFormatter = useNumberFormatter;
var $f6b91c1075a75eeb44c1e388$var$cache = new Map();
let $f2d7166fa8b4811bca7b68ebd673b$var$cache = new Map();
/**
* Provides localized string collation for the current locale. Automatically updates when the locale changes,
* and handles caching of the collator for performance.
* @param options - collator options
*/
function useCollator(options) {
var _useLocale = useLocale(),
locale = _useLocale.locale;
let {
locale
} = useLocale();
let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');
var cacheKey = locale + (options ? Object.entries(options).sort(function (a, b) {
return a[0] < b[0] ? -1 : 1;
}).join() : '');
if ($f6b91c1075a75eeb44c1e388$var$cache.has(cacheKey)) {
return $f6b91c1075a75eeb44c1e388$var$cache.get(cacheKey);
if ($f2d7166fa8b4811bca7b68ebd673b$var$cache.has(cacheKey)) {
return $f2d7166fa8b4811bca7b68ebd673b$var$cache.get(cacheKey);
}
var formatter = new Intl.Collator(locale, options);
$f6b91c1075a75eeb44c1e388$var$cache.set(cacheKey, formatter);
let formatter = new Intl.Collator(locale, options);
$f2d7166fa8b4811bca7b68ebd673b$var$cache.set(cacheKey, formatter);
return formatter;
}
exports.useCollator = useCollator;
exports.useCollator = useCollator;
//# sourceMappingURL=main.js.map

@@ -1,20 +0,69 @@

import _react, { useContext, useEffect, useState } from "react";
import _intlMessageformat from "intl-messageformat";
import _react, { useEffect, useState, useContext } from "react";
function $f64e833f1a7aba5469a82b2d5402655$export$getDefaultLocale() {
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
// https://en.wikipedia.org/wiki/Right-to-left
const $d26e725ad56fbcb2c25f52b7de27$var$RTL_SCRIPTS = new Set(['Arab', 'Syrc', 'Samr', 'Mand', 'Thaa', 'Mend', 'Nkoo', 'Adlm', 'Rohg', 'Hebr']);
const $d26e725ad56fbcb2c25f52b7de27$var$RTL_LANGS = new Set(['ae', 'ar', 'arc', 'bcc', 'bqi', 'ckb', 'dv', 'fa', 'glk', 'he', 'ku', 'mzn', 'nqo', 'pnb', 'ps', 'sd', 'ug', 'ur', 'yi']);
function $d26e725ad56fbcb2c25f52b7de27$export$isRTL(locale) {
// If the Intl.Locale API is available, use it to get the script for the locale.
// This is more accurate than guessing by language, since languages can be written in multiple scripts.
// @ts-ignore
return typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage) || 'en-US';
if (Intl.Locale) {
// @ts-ignore
let script = new Intl.Locale(locale).maximize().script;
return $d26e725ad56fbcb2c25f52b7de27$var$RTL_SCRIPTS.has(script);
} // If not, just guess by the language (first part of the locale)
let lang = locale.split('-')[0];
return $d26e725ad56fbcb2c25f52b7de27$var$RTL_LANGS.has(lang);
}
function $e851d0b81d46abd5f971c8e95c27f1$export$getDefaultLocale() {
// @ts-ignore
let locale = typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage) || 'en-US';
return {
locale,
direction: $d26e725ad56fbcb2c25f52b7de27$export$isRTL(locale) ? 'rtl' : 'ltr'
};
}
let $e851d0b81d46abd5f971c8e95c27f1$var$currentLocale = $e851d0b81d46abd5f971c8e95c27f1$export$getDefaultLocale();
let $e851d0b81d46abd5f971c8e95c27f1$var$listeners = new Set();
function $e851d0b81d46abd5f971c8e95c27f1$var$updateLocale() {
$e851d0b81d46abd5f971c8e95c27f1$var$currentLocale = $e851d0b81d46abd5f971c8e95c27f1$export$getDefaultLocale();
for (let listener of $e851d0b81d46abd5f971c8e95c27f1$var$listeners) {
listener($e851d0b81d46abd5f971c8e95c27f1$var$currentLocale);
}
} // Returns the current browser/system language, and updates when it changes.
function $f64e833f1a7aba5469a82b2d5402655$export$useDefaultLocale() {
let [defaultLocale, setDefaultLocale] = useState($f64e833f1a7aba5469a82b2d5402655$export$getDefaultLocale());
function $e851d0b81d46abd5f971c8e95c27f1$export$useDefaultLocale() {
let [defaultLocale, setDefaultLocale] = useState($e851d0b81d46abd5f971c8e95c27f1$var$currentLocale);
useEffect(() => {
let updateLocale = () => {
setDefaultLocale($f64e833f1a7aba5469a82b2d5402655$export$getDefaultLocale());
};
if ($e851d0b81d46abd5f971c8e95c27f1$var$listeners.size === 0) {
window.addEventListener('languagechange', $e851d0b81d46abd5f971c8e95c27f1$var$updateLocale);
}
window.addEventListener('languagechange', updateLocale);
$e851d0b81d46abd5f971c8e95c27f1$var$listeners.add(setDefaultLocale);
return () => {
window.removeEventListener('languagechange', updateLocale);
$e851d0b81d46abd5f971c8e95c27f1$var$listeners.delete(setDefaultLocale);
if ($e851d0b81d46abd5f971c8e95c27f1$var$listeners.size === 0) {
window.removeEventListener('languagechange', $e851d0b81d46abd5f971c8e95c27f1$var$updateLocale);
}
};

@@ -25,8 +74,9 @@ }, []);

const $b8b17a145b8bd39565e2a94d2f48852$var$I18nContext = _react.createContext({
locale: 'en-US',
direction: 'ltr'
});
const $cff8541df3b5c83067b2ab3ee0d20$var$I18nContext = _react.createContext(null);
/**
* Provides the locale for the application to all child components.
*/
export function Provider(props) {
export function I18nProvider(props) {
let {

@@ -36,13 +86,8 @@ locale,

} = props;
let defaultLocale = $f64e833f1a7aba5469a82b2d5402655$export$useDefaultLocale();
if (!locale) {
locale = defaultLocale;
}
let value = {
let defaultLocale = $e851d0b81d46abd5f971c8e95c27f1$export$useDefaultLocale();
let value = locale ? {
locale,
direction: $b8b17a145b8bd39565e2a94d2f48852$var$isRTL(locale) ? 'rtl' : 'ltr'
};
return (/*#__PURE__*/_react.createElement($b8b17a145b8bd39565e2a94d2f48852$var$I18nContext.Provider, {
direction: $d26e725ad56fbcb2c25f52b7de27$export$isRTL(locale) ? 'rtl' : 'ltr'
} : defaultLocale;
return (/*#__PURE__*/_react.createElement($cff8541df3b5c83067b2ab3ee0d20$var$I18nContext.Provider, {
value: value

@@ -52,25 +97,18 @@ }, children)

}
/**
* Returns the current locale and layout direction.
*/
export function useLocale() {
return useContext($b8b17a145b8bd39565e2a94d2f48852$var$I18nContext);
} // https://en.wikipedia.org/wiki/Right-to-left
const $b8b17a145b8bd39565e2a94d2f48852$var$RTL_SCRIPTS = new Set(['Arab', 'Syrc', 'Samr', 'Mand', 'Thaa', 'Mend', 'Nkoo', 'Adlm', 'Rohg', 'Hebr']);
const $b8b17a145b8bd39565e2a94d2f48852$var$RTL_LANGS = new Set(['ae', 'ar', 'arc', 'bcc', 'bqi', 'ckb', 'dv', 'fa', 'glk', 'he', 'ku', 'mzn', 'nqo', 'pnb', 'ps', 'sd', 'ug', 'ur', 'yi']);
function $b8b17a145b8bd39565e2a94d2f48852$var$isRTL(locale) {
// If the Intl.Locale API is available, use it to get the script for the locale.
// This is more accurate than guessing by language, since languages can be written in multiple scripts.
// @ts-ignore
if (Intl.Locale) {
// @ts-ignore
let script = new Intl.Locale(locale).maximize().script;
return $b8b17a145b8bd39565e2a94d2f48852$var$RTL_SCRIPTS.has(script);
} // If not, just guess by the language (first part of the locale)
let lang = locale.split('-')[0];
return $b8b17a145b8bd39565e2a94d2f48852$var$RTL_LANGS.has(lang);
let defaultLocale = $e851d0b81d46abd5f971c8e95c27f1$export$useDefaultLocale();
let context = useContext($cff8541df3b5c83067b2ab3ee0d20$var$I18nContext);
return context || defaultLocale;
}
const $f58d206cee90f9c2bf3c03e4522c35$var$formatterCache = new Map();
/**
* Handles formatting ICU Message strings to create localized strings for the current locale.
* Automatically updates when the locale changes, and handles caching of messages for performance.
* @param strings - a mapping of languages to strings by key
*/
const $f15dbd0a2c43e9fd57565b379ec1738$var$formatterCache = new Map();
export function useMessageFormatter(strings) {

@@ -81,3 +119,3 @@ let {

let localeCache = $f15dbd0a2c43e9fd57565b379ec1738$var$formatterCache.get(strings);
let localeCache = $f58d206cee90f9c2bf3c03e4522c35$var$formatterCache.get(strings);

@@ -91,11 +129,11 @@ if (localeCache && localeCache.has(currentLocale)) {

localeCache = new Map();
$f15dbd0a2c43e9fd57565b379ec1738$var$formatterCache.set(strings, localeCache);
$f58d206cee90f9c2bf3c03e4522c35$var$formatterCache.set(strings, localeCache);
} // Get the strings for the current locale
let localeStrings = $f15dbd0a2c43e9fd57565b379ec1738$var$selectLocale(strings, currentLocale); // Create a new message formatter
let localeStrings = $f58d206cee90f9c2bf3c03e4522c35$var$selectLocale(strings, currentLocale); // Create a new message formatter
let cache = {};
let formatMessage = (key, variables, formats) => {
let formatMessage = (key, variables) => {
let message = cache[key + '.' + currentLocale];

@@ -107,6 +145,6 @@

if (!msg) {
throw new Error("Could not find intl message ".concat(key, " in ").concat(currentLocale, " locale"));
throw new Error("Could not find intl message " + key + " in " + currentLocale + " locale");
}
message = new _intlMessageformat(msg, currentLocale, formats);
message = new _intlMessageformat(msg, currentLocale);
cache[key] = message;

@@ -122,3 +160,3 @@ }

function $f15dbd0a2c43e9fd57565b379ec1738$var$selectLocale(strings, locale) {
function $f58d206cee90f9c2bf3c03e4522c35$var$selectLocale(strings, locale) {
// If there is an exact match, use it.

@@ -132,3 +170,3 @@ if (strings[locale]) {

let language = $f15dbd0a2c43e9fd57565b379ec1738$var$getLanguage(locale);
let language = $f58d206cee90f9c2bf3c03e4522c35$var$getLanguage(locale);

@@ -145,3 +183,3 @@ for (let key in strings) {

function $f15dbd0a2c43e9fd57565b379ec1738$var$getLanguage(locale) {
function $f58d206cee90f9c2bf3c03e4522c35$var$getLanguage(locale) {
// @ts-ignore

@@ -156,3 +194,9 @@ if (Intl.Locale) {

let $aba9d79335df5c45bb681630807272a2$var$formatterCache = new Map();
let $b0007c63a64054c318efb8b6cd0053f$var$formatterCache = new Map();
/**
* Provides localized date formatting for the current locale. Automatically updates when the locale changes,
* and handles caching of the date formatter for performance.
* @param options - formatting options
*/
export function useDateFormatter(options) {

@@ -164,11 +208,17 @@ let {

if ($aba9d79335df5c45bb681630807272a2$var$formatterCache.has(cacheKey)) {
return $aba9d79335df5c45bb681630807272a2$var$formatterCache.get(cacheKey);
if ($b0007c63a64054c318efb8b6cd0053f$var$formatterCache.has(cacheKey)) {
return $b0007c63a64054c318efb8b6cd0053f$var$formatterCache.get(cacheKey);
}
let formatter = new Intl.DateTimeFormat(locale, options);
$aba9d79335df5c45bb681630807272a2$var$formatterCache.set(cacheKey, formatter);
$b0007c63a64054c318efb8b6cd0053f$var$formatterCache.set(cacheKey, formatter);
return formatter;
}
let $fc1e067f8521660d23904b831e43d70e$var$formatterCache = new Map();
let $ece3e138e83d330f42860705a2ec18a$var$formatterCache = new Map();
/**
* Provides localized number formatting for the current locale. Automatically updates when the locale changes,
* and handles caching of the number formatter for performance.
* @param options - formatting options
*/
export function useNumberFormatter(options) {

@@ -180,11 +230,17 @@ let {

if ($fc1e067f8521660d23904b831e43d70e$var$formatterCache.has(cacheKey)) {
return $fc1e067f8521660d23904b831e43d70e$var$formatterCache.get(cacheKey);
if ($ece3e138e83d330f42860705a2ec18a$var$formatterCache.has(cacheKey)) {
return $ece3e138e83d330f42860705a2ec18a$var$formatterCache.get(cacheKey);
}
let numberFormatter = new Intl.NumberFormat(locale, options);
$fc1e067f8521660d23904b831e43d70e$var$formatterCache.set(cacheKey, numberFormatter);
$ece3e138e83d330f42860705a2ec18a$var$formatterCache.set(cacheKey, numberFormatter);
return numberFormatter;
}
let $a945ed74e7f548aadf4fbe063431e7ff$var$cache = new Map();
let $a4045a18d7252bf6de9312e613c4e$var$cache = new Map();
/**
* Provides localized string collation for the current locale. Automatically updates when the locale changes,
* and handles caching of the collator for performance.
* @param options - collator options
*/
export function useCollator(options) {

@@ -196,9 +252,10 @@ let {

if ($a945ed74e7f548aadf4fbe063431e7ff$var$cache.has(cacheKey)) {
return $a945ed74e7f548aadf4fbe063431e7ff$var$cache.get(cacheKey);
if ($a4045a18d7252bf6de9312e613c4e$var$cache.has(cacheKey)) {
return $a4045a18d7252bf6de9312e613c4e$var$cache.get(cacheKey);
}
let formatter = new Intl.Collator(locale, options);
$a945ed74e7f548aadf4fbe063431e7ff$var$cache.set(cacheKey, formatter);
$a4045a18d7252bf6de9312e613c4e$var$cache.set(cacheKey, formatter);
return formatter;
}
}
//# sourceMappingURL=module.js.map
import { Direction } from "@react-types/shared";
import { ReactNode } from "react";
interface Locale {
/** The [BCP47](https://www.ietf.org/rfc/bcp/bcp47.txt) language code for the locale. */
locale: string;
/** The writing direction for the locale. */
direction: Direction;
}
interface ProviderProps {
/** Contents that should have the locale applied. */
children: ReactNode;
/** The locale to apply to the children. */
locale?: string;
children: ReactNode;
}
interface LocaleContext {
locale: string;
direction: Direction;
}
export function Provider(props: ProviderProps): JSX.Element;
export function useLocale(): LocaleContext;
export function useMessageFormatter(strings: any): any;
/**
* Provides the locale for the application to all child components.
*/
export function I18nProvider(props: ProviderProps): JSX.Element;
/**
* Returns the current locale and layout direction.
*/
export function useLocale(): Locale;
type MessageFormatterStrings = {
[lang: string]: {
[key: string]: string;
};
};
type FormatMessage = (key: string, variables?: {
[key: string]: any;
}) => string;
/**
* Handles formatting ICU Message strings to create localized strings for the current locale.
* Automatically updates when the locale changes, and handles caching of messages for performance.
* @param strings - a mapping of languages to strings by key
*/
export function useMessageFormatter(strings: MessageFormatterStrings): FormatMessage;
/**
* Provides localized date formatting for the current locale. Automatically updates when the locale changes,
* and handles caching of the date formatter for performance.
* @param options - formatting options
*/
export function useDateFormatter(options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat;
/**
* Provides localized number formatting for the current locale. Automatically updates when the locale changes,
* and handles caching of the number formatter for performance.
* @param options - formatting options
*/
export function useNumberFormatter(options?: Intl.NumberFormatOptions): Intl.NumberFormat;
/**
* Provides localized string collation for the current locale. Automatically updates when the locale changes,
* and handles caching of the collator for performance.
* @param options - collator options
*/
export function useCollator(options?: Intl.CollatorOptions): Intl.Collator;
//# sourceMappingURL=types.d.ts.map
{
"name": "@react-aria/i18n",
"version": "3.0.0-rc.2",
"version": "3.0.0-rc.3",
"description": "Spectrum UI components in React",

@@ -20,3 +20,3 @@ "license": "Apache-2.0",

"@babel/runtime": "^7.6.2",
"@react-types/shared": "^3.0.0-rc.2",
"@react-types/shared": "3.0.0-rc.3",
"intl-messageformat": "^2.2.0"

@@ -30,3 +30,3 @@ },

},
"gitHead": "207e6ee9076905c96638a7f81a367758872e1410"
"gitHead": "461d6321126ae9b4f1508aa912f7b36bf8a603f8"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc