@internationalized/message
Advanced tools
Comparing version 3.0.4-nightly.3040 to 3.0.4-nightly.3047
194
dist/main.js
@@ -1,138 +0,104 @@ | ||
var _intlMessageformat = $parcel$interopDefault(require("intl-messageformat")); | ||
var $lHd5C$intlmessageformat = require("intl-messageformat"); | ||
var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends")); | ||
function $parcel$exportWildcard(dest, source) { | ||
Object.keys(source).forEach(function(key) { | ||
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) { | ||
return; | ||
} | ||
Object.defineProperty(dest, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return source[key]; | ||
} | ||
}); | ||
}); | ||
return dest; | ||
} | ||
function $parcel$export(e, n, v, s) { | ||
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); | ||
} | ||
function $parcel$interopDefault(a) { | ||
return a && a.__esModule ? a.default : a; | ||
} | ||
var $29fb5af3755ddf2a$exports = {}; | ||
/* | ||
* 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. | ||
*/ | ||
/** | ||
* Stores a mapping of localized strings. Can be used to find the | ||
* closest available string for a given locale. | ||
*/ | ||
class MessageDictionary { | ||
constructor(messages, defaultLocale) { | ||
if (defaultLocale === void 0) { | ||
defaultLocale = 'en-US'; | ||
$parcel$export($29fb5af3755ddf2a$exports, "MessageDictionary", () => $29fb5af3755ddf2a$export$64839e615120df17); | ||
class $29fb5af3755ddf2a$export$64839e615120df17 { | ||
constructor(messages, defaultLocale = 'en-US'){ | ||
// Clone messages so we don't modify the original object. | ||
this.messages = { | ||
...messages | ||
}; | ||
this.defaultLocale = defaultLocale; | ||
} | ||
this.messages = void 0; | ||
this.defaultLocale = void 0; | ||
// Clone messages so we don't modify the original object. | ||
this.messages = _babelRuntimeHelpersExtends({}, messages); | ||
this.defaultLocale = defaultLocale; | ||
} | ||
getStringForLocale(key, locale) { | ||
let strings = this.messages[locale]; | ||
if (!strings) { | ||
strings = $defc888dbd27849217e7ac080e7d$var$getStringsForLocale(locale, this.messages, this.defaultLocale); | ||
this.messages[locale] = strings; | ||
getStringForLocale(key, locale) { | ||
let strings = this.messages[locale]; | ||
if (!strings) { | ||
strings = $29fb5af3755ddf2a$var$getStringsForLocale(locale, this.messages, this.defaultLocale); | ||
this.messages[locale] = strings; | ||
} | ||
let string = strings[key]; | ||
if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`); | ||
return string; | ||
} | ||
let string = strings[key]; | ||
if (!string) { | ||
throw new Error("Could not find intl message " + key + " in " + locale + " locale"); | ||
} | ||
return string; | ||
} | ||
} | ||
exports.MessageDictionary = MessageDictionary; | ||
function $defc888dbd27849217e7ac080e7d$var$getStringsForLocale(locale, strings, defaultLocale) { | ||
if (defaultLocale === void 0) { | ||
defaultLocale = 'en-US'; | ||
} | ||
// If there is an exact match, use it. | ||
if (strings[locale]) { | ||
return strings[locale]; | ||
} // Attempt to find the closest match by language. | ||
// For example, if the locale is fr-CA (French Canadian), but there is only | ||
// an fr-FR (France) set of strings, use that. | ||
// This could be replaced with Intl.LocaleMatcher once it is supported. | ||
// https://github.com/tc39/proposal-intl-localematcher | ||
let language = $defc888dbd27849217e7ac080e7d$var$getLanguage(locale); | ||
for (let key in strings) { | ||
if (key.startsWith(language + '-')) { | ||
return strings[key]; | ||
function $29fb5af3755ddf2a$var$getStringsForLocale(locale, strings, defaultLocale = 'en-US') { | ||
// If there is an exact match, use it. | ||
if (strings[locale]) return strings[locale]; | ||
// Attempt to find the closest match by language. | ||
// For example, if the locale is fr-CA (French Canadian), but there is only | ||
// an fr-FR (France) set of strings, use that. | ||
// This could be replaced with Intl.LocaleMatcher once it is supported. | ||
// https://github.com/tc39/proposal-intl-localematcher | ||
let language = $29fb5af3755ddf2a$var$getLanguage(locale); | ||
for(let key in strings){ | ||
if (key.startsWith(language + '-')) return strings[key]; | ||
} | ||
} // Nothing close, use english. | ||
return strings[defaultLocale]; | ||
// Nothing close, use english. | ||
return strings[defaultLocale]; | ||
} | ||
function $defc888dbd27849217e7ac080e7d$var$getLanguage(locale) { | ||
// @ts-ignore | ||
if (Intl.Locale) { | ||
function $29fb5af3755ddf2a$var$getLanguage(locale) { | ||
// @ts-ignore | ||
if (Intl.Locale) // @ts-ignore | ||
return new Intl.Locale(locale).language; | ||
} | ||
return locale.split('-')[0]; | ||
return locale.split('-')[0]; | ||
} | ||
/** | ||
* Formats ICU Message strings to create localized strings from a MessageDictionary. | ||
*/ | ||
class MessageFormatter { | ||
constructor(locale, messages) { | ||
this.locale = void 0; | ||
this.messages = void 0; | ||
this.cache = void 0; | ||
this.locale = locale; | ||
this.messages = messages; | ||
this.cache = {}; | ||
} | ||
format(key, variables) { | ||
let message = this.cache[key]; | ||
var $dbb5799d8eb67295$exports = {}; | ||
if (!message) { | ||
let msg = this.messages.getStringForLocale(key, this.locale); | ||
$parcel$export($dbb5799d8eb67295$exports, "MessageFormatter", () => $dbb5799d8eb67295$export$526ebc05ff964723); | ||
if (!msg) { | ||
throw new Error("Could not find intl message " + key + " in " + this.locale + " locale"); | ||
} | ||
message = new _intlMessageformat(msg, this.locale); | ||
this.cache[key] = message; | ||
class $dbb5799d8eb67295$export$526ebc05ff964723 { | ||
constructor(locale, messages){ | ||
this.locale = locale; | ||
this.messages = messages; | ||
this.cache = { | ||
}; | ||
} | ||
format(key, variables) { | ||
let message = this.cache[key]; | ||
if (!message) { | ||
let msg = this.messages.getStringForLocale(key, this.locale); | ||
if (!msg) throw new Error(`Could not find intl message ${key} in ${this.locale} locale`); | ||
message = new ($parcel$interopDefault($lHd5C$intlmessageformat))(msg, this.locale); | ||
this.cache[key] = message; | ||
} | ||
let varCopy; | ||
if (variables) varCopy = Object.keys(variables).reduce((acc, key)=>{ | ||
acc[key] = variables[key] == null ? false : variables[key]; | ||
return acc; | ||
}, { | ||
}); | ||
return message.format(varCopy); | ||
} | ||
} | ||
let varCopy; | ||
if (variables) { | ||
varCopy = Object.keys(variables).reduce((acc, key) => { | ||
acc[key] = variables[key] == null ? false : variables[key]; | ||
return acc; | ||
}, {}); | ||
} | ||
$parcel$exportWildcard(module.exports, $29fb5af3755ddf2a$exports); | ||
$parcel$exportWildcard(module.exports, $dbb5799d8eb67295$exports); | ||
return message.format(varCopy); | ||
} | ||
} | ||
exports.MessageFormatter = MessageFormatter; | ||
//# sourceMappingURL=main.js.map |
@@ -1,129 +0,84 @@ | ||
import _intlMessageformat from "intl-messageformat"; | ||
import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends"; | ||
import $OrrLx$intlmessageformat from "intl-messageformat"; | ||
/* | ||
* 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. | ||
*/ | ||
function $parcel$export(e, n, v, s) { | ||
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); | ||
} | ||
var $66bb1da03ca047c3$exports = {}; | ||
/** | ||
* Stores a mapping of localized strings. Can be used to find the | ||
* closest available string for a given locale. | ||
*/ | ||
export class MessageDictionary { | ||
constructor(messages, defaultLocale) { | ||
if (defaultLocale === void 0) { | ||
defaultLocale = 'en-US'; | ||
$parcel$export($66bb1da03ca047c3$exports, "MessageDictionary", () => $66bb1da03ca047c3$export$64839e615120df17); | ||
class $66bb1da03ca047c3$export$64839e615120df17 { | ||
constructor(messages, defaultLocale = 'en-US'){ | ||
// Clone messages so we don't modify the original object. | ||
this.messages = { | ||
...messages | ||
}; | ||
this.defaultLocale = defaultLocale; | ||
} | ||
this.messages = void 0; | ||
this.defaultLocale = void 0; | ||
// Clone messages so we don't modify the original object. | ||
this.messages = _babelRuntimeHelpersEsmExtends({}, messages); | ||
this.defaultLocale = defaultLocale; | ||
} | ||
getStringForLocale(key, locale) { | ||
let strings = this.messages[locale]; | ||
if (!strings) { | ||
strings = $e73469445899f72bd9d935bbafe76d4$var$getStringsForLocale(locale, this.messages, this.defaultLocale); | ||
this.messages[locale] = strings; | ||
getStringForLocale(key, locale) { | ||
let strings = this.messages[locale]; | ||
if (!strings) { | ||
strings = $66bb1da03ca047c3$var$getStringsForLocale(locale, this.messages, this.defaultLocale); | ||
this.messages[locale] = strings; | ||
} | ||
let string = strings[key]; | ||
if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`); | ||
return string; | ||
} | ||
let string = strings[key]; | ||
if (!string) { | ||
throw new Error("Could not find intl message " + key + " in " + locale + " locale"); | ||
} | ||
return string; | ||
} | ||
} | ||
function $e73469445899f72bd9d935bbafe76d4$var$getStringsForLocale(locale, strings, defaultLocale) { | ||
if (defaultLocale === void 0) { | ||
defaultLocale = 'en-US'; | ||
} | ||
// If there is an exact match, use it. | ||
if (strings[locale]) { | ||
return strings[locale]; | ||
} // Attempt to find the closest match by language. | ||
// For example, if the locale is fr-CA (French Canadian), but there is only | ||
// an fr-FR (France) set of strings, use that. | ||
// This could be replaced with Intl.LocaleMatcher once it is supported. | ||
// https://github.com/tc39/proposal-intl-localematcher | ||
let language = $e73469445899f72bd9d935bbafe76d4$var$getLanguage(locale); | ||
for (let key in strings) { | ||
if (key.startsWith(language + '-')) { | ||
return strings[key]; | ||
function $66bb1da03ca047c3$var$getStringsForLocale(locale, strings, defaultLocale = 'en-US') { | ||
// If there is an exact match, use it. | ||
if (strings[locale]) return strings[locale]; | ||
// Attempt to find the closest match by language. | ||
// For example, if the locale is fr-CA (French Canadian), but there is only | ||
// an fr-FR (France) set of strings, use that. | ||
// This could be replaced with Intl.LocaleMatcher once it is supported. | ||
// https://github.com/tc39/proposal-intl-localematcher | ||
let language = $66bb1da03ca047c3$var$getLanguage(locale); | ||
for(let key in strings){ | ||
if (key.startsWith(language + '-')) return strings[key]; | ||
} | ||
} // Nothing close, use english. | ||
return strings[defaultLocale]; | ||
// Nothing close, use english. | ||
return strings[defaultLocale]; | ||
} | ||
function $e73469445899f72bd9d935bbafe76d4$var$getLanguage(locale) { | ||
// @ts-ignore | ||
if (Intl.Locale) { | ||
function $66bb1da03ca047c3$var$getLanguage(locale) { | ||
// @ts-ignore | ||
if (Intl.Locale) // @ts-ignore | ||
return new Intl.Locale(locale).language; | ||
} | ||
return locale.split('-')[0]; | ||
return locale.split('-')[0]; | ||
} | ||
/** | ||
* Formats ICU Message strings to create localized strings from a MessageDictionary. | ||
*/ | ||
export class MessageFormatter { | ||
constructor(locale, messages) { | ||
this.locale = void 0; | ||
this.messages = void 0; | ||
this.cache = void 0; | ||
this.locale = locale; | ||
this.messages = messages; | ||
this.cache = {}; | ||
} | ||
format(key, variables) { | ||
let message = this.cache[key]; | ||
var $2a9c3b8a3a59b7ef$exports = {}; | ||
if (!message) { | ||
let msg = this.messages.getStringForLocale(key, this.locale); | ||
$parcel$export($2a9c3b8a3a59b7ef$exports, "MessageFormatter", () => $2a9c3b8a3a59b7ef$export$526ebc05ff964723); | ||
if (!msg) { | ||
throw new Error("Could not find intl message " + key + " in " + this.locale + " locale"); | ||
} | ||
message = new _intlMessageformat(msg, this.locale); | ||
this.cache[key] = message; | ||
class $2a9c3b8a3a59b7ef$export$526ebc05ff964723 { | ||
constructor(locale, messages){ | ||
this.locale = locale; | ||
this.messages = messages; | ||
this.cache = { | ||
}; | ||
} | ||
format(key, variables) { | ||
let message = this.cache[key]; | ||
if (!message) { | ||
let msg = this.messages.getStringForLocale(key, this.locale); | ||
if (!msg) throw new Error(`Could not find intl message ${key} in ${this.locale} locale`); | ||
message = new $OrrLx$intlmessageformat(msg, this.locale); | ||
this.cache[key] = message; | ||
} | ||
let varCopy; | ||
if (variables) varCopy = Object.keys(variables).reduce((acc, key)=>{ | ||
acc[key] = variables[key] == null ? false : variables[key]; | ||
return acc; | ||
}, { | ||
}); | ||
return message.format(varCopy); | ||
} | ||
} | ||
let varCopy; | ||
if (variables) { | ||
varCopy = Object.keys(variables).reduce((acc, key) => { | ||
acc[key] = variables[key] == null ? false : variables[key]; | ||
return acc; | ||
}, {}); | ||
} | ||
return message.format(varCopy); | ||
} | ||
} | ||
export {$66bb1da03ca047c3$export$64839e615120df17 as MessageDictionary, $2a9c3b8a3a59b7ef$export$526ebc05ff964723 as MessageFormatter}; | ||
//# sourceMappingURL=module.js.map |
{ | ||
"name": "@internationalized/message", | ||
"version": "3.0.4-nightly.3040+e2b459ab9", | ||
"version": "3.0.4-nightly.3047+87960ad25", | ||
"description": "Internationalized message formatting and locale negotiation", | ||
@@ -26,3 +26,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "e2b459ab996abd06b0913942e9801b88493ed940" | ||
"gitHead": "87960ad25c26bc4cd6af506bb5e7e0f06621556c" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
42377
1
80
315