@internationalized/string 3.2.2-nightly.4552 → 3.2.2-nightly.4558

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+
2
+ function $parcel$export(e, n, v, s) {
3
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
+ }
5
+
6
+ $parcel$export(module.exports, "LocalizedStringDictionary", () => $f80be5fd4d03dda9$export$c17fa47878dc55b6);
7
+ /*
8
+ * Copyright 2022 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */ const $f80be5fd4d03dda9$var$localeSymbol = Symbol.for("react-aria.i18n.locale");
18
+ const $f80be5fd4d03dda9$var$stringsSymbol = Symbol.for("react-aria.i18n.strings");
19
+ let $f80be5fd4d03dda9$var$cachedGlobalStrings = undefined;
20
+ class $f80be5fd4d03dda9$export$c17fa47878dc55b6 {
21
+ /** Returns a localized string for the given key and locale. */ getStringForLocale(key, locale) {
22
+ let strings = this.getStringsForLocale(locale);
23
+ let string = strings[key];
24
+ if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
25
+ return string;
26
+ }
27
+ /** Returns all localized strings for the given locale. */ getStringsForLocale(locale) {
28
+ let strings = this.strings[locale];
29
+ if (!strings) {
30
+ strings = $f80be5fd4d03dda9$var$getStringsForLocale(locale, this.strings, this.defaultLocale);
31
+ this.strings[locale] = strings;
32
+ }
33
+ return strings;
34
+ }
35
+ static getGlobalDictionaryForPackage(packageName) {
36
+ if (typeof window === "undefined") return null;
37
+ let locale = window[$f80be5fd4d03dda9$var$localeSymbol];
38
+ if ($f80be5fd4d03dda9$var$cachedGlobalStrings === undefined) {
39
+ let globalStrings = window[$f80be5fd4d03dda9$var$stringsSymbol];
40
+ if (!globalStrings) return null;
41
+ $f80be5fd4d03dda9$var$cachedGlobalStrings = {};
42
+ for(let pkg in globalStrings)$f80be5fd4d03dda9$var$cachedGlobalStrings[pkg] = new $f80be5fd4d03dda9$export$c17fa47878dc55b6({
43
+ [locale]: globalStrings[pkg]
44
+ }, locale);
45
+ }
46
+ let dictionary = $f80be5fd4d03dda9$var$cachedGlobalStrings === null || $f80be5fd4d03dda9$var$cachedGlobalStrings === void 0 ? void 0 : $f80be5fd4d03dda9$var$cachedGlobalStrings[packageName];
47
+ if (!dictionary) throw new Error(`Strings for package "${packageName}" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`);
48
+ return dictionary;
49
+ }
50
+ constructor(messages, defaultLocale = "en-US"){
51
+ // Clone messages so we don't modify the original object.
52
+ // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
53
+ this.strings = Object.fromEntries(Object.entries(messages).filter(([, v])=>v));
54
+ this.defaultLocale = defaultLocale;
55
+ }
56
+ }
57
+ function $f80be5fd4d03dda9$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
58
+ // If there is an exact match, use it.
59
+ if (strings[locale]) return strings[locale];
60
+ // Attempt to find the closest match by language.
61
+ // For example, if the locale is fr-CA (French Canadian), but there is only
62
+ // an fr-FR (France) set of strings, use that.
63
+ // This could be replaced with Intl.LocaleMatcher once it is supported.
64
+ // https://github.com/tc39/proposal-intl-localematcher
65
+ let language = $f80be5fd4d03dda9$var$getLanguage(locale);
66
+ if (strings[language]) return strings[language];
67
+ for(let key in strings){
68
+ if (key.startsWith(language + "-")) return strings[key];
69
+ }
70
+ // Nothing close, use english.
71
+ return strings[defaultLocale];
72
+ }
73
+ function $f80be5fd4d03dda9$var$getLanguage(locale) {
74
+ // @ts-ignore
75
+ if (Intl.Locale) // @ts-ignore
76
+ return new Intl.Locale(locale).language;
77
+ return locale.split("-")[0];
78
+ }
79
+
80
+
81
+ //# sourceMappingURL=LocalizedStringDictionary.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAQD,MAAM,qCAAe,OAAO,GAAG,CAAC;AAChC,MAAM,sCAAgB,OAAO,GAAG,CAAC;AACjC,IAAI,4CAAuG;AAMpG,MAAM;IAaX,6DAA6D,GAC7D,mBAAmB,GAAM,EAAE,MAAc,EAAK;QAC5C,IAAI,UAAU,IAAI,CAAC,mBAAmB,CAAC;QACvC,IAAI,SAAS,OAAO,CAAC,IAAI;QACzB,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,OAAO,OAAO,CAAC;QAG1E,OAAO;IACT;IAEA,wDAAwD,GACxD,oBAAoB,MAAc,EAAgB;QAChD,IAAI,UAAU,IAAI,CAAC,OAAO,CAAC,OAAO;QAClC,IAAI,CAAC,SAAS;YACZ,UAAU,0CAAoB,QAAQ,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa;YACtE,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG;QACzB;QAEA,OAAO;IACT;IAEA,OAAO,8BAA6F,WAAmB,EAA0C;QAC/J,IAAI,OAAO,WAAW,aACpB,OAAO;QAGT,IAAI,SAAS,MAAM,CAAC,mCAAa;QACjC,IAAI,8CAAwB,WAAW;YACrC,IAAI,gBAAgB,MAAM,CAAC,oCAAc;YACzC,IAAI,CAAC,eACH,OAAO;YAGT,4CAAsB,CAAC;YACvB,IAAK,IAAI,OAAO,cACd,yCAAmB,CAAC,IAAI,GAAG,IAAI,0CAA0B;gBAAC,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI;YAAA,GAAG;QAE7F;QAEA,IAAI,aAAa,sDAAA,gEAAA,yCAAqB,CAAC,YAAY;QACnD,IAAI,CAAC,YACH,MAAM,IAAI,MAAM,CAAC,qBAAqB,EAAE,YAAY,oHAAoH,CAAC;QAG3K,OAAO;IACT;IAvDA,YAAY,QAAgC,EAAE,gBAAwB,OAAO,CAAE;QAC7E,yDAAyD;QACzD,uGAAuG;QACvG,IAAI,CAAC,OAAO,GAAG,OAAO,WAAW,CAC/B,OAAO,OAAO,CAAC,UAAU,MAAM,CAAC,CAAC,GAAG,EAAE,GAAK;QAE7C,IAAI,CAAC,aAAa,GAAG;IACvB;AAiDF;AAEA,SAAS,0CAAiE,MAAc,EAAE,OAA+B,EAAE,gBAAgB,OAAO;IAChJ,sCAAsC;IACtC,IAAI,OAAO,CAAC,OAAO,EACjB,OAAO,OAAO,CAAC,OAAO;IAGxB,iDAAiD;IACjD,2EAA2E;IAC3E,8CAA8C;IAC9C,uEAAuE;IACvE,sDAAsD;IACtD,IAAI,WAAW,kCAAY;IAC3B,IAAI,OAAO,CAAC,SAAS,EACnB,OAAO,OAAO,CAAC,SAAS;IAG1B,IAAK,IAAI,OAAO,QAAS;QACvB,IAAI,IAAI,UAAU,CAAC,WAAW,MAC5B,OAAO,OAAO,CAAC,IAAI;IAEvB;IAEA,8BAA8B;IAC9B,OAAO,OAAO,CAAC,cAAc;AAC/B;AAEA,SAAS,kCAAY,MAAc;IACjC,aAAa;IACb,IAAI,KAAK,MAAM,EACb,aAAa;IACb,OAAO,IAAI,KAAK,MAAM,CAAC,QAAQ,QAAQ;IAGzC,OAAO,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE;AAC7B","sources":["packages/@internationalized/string/src/LocalizedStringDictionary.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedString} from './LocalizedStringFormatter';\n\nexport type LocalizedStrings<K extends string, T extends LocalizedString> = {\n [lang: string]: Record<K, T>\n};\n\nconst localeSymbol = Symbol.for('react-aria.i18n.locale');\nconst stringsSymbol = Symbol.for('react-aria.i18n.strings');\nlet cachedGlobalStrings: {[packageName: string]: LocalizedStringDictionary<any, any>} | null | undefined = undefined;\n\n/**\n * Stores a mapping of localized strings. Can be used to find the\n * closest available string for a given locale.\n */\nexport class LocalizedStringDictionary<K extends string = string, T extends LocalizedString = string> {\n private strings: LocalizedStrings<K, T>;\n private defaultLocale: string;\n\n constructor(messages: LocalizedStrings<K, T>, defaultLocale: string = 'en-US') {\n // Clone messages so we don't modify the original object.\n // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.\n this.strings = Object.fromEntries(\n Object.entries(messages).filter(([, v]) => v)\n );\n this.defaultLocale = defaultLocale;\n }\n\n /** Returns a localized string for the given key and locale. */\n getStringForLocale(key: K, locale: string): T {\n let strings = this.getStringsForLocale(locale);\n let string = strings[key];\n if (!string) {\n throw new Error(`Could not find intl message ${key} in ${locale} locale`);\n }\n\n return string;\n }\n\n /** Returns all localized strings for the given locale. */\n getStringsForLocale(locale: string): Record<K, T> {\n let strings = this.strings[locale];\n if (!strings) {\n strings = getStringsForLocale(locale, this.strings, this.defaultLocale);\n this.strings[locale] = strings;\n }\n\n return strings;\n }\n\n static getGlobalDictionaryForPackage<K extends string = string, T extends LocalizedString = string>(packageName: string): LocalizedStringDictionary<K, T> | null {\n if (typeof window === 'undefined') {\n return null;\n }\n\n let locale = window[localeSymbol];\n if (cachedGlobalStrings === undefined) {\n let globalStrings = window[stringsSymbol];\n if (!globalStrings) {\n return null;\n }\n\n cachedGlobalStrings = {};\n for (let pkg in globalStrings) {\n cachedGlobalStrings[pkg] = new LocalizedStringDictionary({[locale]: globalStrings[pkg]}, locale);\n }\n }\n\n let dictionary = cachedGlobalStrings?.[packageName];\n if (!dictionary) {\n throw new Error(`Strings for package \"${packageName}\" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`);\n }\n\n return dictionary;\n }\n}\n\nfunction getStringsForLocale<K extends string, T extends LocalizedString>(locale: string, strings: LocalizedStrings<K, T>, defaultLocale = 'en-US') {\n // If there is an exact match, use it.\n if (strings[locale]) {\n return strings[locale];\n }\n\n // Attempt to find the closest match by language.\n // For example, if the locale is fr-CA (French Canadian), but there is only\n // an fr-FR (France) set of strings, use that.\n // This could be replaced with Intl.LocaleMatcher once it is supported.\n // https://github.com/tc39/proposal-intl-localematcher\n let language = getLanguage(locale);\n if (strings[language]) {\n return strings[language];\n }\n\n for (let key in strings) {\n if (key.startsWith(language + '-')) {\n return strings[key];\n }\n }\n\n // Nothing close, use english.\n return strings[defaultLocale];\n}\n\nfunction getLanguage(locale: string) {\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n return new Intl.Locale(locale).language;\n }\n\n return locale.split('-')[0];\n}\n"],"names":[],"version":3,"file":"LocalizedStringDictionary.main.js.map"}
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright 2022 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ const $5b160d28a433310d$var$localeSymbol = Symbol.for("react-aria.i18n.locale");
12
+ const $5b160d28a433310d$var$stringsSymbol = Symbol.for("react-aria.i18n.strings");
13
+ let $5b160d28a433310d$var$cachedGlobalStrings = undefined;
14
+ class $5b160d28a433310d$export$c17fa47878dc55b6 {
15
+ /** Returns a localized string for the given key and locale. */ getStringForLocale(key, locale) {
16
+ let strings = this.getStringsForLocale(locale);
17
+ let string = strings[key];
18
+ if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
19
+ return string;
20
+ }
21
+ /** Returns all localized strings for the given locale. */ getStringsForLocale(locale) {
22
+ let strings = this.strings[locale];
23
+ if (!strings) {
24
+ strings = $5b160d28a433310d$var$getStringsForLocale(locale, this.strings, this.defaultLocale);
25
+ this.strings[locale] = strings;
26
+ }
27
+ return strings;
28
+ }
29
+ static getGlobalDictionaryForPackage(packageName) {
30
+ if (typeof window === "undefined") return null;
31
+ let locale = window[$5b160d28a433310d$var$localeSymbol];
32
+ if ($5b160d28a433310d$var$cachedGlobalStrings === undefined) {
33
+ let globalStrings = window[$5b160d28a433310d$var$stringsSymbol];
34
+ if (!globalStrings) return null;
35
+ $5b160d28a433310d$var$cachedGlobalStrings = {};
36
+ for(let pkg in globalStrings)$5b160d28a433310d$var$cachedGlobalStrings[pkg] = new $5b160d28a433310d$export$c17fa47878dc55b6({
37
+ [locale]: globalStrings[pkg]
38
+ }, locale);
39
+ }
40
+ let dictionary = $5b160d28a433310d$var$cachedGlobalStrings === null || $5b160d28a433310d$var$cachedGlobalStrings === void 0 ? void 0 : $5b160d28a433310d$var$cachedGlobalStrings[packageName];
41
+ if (!dictionary) throw new Error(`Strings for package "${packageName}" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`);
42
+ return dictionary;
43
+ }
44
+ constructor(messages, defaultLocale = "en-US"){
45
+ // Clone messages so we don't modify the original object.
46
+ // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
47
+ this.strings = Object.fromEntries(Object.entries(messages).filter(([, v])=>v));
48
+ this.defaultLocale = defaultLocale;
49
+ }
50
+ }
51
+ function $5b160d28a433310d$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
52
+ // If there is an exact match, use it.
53
+ if (strings[locale]) return strings[locale];
54
+ // Attempt to find the closest match by language.
55
+ // For example, if the locale is fr-CA (French Canadian), but there is only
56
+ // an fr-FR (France) set of strings, use that.
57
+ // This could be replaced with Intl.LocaleMatcher once it is supported.
58
+ // https://github.com/tc39/proposal-intl-localematcher
59
+ let language = $5b160d28a433310d$var$getLanguage(locale);
60
+ if (strings[language]) return strings[language];
61
+ for(let key in strings){
62
+ if (key.startsWith(language + "-")) return strings[key];
63
+ }
64
+ // Nothing close, use english.
65
+ return strings[defaultLocale];
66
+ }
67
+ function $5b160d28a433310d$var$getLanguage(locale) {
68
+ // @ts-ignore
69
+ if (Intl.Locale) // @ts-ignore
70
+ return new Intl.Locale(locale).language;
71
+ return locale.split("-")[0];
72
+ }
73
+
74
+
75
+ export {$5b160d28a433310d$export$c17fa47878dc55b6 as LocalizedStringDictionary};
76
+ //# sourceMappingURL=LocalizedStringDictionary.mjs.map
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright 2022 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ const $5b160d28a433310d$var$localeSymbol = Symbol.for("react-aria.i18n.locale");
12
+ const $5b160d28a433310d$var$stringsSymbol = Symbol.for("react-aria.i18n.strings");
13
+ let $5b160d28a433310d$var$cachedGlobalStrings = undefined;
14
+ class $5b160d28a433310d$export$c17fa47878dc55b6 {
15
+ /** Returns a localized string for the given key and locale. */ getStringForLocale(key, locale) {
16
+ let strings = this.getStringsForLocale(locale);
17
+ let string = strings[key];
18
+ if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
19
+ return string;
20
+ }
21
+ /** Returns all localized strings for the given locale. */ getStringsForLocale(locale) {
22
+ let strings = this.strings[locale];
23
+ if (!strings) {
24
+ strings = $5b160d28a433310d$var$getStringsForLocale(locale, this.strings, this.defaultLocale);
25
+ this.strings[locale] = strings;
26
+ }
27
+ return strings;
28
+ }
29
+ static getGlobalDictionaryForPackage(packageName) {
30
+ if (typeof window === "undefined") return null;
31
+ let locale = window[$5b160d28a433310d$var$localeSymbol];
32
+ if ($5b160d28a433310d$var$cachedGlobalStrings === undefined) {
33
+ let globalStrings = window[$5b160d28a433310d$var$stringsSymbol];
34
+ if (!globalStrings) return null;
35
+ $5b160d28a433310d$var$cachedGlobalStrings = {};
36
+ for(let pkg in globalStrings)$5b160d28a433310d$var$cachedGlobalStrings[pkg] = new $5b160d28a433310d$export$c17fa47878dc55b6({
37
+ [locale]: globalStrings[pkg]
38
+ }, locale);
39
+ }
40
+ let dictionary = $5b160d28a433310d$var$cachedGlobalStrings === null || $5b160d28a433310d$var$cachedGlobalStrings === void 0 ? void 0 : $5b160d28a433310d$var$cachedGlobalStrings[packageName];
41
+ if (!dictionary) throw new Error(`Strings for package "${packageName}" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`);
42
+ return dictionary;
43
+ }
44
+ constructor(messages, defaultLocale = "en-US"){
45
+ // Clone messages so we don't modify the original object.
46
+ // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
47
+ this.strings = Object.fromEntries(Object.entries(messages).filter(([, v])=>v));
48
+ this.defaultLocale = defaultLocale;
49
+ }
50
+ }
51
+ function $5b160d28a433310d$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
52
+ // If there is an exact match, use it.
53
+ if (strings[locale]) return strings[locale];
54
+ // Attempt to find the closest match by language.
55
+ // For example, if the locale is fr-CA (French Canadian), but there is only
56
+ // an fr-FR (France) set of strings, use that.
57
+ // This could be replaced with Intl.LocaleMatcher once it is supported.
58
+ // https://github.com/tc39/proposal-intl-localematcher
59
+ let language = $5b160d28a433310d$var$getLanguage(locale);
60
+ if (strings[language]) return strings[language];
61
+ for(let key in strings){
62
+ if (key.startsWith(language + "-")) return strings[key];
63
+ }
64
+ // Nothing close, use english.
65
+ return strings[defaultLocale];
66
+ }
67
+ function $5b160d28a433310d$var$getLanguage(locale) {
68
+ // @ts-ignore
69
+ if (Intl.Locale) // @ts-ignore
70
+ return new Intl.Locale(locale).language;
71
+ return locale.split("-")[0];
72
+ }
73
+
74
+
75
+ export {$5b160d28a433310d$export$c17fa47878dc55b6 as LocalizedStringDictionary};
76
+ //# sourceMappingURL=LocalizedStringDictionary.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAQD,MAAM,qCAAe,OAAO,GAAG,CAAC;AAChC,MAAM,sCAAgB,OAAO,GAAG,CAAC;AACjC,IAAI,4CAAuG;AAMpG,MAAM;IAaX,6DAA6D,GAC7D,mBAAmB,GAAM,EAAE,MAAc,EAAK;QAC5C,IAAI,UAAU,IAAI,CAAC,mBAAmB,CAAC;QACvC,IAAI,SAAS,OAAO,CAAC,IAAI;QACzB,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,OAAO,OAAO,CAAC;QAG1E,OAAO;IACT;IAEA,wDAAwD,GACxD,oBAAoB,MAAc,EAAgB;QAChD,IAAI,UAAU,IAAI,CAAC,OAAO,CAAC,OAAO;QAClC,IAAI,CAAC,SAAS;YACZ,UAAU,0CAAoB,QAAQ,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa;YACtE,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG;QACzB;QAEA,OAAO;IACT;IAEA,OAAO,8BAA6F,WAAmB,EAA0C;QAC/J,IAAI,OAAO,WAAW,aACpB,OAAO;QAGT,IAAI,SAAS,MAAM,CAAC,mCAAa;QACjC,IAAI,8CAAwB,WAAW;YACrC,IAAI,gBAAgB,MAAM,CAAC,oCAAc;YACzC,IAAI,CAAC,eACH,OAAO;YAGT,4CAAsB,CAAC;YACvB,IAAK,IAAI,OAAO,cACd,yCAAmB,CAAC,IAAI,GAAG,IAAI,0CAA0B;gBAAC,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI;YAAA,GAAG;QAE7F;QAEA,IAAI,aAAa,sDAAA,gEAAA,yCAAqB,CAAC,YAAY;QACnD,IAAI,CAAC,YACH,MAAM,IAAI,MAAM,CAAC,qBAAqB,EAAE,YAAY,oHAAoH,CAAC;QAG3K,OAAO;IACT;IAvDA,YAAY,QAAgC,EAAE,gBAAwB,OAAO,CAAE;QAC7E,yDAAyD;QACzD,uGAAuG;QACvG,IAAI,CAAC,OAAO,GAAG,OAAO,WAAW,CAC/B,OAAO,OAAO,CAAC,UAAU,MAAM,CAAC,CAAC,GAAG,EAAE,GAAK;QAE7C,IAAI,CAAC,aAAa,GAAG;IACvB;AAiDF;AAEA,SAAS,0CAAiE,MAAc,EAAE,OAA+B,EAAE,gBAAgB,OAAO;IAChJ,sCAAsC;IACtC,IAAI,OAAO,CAAC,OAAO,EACjB,OAAO,OAAO,CAAC,OAAO;IAGxB,iDAAiD;IACjD,2EAA2E;IAC3E,8CAA8C;IAC9C,uEAAuE;IACvE,sDAAsD;IACtD,IAAI,WAAW,kCAAY;IAC3B,IAAI,OAAO,CAAC,SAAS,EACnB,OAAO,OAAO,CAAC,SAAS;IAG1B,IAAK,IAAI,OAAO,QAAS;QACvB,IAAI,IAAI,UAAU,CAAC,WAAW,MAC5B,OAAO,OAAO,CAAC,IAAI;IAEvB;IAEA,8BAA8B;IAC9B,OAAO,OAAO,CAAC,cAAc;AAC/B;AAEA,SAAS,kCAAY,MAAc;IACjC,aAAa;IACb,IAAI,KAAK,MAAM,EACb,aAAa;IACb,OAAO,IAAI,KAAK,MAAM,CAAC,QAAQ,QAAQ;IAGzC,OAAO,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE;AAC7B","sources":["packages/@internationalized/string/src/LocalizedStringDictionary.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedString} from './LocalizedStringFormatter';\n\nexport type LocalizedStrings<K extends string, T extends LocalizedString> = {\n [lang: string]: Record<K, T>\n};\n\nconst localeSymbol = Symbol.for('react-aria.i18n.locale');\nconst stringsSymbol = Symbol.for('react-aria.i18n.strings');\nlet cachedGlobalStrings: {[packageName: string]: LocalizedStringDictionary<any, any>} | null | undefined = undefined;\n\n/**\n * Stores a mapping of localized strings. Can be used to find the\n * closest available string for a given locale.\n */\nexport class LocalizedStringDictionary<K extends string = string, T extends LocalizedString = string> {\n private strings: LocalizedStrings<K, T>;\n private defaultLocale: string;\n\n constructor(messages: LocalizedStrings<K, T>, defaultLocale: string = 'en-US') {\n // Clone messages so we don't modify the original object.\n // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.\n this.strings = Object.fromEntries(\n Object.entries(messages).filter(([, v]) => v)\n );\n this.defaultLocale = defaultLocale;\n }\n\n /** Returns a localized string for the given key and locale. */\n getStringForLocale(key: K, locale: string): T {\n let strings = this.getStringsForLocale(locale);\n let string = strings[key];\n if (!string) {\n throw new Error(`Could not find intl message ${key} in ${locale} locale`);\n }\n\n return string;\n }\n\n /** Returns all localized strings for the given locale. */\n getStringsForLocale(locale: string): Record<K, T> {\n let strings = this.strings[locale];\n if (!strings) {\n strings = getStringsForLocale(locale, this.strings, this.defaultLocale);\n this.strings[locale] = strings;\n }\n\n return strings;\n }\n\n static getGlobalDictionaryForPackage<K extends string = string, T extends LocalizedString = string>(packageName: string): LocalizedStringDictionary<K, T> | null {\n if (typeof window === 'undefined') {\n return null;\n }\n\n let locale = window[localeSymbol];\n if (cachedGlobalStrings === undefined) {\n let globalStrings = window[stringsSymbol];\n if (!globalStrings) {\n return null;\n }\n\n cachedGlobalStrings = {};\n for (let pkg in globalStrings) {\n cachedGlobalStrings[pkg] = new LocalizedStringDictionary({[locale]: globalStrings[pkg]}, locale);\n }\n }\n\n let dictionary = cachedGlobalStrings?.[packageName];\n if (!dictionary) {\n throw new Error(`Strings for package \"${packageName}\" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`);\n }\n\n return dictionary;\n }\n}\n\nfunction getStringsForLocale<K extends string, T extends LocalizedString>(locale: string, strings: LocalizedStrings<K, T>, defaultLocale = 'en-US') {\n // If there is an exact match, use it.\n if (strings[locale]) {\n return strings[locale];\n }\n\n // Attempt to find the closest match by language.\n // For example, if the locale is fr-CA (French Canadian), but there is only\n // an fr-FR (France) set of strings, use that.\n // This could be replaced with Intl.LocaleMatcher once it is supported.\n // https://github.com/tc39/proposal-intl-localematcher\n let language = getLanguage(locale);\n if (strings[language]) {\n return strings[language];\n }\n\n for (let key in strings) {\n if (key.startsWith(language + '-')) {\n return strings[key];\n }\n }\n\n // Nothing close, use english.\n return strings[defaultLocale];\n}\n\nfunction getLanguage(locale: string) {\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n return new Intl.Locale(locale).language;\n }\n\n return locale.split('-')[0];\n}\n"],"names":[],"version":3,"file":"LocalizedStringDictionary.module.js.map"}
@@ -0,0 +1,58 @@
1
+
2
+ function $parcel$export(e, n, v, s) {
3
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
+ }
5
+
6
+ $parcel$export(module.exports, "LocalizedStringFormatter", () => $3e95fbf3429967d1$export$2f817fcdc4b89ae0);
7
+ /*
8
+ * Copyright 2022 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */ const $3e95fbf3429967d1$var$pluralRulesCache = new Map();
18
+ const $3e95fbf3429967d1$var$numberFormatCache = new Map();
19
+ class $3e95fbf3429967d1$export$2f817fcdc4b89ae0 {
20
+ /** Formats a localized string for the given key with the provided variables. */ format(key, variables) {
21
+ let message = this.strings.getStringForLocale(key, this.locale);
22
+ return typeof message === "function" ? message(variables, this) : message;
23
+ }
24
+ plural(count, options, type = "cardinal") {
25
+ let opt = options["=" + count];
26
+ if (opt) return typeof opt === "function" ? opt() : opt;
27
+ let key = this.locale + ":" + type;
28
+ let pluralRules = $3e95fbf3429967d1$var$pluralRulesCache.get(key);
29
+ if (!pluralRules) {
30
+ pluralRules = new Intl.PluralRules(this.locale, {
31
+ type: type
32
+ });
33
+ $3e95fbf3429967d1$var$pluralRulesCache.set(key, pluralRules);
34
+ }
35
+ let selected = pluralRules.select(count);
36
+ opt = options[selected] || options.other;
37
+ return typeof opt === "function" ? opt() : opt;
38
+ }
39
+ number(value) {
40
+ let numberFormat = $3e95fbf3429967d1$var$numberFormatCache.get(this.locale);
41
+ if (!numberFormat) {
42
+ numberFormat = new Intl.NumberFormat(this.locale);
43
+ $3e95fbf3429967d1$var$numberFormatCache.set(this.locale, numberFormat);
44
+ }
45
+ return numberFormat.format(value);
46
+ }
47
+ select(options, value) {
48
+ let opt = options[value] || options.other;
49
+ return typeof opt === "function" ? opt() : opt;
50
+ }
51
+ constructor(locale, strings){
52
+ this.locale = locale;
53
+ this.strings = strings;
54
+ }
55
+ }
56
+
57
+
58
+ //# sourceMappingURL=LocalizedStringFormatter.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAQD,MAAM,yCAAmB,IAAI;AAC7B,MAAM,0CAAoB,IAAI;AAMvB,MAAM;IASX,8EAA8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"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedStringDictionary} from './LocalizedStringDictionary';\n\nexport type Variables = Record<string, string | number | boolean> | undefined;\nexport type LocalizedString = string | ((args: Variables, formatter?: LocalizedStringFormatter<any, any>) => string);\ntype InternalString = string | (() => string);\n\nconst pluralRulesCache = new Map<string, Intl.PluralRules>();\nconst numberFormatCache = new Map<string, Intl.NumberFormat>();\n\n/**\n * Formats localized strings from a LocalizedStringDictionary. Supports interpolating variables,\n * selecting the correct pluralization, and formatting numbers for the locale.\n */\nexport class LocalizedStringFormatter<K extends string = string, T extends LocalizedString = string> {\n private locale: string;\n private strings: LocalizedStringDictionary<K, T>;\n\n constructor(locale: string, strings: LocalizedStringDictionary<K, T>) {\n this.locale = locale;\n this.strings = strings;\n }\n\n /** Formats a localized string for the given key with the provided variables. */\n format(key: K, variables?: Variables): string {\n let message = this.strings.getStringForLocale(key, this.locale);\n return typeof message === 'function' ? message(variables, this) : message;\n }\n\n protected plural(count: number, options: Record<string, InternalString>, type: Intl.PluralRuleType = 'cardinal') {\n let opt = options['=' + count];\n if (opt) {\n return typeof opt === 'function' ? opt() : opt;\n }\n\n let key = this.locale + ':' + type;\n let pluralRules = pluralRulesCache.get(key);\n if (!pluralRules) {\n pluralRules = new Intl.PluralRules(this.locale, {type});\n pluralRulesCache.set(key, pluralRules);\n }\n\n let selected = pluralRules.select(count);\n opt = options[selected] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n\n protected number(value: number) {\n let numberFormat = numberFormatCache.get(this.locale);\n if (!numberFormat) {\n numberFormat = new Intl.NumberFormat(this.locale);\n numberFormatCache.set(this.locale, numberFormat);\n }\n return numberFormat.format(value);\n }\n\n protected select(options: Record<string, InternalString>, value: string) {\n let opt = options[value] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n}\n"],"names":[],"version":3,"file":"LocalizedStringFormatter.main.js.map"}
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright 2022 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ const $6db58dc88e78b024$var$pluralRulesCache = new Map();
12
+ const $6db58dc88e78b024$var$numberFormatCache = new Map();
13
+ class $6db58dc88e78b024$export$2f817fcdc4b89ae0 {
14
+ /** Formats a localized string for the given key with the provided variables. */ format(key, variables) {
15
+ let message = this.strings.getStringForLocale(key, this.locale);
16
+ return typeof message === "function" ? message(variables, this) : message;
17
+ }
18
+ plural(count, options, type = "cardinal") {
19
+ let opt = options["=" + count];
20
+ if (opt) return typeof opt === "function" ? opt() : opt;
21
+ let key = this.locale + ":" + type;
22
+ let pluralRules = $6db58dc88e78b024$var$pluralRulesCache.get(key);
23
+ if (!pluralRules) {
24
+ pluralRules = new Intl.PluralRules(this.locale, {
25
+ type: type
26
+ });
27
+ $6db58dc88e78b024$var$pluralRulesCache.set(key, pluralRules);
28
+ }
29
+ let selected = pluralRules.select(count);
30
+ opt = options[selected] || options.other;
31
+ return typeof opt === "function" ? opt() : opt;
32
+ }
33
+ number(value) {
34
+ let numberFormat = $6db58dc88e78b024$var$numberFormatCache.get(this.locale);
35
+ if (!numberFormat) {
36
+ numberFormat = new Intl.NumberFormat(this.locale);
37
+ $6db58dc88e78b024$var$numberFormatCache.set(this.locale, numberFormat);
38
+ }
39
+ return numberFormat.format(value);
40
+ }
41
+ select(options, value) {
42
+ let opt = options[value] || options.other;
43
+ return typeof opt === "function" ? opt() : opt;
44
+ }
45
+ constructor(locale, strings){
46
+ this.locale = locale;
47
+ this.strings = strings;
48
+ }
49
+ }
50
+
51
+
52
+ export {$6db58dc88e78b024$export$2f817fcdc4b89ae0 as LocalizedStringFormatter};
53
+ //# sourceMappingURL=LocalizedStringFormatter.mjs.map
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright 2022 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ const $6db58dc88e78b024$var$pluralRulesCache = new Map();
12
+ const $6db58dc88e78b024$var$numberFormatCache = new Map();
13
+ class $6db58dc88e78b024$export$2f817fcdc4b89ae0 {
14
+ /** Formats a localized string for the given key with the provided variables. */ format(key, variables) {
15
+ let message = this.strings.getStringForLocale(key, this.locale);
16
+ return typeof message === "function" ? message(variables, this) : message;
17
+ }
18
+ plural(count, options, type = "cardinal") {
19
+ let opt = options["=" + count];
20
+ if (opt) return typeof opt === "function" ? opt() : opt;
21
+ let key = this.locale + ":" + type;
22
+ let pluralRules = $6db58dc88e78b024$var$pluralRulesCache.get(key);
23
+ if (!pluralRules) {
24
+ pluralRules = new Intl.PluralRules(this.locale, {
25
+ type: type
26
+ });
27
+ $6db58dc88e78b024$var$pluralRulesCache.set(key, pluralRules);
28
+ }
29
+ let selected = pluralRules.select(count);
30
+ opt = options[selected] || options.other;
31
+ return typeof opt === "function" ? opt() : opt;
32
+ }
33
+ number(value) {
34
+ let numberFormat = $6db58dc88e78b024$var$numberFormatCache.get(this.locale);
35
+ if (!numberFormat) {
36
+ numberFormat = new Intl.NumberFormat(this.locale);
37
+ $6db58dc88e78b024$var$numberFormatCache.set(this.locale, numberFormat);
38
+ }
39
+ return numberFormat.format(value);
40
+ }
41
+ select(options, value) {
42
+ let opt = options[value] || options.other;
43
+ return typeof opt === "function" ? opt() : opt;
44
+ }
45
+ constructor(locale, strings){
46
+ this.locale = locale;
47
+ this.strings = strings;
48
+ }
49
+ }
50
+
51
+
52
+ export {$6db58dc88e78b024$export$2f817fcdc4b89ae0 as LocalizedStringFormatter};
53
+ //# sourceMappingURL=LocalizedStringFormatter.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAQD,MAAM,yCAAmB,IAAI;AAC7B,MAAM,0CAAoB,IAAI;AAMvB,MAAM;IASX,8EAA8E,GAC9E,OAAO,GAAM,EAAE,SAAqB,EAAU;QAC5C,IAAI,UAAU,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC,MAAM;QAC9D,OAAO,OAAO,YAAY,aAAa,QAAQ,WAAW,IAAI,IAAI;IACpE;IAEU,OAAO,KAAa,EAAE,OAAuC,EAAE,OAA4B,UAAU,EAAE;QAC/G,IAAI,MAAM,OAAO,CAAC,MAAM,MAAM;QAC9B,IAAI,KACF,OAAO,OAAO,QAAQ,aAAa,QAAQ;QAG7C,IAAI,MAAM,IAAI,CAAC,MAAM,GAAG,MAAM;QAC9B,IAAI,cAAc,uCAAiB,GAAG,CAAC;QACvC,IAAI,CAAC,aAAa;YAChB,cAAc,IAAI,KAAK,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE;sBAAC;YAAI;YACrD,uCAAiB,GAAG,CAAC,KAAK;QAC5B;QAEA,IAAI,WAAW,YAAY,MAAM,CAAC;QAClC,MAAM,OAAO,CAAC,SAAS,IAAI,QAAQ,KAAK;QACxC,OAAO,OAAO,QAAQ,aAAa,QAAQ;IAC7C;IAEU,OAAO,KAAa,EAAE;QAC9B,IAAI,eAAe,wCAAkB,GAAG,CAAC,IAAI,CAAC,MAAM;QACpD,IAAI,CAAC,cAAc;YACjB,eAAe,IAAI,KAAK,YAAY,CAAC,IAAI,CAAC,MAAM;YAChD,wCAAkB,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE;QACrC;QACA,OAAO,aAAa,MAAM,CAAC;IAC7B;IAEU,OAAO,OAAuC,EAAE,KAAa,EAAE;QACvE,IAAI,MAAM,OAAO,CAAC,MAAM,IAAI,QAAQ,KAAK;QACzC,OAAO,OAAO,QAAQ,aAAa,QAAQ;IAC7C;IAzCA,YAAY,MAAc,EAAE,OAAwC,CAAE;QACpE,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,OAAO,GAAG;IACjB;AAuCF","sources":["packages/@internationalized/string/src/LocalizedStringFormatter.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedStringDictionary} from './LocalizedStringDictionary';\n\nexport type Variables = Record<string, string | number | boolean> | undefined;\nexport type LocalizedString = string | ((args: Variables, formatter?: LocalizedStringFormatter<any, any>) => string);\ntype InternalString = string | (() => string);\n\nconst pluralRulesCache = new Map<string, Intl.PluralRules>();\nconst numberFormatCache = new Map<string, Intl.NumberFormat>();\n\n/**\n * Formats localized strings from a LocalizedStringDictionary. Supports interpolating variables,\n * selecting the correct pluralization, and formatting numbers for the locale.\n */\nexport class LocalizedStringFormatter<K extends string = string, T extends LocalizedString = string> {\n private locale: string;\n private strings: LocalizedStringDictionary<K, T>;\n\n constructor(locale: string, strings: LocalizedStringDictionary<K, T>) {\n this.locale = locale;\n this.strings = strings;\n }\n\n /** Formats a localized string for the given key with the provided variables. */\n format(key: K, variables?: Variables): string {\n let message = this.strings.getStringForLocale(key, this.locale);\n return typeof message === 'function' ? message(variables, this) : message;\n }\n\n protected plural(count: number, options: Record<string, InternalString>, type: Intl.PluralRuleType = 'cardinal') {\n let opt = options['=' + count];\n if (opt) {\n return typeof opt === 'function' ? opt() : opt;\n }\n\n let key = this.locale + ':' + type;\n let pluralRules = pluralRulesCache.get(key);\n if (!pluralRules) {\n pluralRules = new Intl.PluralRules(this.locale, {type});\n pluralRulesCache.set(key, pluralRules);\n }\n\n let selected = pluralRules.select(count);\n opt = options[selected] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n\n protected number(value: number) {\n let numberFormat = numberFormatCache.get(this.locale);\n if (!numberFormat) {\n numberFormat = new Intl.NumberFormat(this.locale);\n numberFormatCache.set(this.locale, numberFormat);\n }\n return numberFormat.format(value);\n }\n\n protected select(options: Record<string, InternalString>, value: string) {\n let opt = options[value] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n}\n"],"names":[],"version":3,"file":"LocalizedStringFormatter.module.js.map"}
package/dist/import.mjs CHANGED
@@ -1,86 +1,5 @@
1
- /*
2
- * Copyright 2022 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */ /*
12
- * Copyright 2022 Adobe. All rights reserved.
13
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License. You may obtain a copy
15
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software distributed under
18
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
- * OF ANY KIND, either express or implied. See the License for the specific language
20
- * governing permissions and limitations under the License.
21
- */ const $5b160d28a433310d$var$localeSymbol = Symbol.for("react-aria.i18n.locale");
22
- const $5b160d28a433310d$var$stringsSymbol = Symbol.for("react-aria.i18n.strings");
23
- let $5b160d28a433310d$var$cachedGlobalStrings = undefined;
24
- class $5b160d28a433310d$export$c17fa47878dc55b6 {
25
- /** Returns a localized string for the given key and locale. */ getStringForLocale(key, locale) {
26
- let strings = this.getStringsForLocale(locale);
27
- let string = strings[key];
28
- if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
29
- return string;
30
- }
31
- /** Returns all localized strings for the given locale. */ getStringsForLocale(locale) {
32
- let strings = this.strings[locale];
33
- if (!strings) {
34
- strings = $5b160d28a433310d$var$getStringsForLocale(locale, this.strings, this.defaultLocale);
35
- this.strings[locale] = strings;
36
- }
37
- return strings;
38
- }
39
- static getGlobalDictionaryForPackage(packageName) {
40
- if (typeof window === "undefined") return null;
41
- let locale = window[$5b160d28a433310d$var$localeSymbol];
42
- if ($5b160d28a433310d$var$cachedGlobalStrings === undefined) {
43
- let globalStrings = window[$5b160d28a433310d$var$stringsSymbol];
44
- if (!globalStrings) return null;
45
- $5b160d28a433310d$var$cachedGlobalStrings = {};
46
- for(let pkg in globalStrings)$5b160d28a433310d$var$cachedGlobalStrings[pkg] = new $5b160d28a433310d$export$c17fa47878dc55b6({
47
- [locale]: globalStrings[pkg]
48
- }, locale);
49
- }
50
- let dictionary = $5b160d28a433310d$var$cachedGlobalStrings === null || $5b160d28a433310d$var$cachedGlobalStrings === void 0 ? void 0 : $5b160d28a433310d$var$cachedGlobalStrings[packageName];
51
- if (!dictionary) throw new Error(`Strings for package "${packageName}" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`);
52
- return dictionary;
53
- }
54
- constructor(messages, defaultLocale = "en-US"){
55
- // Clone messages so we don't modify the original object.
56
- // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
57
- this.strings = Object.fromEntries(Object.entries(messages).filter(([, v])=>v));
58
- this.defaultLocale = defaultLocale;
59
- }
60
- }
61
- function $5b160d28a433310d$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
62
- // If there is an exact match, use it.
63
- if (strings[locale]) return strings[locale];
64
- // Attempt to find the closest match by language.
65
- // For example, if the locale is fr-CA (French Canadian), but there is only
66
- // an fr-FR (France) set of strings, use that.
67
- // This could be replaced with Intl.LocaleMatcher once it is supported.
68
- // https://github.com/tc39/proposal-intl-localematcher
69
- let language = $5b160d28a433310d$var$getLanguage(locale);
70
- if (strings[language]) return strings[language];
71
- for(let key in strings){
72
- if (key.startsWith(language + "-")) return strings[key];
73
- }
74
- // Nothing close, use english.
75
- return strings[defaultLocale];
76
- }
77
- function $5b160d28a433310d$var$getLanguage(locale) {
78
- // @ts-ignore
79
- if (Intl.Locale) // @ts-ignore
80
- return new Intl.Locale(locale).language;
81
- return locale.split("-")[0];
82
- }
83
-
1
+ import {LocalizedStringDictionary as $5b160d28a433310d$export$c17fa47878dc55b6} from "./LocalizedStringDictionary.mjs";
2
+ import {LocalizedStringFormatter as $6db58dc88e78b024$export$2f817fcdc4b89ae0} from "./LocalizedStringFormatter.mjs";
84
3
 
85
4
  /*
86
5
  * Copyright 2022 Adobe. All rights reserved.
@@ -92,46 +11,7 @@ function $5b160d28a433310d$var$getLanguage(locale) {
92
11
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
93
12
  * OF ANY KIND, either express or implied. See the License for the specific language
94
13
  * governing permissions and limitations under the License.
95
- */ const $6db58dc88e78b024$var$pluralRulesCache = new Map();
96
- const $6db58dc88e78b024$var$numberFormatCache = new Map();
97
- class $6db58dc88e78b024$export$2f817fcdc4b89ae0 {
98
- /** Formats a localized string for the given key with the provided variables. */ format(key, variables) {
99
- let message = this.strings.getStringForLocale(key, this.locale);
100
- return typeof message === "function" ? message(variables, this) : message;
101
- }
102
- plural(count, options, type = "cardinal") {
103
- let opt = options["=" + count];
104
- if (opt) return typeof opt === "function" ? opt() : opt;
105
- let key = this.locale + ":" + type;
106
- let pluralRules = $6db58dc88e78b024$var$pluralRulesCache.get(key);
107
- if (!pluralRules) {
108
- pluralRules = new Intl.PluralRules(this.locale, {
109
- type: type
110
- });
111
- $6db58dc88e78b024$var$pluralRulesCache.set(key, pluralRules);
112
- }
113
- let selected = pluralRules.select(count);
114
- opt = options[selected] || options.other;
115
- return typeof opt === "function" ? opt() : opt;
116
- }
117
- number(value) {
118
- let numberFormat = $6db58dc88e78b024$var$numberFormatCache.get(this.locale);
119
- if (!numberFormat) {
120
- numberFormat = new Intl.NumberFormat(this.locale);
121
- $6db58dc88e78b024$var$numberFormatCache.set(this.locale, numberFormat);
122
- }
123
- return numberFormat.format(value);
124
- }
125
- select(options, value) {
126
- let opt = options[value] || options.other;
127
- return typeof opt === "function" ? opt() : opt;
128
- }
129
- constructor(locale, strings){
130
- this.locale = locale;
131
- this.strings = strings;
132
- }
133
- }
134
-
14
+ */
135
15
 
136
16
 
137
17
 
package/dist/main.js CHANGED
@@ -1,10 +1,13 @@
1
+ var $f80be5fd4d03dda9$exports = require("./LocalizedStringDictionary.main.js");
2
+ var $3e95fbf3429967d1$exports = require("./LocalizedStringFormatter.main.js");
3
+
1
4
 
2
5
  function $parcel$export(e, n, v, s) {
3
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
7
  }
5
8
 
6
- $parcel$export(module.exports, "LocalizedStringDictionary", () => $f80be5fd4d03dda9$export$c17fa47878dc55b6);
7
- $parcel$export(module.exports, "LocalizedStringFormatter", () => $3e95fbf3429967d1$export$2f817fcdc4b89ae0);
9
+ $parcel$export(module.exports, "LocalizedStringDictionary", () => $f80be5fd4d03dda9$exports.LocalizedStringDictionary);
10
+ $parcel$export(module.exports, "LocalizedStringFormatter", () => $3e95fbf3429967d1$exports.LocalizedStringFormatter);
8
11
  /*
9
12
  * Copyright 2022 Adobe. All rights reserved.
10
13
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -15,130 +18,7 @@ $parcel$export(module.exports, "LocalizedStringFormatter", () => $3e95fbf3429967
15
18
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
19
  * OF ANY KIND, either express or implied. See the License for the specific language
17
20
  * governing permissions and limitations under the License.
18
- */ /*
19
- * Copyright 2022 Adobe. All rights reserved.
20
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
21
- * you may not use this file except in compliance with the License. You may obtain a copy
22
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
23
- *
24
- * Unless required by applicable law or agreed to in writing, software distributed under
25
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
26
- * OF ANY KIND, either express or implied. See the License for the specific language
27
- * governing permissions and limitations under the License.
28
- */ const $f80be5fd4d03dda9$var$localeSymbol = Symbol.for("react-aria.i18n.locale");
29
- const $f80be5fd4d03dda9$var$stringsSymbol = Symbol.for("react-aria.i18n.strings");
30
- let $f80be5fd4d03dda9$var$cachedGlobalStrings = undefined;
31
- class $f80be5fd4d03dda9$export$c17fa47878dc55b6 {
32
- /** Returns a localized string for the given key and locale. */ getStringForLocale(key, locale) {
33
- let strings = this.getStringsForLocale(locale);
34
- let string = strings[key];
35
- if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
36
- return string;
37
- }
38
- /** Returns all localized strings for the given locale. */ getStringsForLocale(locale) {
39
- let strings = this.strings[locale];
40
- if (!strings) {
41
- strings = $f80be5fd4d03dda9$var$getStringsForLocale(locale, this.strings, this.defaultLocale);
42
- this.strings[locale] = strings;
43
- }
44
- return strings;
45
- }
46
- static getGlobalDictionaryForPackage(packageName) {
47
- if (typeof window === "undefined") return null;
48
- let locale = window[$f80be5fd4d03dda9$var$localeSymbol];
49
- if ($f80be5fd4d03dda9$var$cachedGlobalStrings === undefined) {
50
- let globalStrings = window[$f80be5fd4d03dda9$var$stringsSymbol];
51
- if (!globalStrings) return null;
52
- $f80be5fd4d03dda9$var$cachedGlobalStrings = {};
53
- for(let pkg in globalStrings)$f80be5fd4d03dda9$var$cachedGlobalStrings[pkg] = new $f80be5fd4d03dda9$export$c17fa47878dc55b6({
54
- [locale]: globalStrings[pkg]
55
- }, locale);
56
- }
57
- let dictionary = $f80be5fd4d03dda9$var$cachedGlobalStrings === null || $f80be5fd4d03dda9$var$cachedGlobalStrings === void 0 ? void 0 : $f80be5fd4d03dda9$var$cachedGlobalStrings[packageName];
58
- if (!dictionary) throw new Error(`Strings for package "${packageName}" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`);
59
- return dictionary;
60
- }
61
- constructor(messages, defaultLocale = "en-US"){
62
- // Clone messages so we don't modify the original object.
63
- // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
64
- this.strings = Object.fromEntries(Object.entries(messages).filter(([, v])=>v));
65
- this.defaultLocale = defaultLocale;
66
- }
67
- }
68
- function $f80be5fd4d03dda9$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
69
- // If there is an exact match, use it.
70
- if (strings[locale]) return strings[locale];
71
- // Attempt to find the closest match by language.
72
- // For example, if the locale is fr-CA (French Canadian), but there is only
73
- // an fr-FR (France) set of strings, use that.
74
- // This could be replaced with Intl.LocaleMatcher once it is supported.
75
- // https://github.com/tc39/proposal-intl-localematcher
76
- let language = $f80be5fd4d03dda9$var$getLanguage(locale);
77
- if (strings[language]) return strings[language];
78
- for(let key in strings){
79
- if (key.startsWith(language + "-")) return strings[key];
80
- }
81
- // Nothing close, use english.
82
- return strings[defaultLocale];
83
- }
84
- function $f80be5fd4d03dda9$var$getLanguage(locale) {
85
- // @ts-ignore
86
- if (Intl.Locale) // @ts-ignore
87
- return new Intl.Locale(locale).language;
88
- return locale.split("-")[0];
89
- }
90
-
91
-
92
- /*
93
- * Copyright 2022 Adobe. All rights reserved.
94
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
95
- * you may not use this file except in compliance with the License. You may obtain a copy
96
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
97
- *
98
- * Unless required by applicable law or agreed to in writing, software distributed under
99
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
100
- * OF ANY KIND, either express or implied. See the License for the specific language
101
- * governing permissions and limitations under the License.
102
- */ const $3e95fbf3429967d1$var$pluralRulesCache = new Map();
103
- const $3e95fbf3429967d1$var$numberFormatCache = new Map();
104
- class $3e95fbf3429967d1$export$2f817fcdc4b89ae0 {
105
- /** Formats a localized string for the given key with the provided variables. */ format(key, variables) {
106
- let message = this.strings.getStringForLocale(key, this.locale);
107
- return typeof message === "function" ? message(variables, this) : message;
108
- }
109
- plural(count, options, type = "cardinal") {
110
- let opt = options["=" + count];
111
- if (opt) return typeof opt === "function" ? opt() : opt;
112
- let key = this.locale + ":" + type;
113
- let pluralRules = $3e95fbf3429967d1$var$pluralRulesCache.get(key);
114
- if (!pluralRules) {
115
- pluralRules = new Intl.PluralRules(this.locale, {
116
- type: type
117
- });
118
- $3e95fbf3429967d1$var$pluralRulesCache.set(key, pluralRules);
119
- }
120
- let selected = pluralRules.select(count);
121
- opt = options[selected] || options.other;
122
- return typeof opt === "function" ? opt() : opt;
123
- }
124
- number(value) {
125
- let numberFormat = $3e95fbf3429967d1$var$numberFormatCache.get(this.locale);
126
- if (!numberFormat) {
127
- numberFormat = new Intl.NumberFormat(this.locale);
128
- $3e95fbf3429967d1$var$numberFormatCache.set(this.locale, numberFormat);
129
- }
130
- return numberFormat.format(value);
131
- }
132
- select(options, value) {
133
- let opt = options[value] || options.other;
134
- return typeof opt === "function" ? opt() : opt;
135
- }
136
- constructor(locale, strings){
137
- this.locale = locale;
138
- this.strings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A4B,UAAU,EAAE;QAC/G,IAAI,MAAM,OAAO,CAAC,MAAM,MAAM;QAC9B,IAAI,KACF,OAAO,OAAO,QAAQ,aAAa,QAAQ;QAG7C,IAAI,MAAM,IAAI,CAAC,MAAM,GAAG,MAAM;QAC9B,IAAI,cAAc,uCAAiB,GAAG,CAAC;QACvC,IAAI,CAAC,aAAa;YAChB,cAAc,IAAI,KAAK,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE;sBAAC;YAAI;YACrD,uCAAiB,GAAG,CAAC,KAAK;QAC5B;QAEA,IAAI,WAAW,YAAY,MAAM,CAAC;QAClC,MAAM,OAAO,CAAC,SAAS,IAAI,QAAQ,KAAK;QACxC,OAAO,OAAO,QAAQ,aAAa,QAAQ;IAC7C;IAEU,OAAO,KAAa,EAAE;QAC9B,IAAI,eAAe,wCAAkB,GAAG,CAAC,IAAI,CAAC,MAAM;QACpD,IAAI,CAAC,cAAc;YACjB,eAAe,IAAI,KAAK,YAAY,CAAC,IAAI,CAAC,MAAM;YAChD,wCAAkB,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE;QACrC;QACA,OAAO,aAAa,MAAM,CAAC;IAC7B;IAEU,OAAO,OAAuC,EAAE,KAAa,EAAE;QACvE,IAAI,MAAM,OAAO,CAAC,MAAM,IAAI,QAAQ,KAAK;QACzC,OAAO,OAAO,QAAQ,aAAa,QAAQ;IAC7C;IAzCA,YAAY,MAAc,EAAE,OAAwC,CAAE;QACpE,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,OAAO,GAAG;IACjB;AAuCF;","sources":["packages/@internationalized/string/src/index.ts","packages/@internationalized/string/src/LocalizedStringDictionary.ts","packages/@internationalized/string/src/LocalizedStringFormatter.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {Variables, LocalizedString} from './LocalizedStringFormatter';\nexport type {LocalizedStrings} from './LocalizedStringDictionary';\nexport {LocalizedStringDictionary} from './LocalizedStringDictionary';\nexport {LocalizedStringFormatter} from './LocalizedStringFormatter';\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedString} from './LocalizedStringFormatter';\n\nexport type LocalizedStrings<K extends string, T extends LocalizedString> = {\n [lang: string]: Record<K, T>\n};\n\nconst localeSymbol = Symbol.for('react-aria.i18n.locale');\nconst stringsSymbol = Symbol.for('react-aria.i18n.strings');\nlet cachedGlobalStrings: {[packageName: string]: LocalizedStringDictionary<any, any>} | null | undefined = undefined;\n\n/**\n * Stores a mapping of localized strings. Can be used to find the\n * closest available string for a given locale.\n */\nexport class LocalizedStringDictionary<K extends string = string, T extends LocalizedString = string> {\n private strings: LocalizedStrings<K, T>;\n private defaultLocale: string;\n\n constructor(messages: LocalizedStrings<K, T>, defaultLocale: string = 'en-US') {\n // Clone messages so we don't modify the original object.\n // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.\n this.strings = Object.fromEntries(\n Object.entries(messages).filter(([, v]) => v)\n );\n this.defaultLocale = defaultLocale;\n }\n\n /** Returns a localized string for the given key and locale. */\n getStringForLocale(key: K, locale: string): T {\n let strings = this.getStringsForLocale(locale);\n let string = strings[key];\n if (!string) {\n throw new Error(`Could not find intl message ${key} in ${locale} locale`);\n }\n\n return string;\n }\n\n /** Returns all localized strings for the given locale. */\n getStringsForLocale(locale: string): Record<K, T> {\n let strings = this.strings[locale];\n if (!strings) {\n strings = getStringsForLocale(locale, this.strings, this.defaultLocale);\n this.strings[locale] = strings;\n }\n\n return strings;\n }\n\n static getGlobalDictionaryForPackage<K extends string = string, T extends LocalizedString = string>(packageName: string): LocalizedStringDictionary<K, T> | null {\n if (typeof window === 'undefined') {\n return null;\n }\n\n let locale = window[localeSymbol];\n if (cachedGlobalStrings === undefined) {\n let globalStrings = window[stringsSymbol];\n if (!globalStrings) {\n return null;\n }\n\n cachedGlobalStrings = {};\n for (let pkg in globalStrings) {\n cachedGlobalStrings[pkg] = new LocalizedStringDictionary({[locale]: globalStrings[pkg]}, locale);\n }\n }\n\n let dictionary = cachedGlobalStrings?.[packageName];\n if (!dictionary) {\n throw new Error(`Strings for package \"${packageName}\" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`);\n }\n\n return dictionary;\n }\n}\n\nfunction getStringsForLocale<K extends string, T extends LocalizedString>(locale: string, strings: LocalizedStrings<K, T>, defaultLocale = 'en-US') {\n // If there is an exact match, use it.\n if (strings[locale]) {\n return strings[locale];\n }\n\n // Attempt to find the closest match by language.\n // For example, if the locale is fr-CA (French Canadian), but there is only\n // an fr-FR (France) set of strings, use that.\n // This could be replaced with Intl.LocaleMatcher once it is supported.\n // https://github.com/tc39/proposal-intl-localematcher\n let language = getLanguage(locale);\n if (strings[language]) {\n return strings[language];\n }\n\n for (let key in strings) {\n if (key.startsWith(language + '-')) {\n return strings[key];\n }\n }\n\n // Nothing close, use english.\n return strings[defaultLocale];\n}\n\nfunction getLanguage(locale: string) {\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n return new Intl.Locale(locale).language;\n }\n\n return locale.split('-')[0];\n}\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedStringDictionary} from './LocalizedStringDictionary';\n\nexport type Variables = Record<string, string | number | boolean> | undefined;\nexport type LocalizedString = string | ((args: Variables, formatter?: LocalizedStringFormatter<any, any>) => string);\ntype InternalString = string | (() => string);\n\nconst pluralRulesCache = new Map<string, Intl.PluralRules>();\nconst numberFormatCache = new Map<string, Intl.NumberFormat>();\n\n/**\n * Formats localized strings from a LocalizedStringDictionary. Supports interpolating variables,\n * selecting the correct pluralization, and formatting numbers for the locale.\n */\nexport class LocalizedStringFormatter<K extends string = string, T extends LocalizedString = string> {\n private locale: string;\n private strings: LocalizedStringDictionary<K, T>;\n\n constructor(locale: string, strings: LocalizedStringDictionary<K, T>) {\n this.locale = locale;\n this.strings = strings;\n }\n\n /** Formats a localized string for the given key with the provided variables. */\n format(key: K, variables?: Variables): string {\n let message = this.strings.getStringForLocale(key, this.locale);\n return typeof message === 'function' ? message(variables, this) : message;\n }\n\n protected plural(count: number, options: Record<string, InternalString>, type: Intl.PluralRuleType = 'cardinal') {\n let opt = options['=' + count];\n if (opt) {\n return typeof opt === 'function' ? opt() : opt;\n }\n\n let key = this.locale + ':' + type;\n let pluralRules = pluralRulesCache.get(key);\n if (!pluralRules) {\n pluralRules = new Intl.PluralRules(this.locale, {type});\n pluralRulesCache.set(key, pluralRules);\n }\n\n let selected = pluralRules.select(count);\n opt = options[selected] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n\n protected number(value: number) {\n let numberFormat = numberFormatCache.get(this.locale);\n if (!numberFormat) {\n numberFormat = new Intl.NumberFormat(this.locale);\n numberFormatCache.set(this.locale, numberFormat);\n }\n return numberFormat.format(value);\n }\n\n protected select(options: Record<string, InternalString>, value: string) {\n let opt = options[value] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@internationalized/string/src/index.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {Variables, LocalizedString} from './LocalizedStringFormatter';\nexport type {LocalizedStrings} from './LocalizedStringDictionary';\nexport {LocalizedStringDictionary} from './LocalizedStringDictionary';\nexport {LocalizedStringFormatter} from './LocalizedStringFormatter';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,86 +1,5 @@
1
- /*
2
- * Copyright 2022 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */ /*
12
- * Copyright 2022 Adobe. All rights reserved.
13
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License. You may obtain a copy
15
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software distributed under
18
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
- * OF ANY KIND, either express or implied. See the License for the specific language
20
- * governing permissions and limitations under the License.
21
- */ const $5b160d28a433310d$var$localeSymbol = Symbol.for("react-aria.i18n.locale");
22
- const $5b160d28a433310d$var$stringsSymbol = Symbol.for("react-aria.i18n.strings");
23
- let $5b160d28a433310d$var$cachedGlobalStrings = undefined;
24
- class $5b160d28a433310d$export$c17fa47878dc55b6 {
25
- /** Returns a localized string for the given key and locale. */ getStringForLocale(key, locale) {
26
- let strings = this.getStringsForLocale(locale);
27
- let string = strings[key];
28
- if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
29
- return string;
30
- }
31
- /** Returns all localized strings for the given locale. */ getStringsForLocale(locale) {
32
- let strings = this.strings[locale];
33
- if (!strings) {
34
- strings = $5b160d28a433310d$var$getStringsForLocale(locale, this.strings, this.defaultLocale);
35
- this.strings[locale] = strings;
36
- }
37
- return strings;
38
- }
39
- static getGlobalDictionaryForPackage(packageName) {
40
- if (typeof window === "undefined") return null;
41
- let locale = window[$5b160d28a433310d$var$localeSymbol];
42
- if ($5b160d28a433310d$var$cachedGlobalStrings === undefined) {
43
- let globalStrings = window[$5b160d28a433310d$var$stringsSymbol];
44
- if (!globalStrings) return null;
45
- $5b160d28a433310d$var$cachedGlobalStrings = {};
46
- for(let pkg in globalStrings)$5b160d28a433310d$var$cachedGlobalStrings[pkg] = new $5b160d28a433310d$export$c17fa47878dc55b6({
47
- [locale]: globalStrings[pkg]
48
- }, locale);
49
- }
50
- let dictionary = $5b160d28a433310d$var$cachedGlobalStrings === null || $5b160d28a433310d$var$cachedGlobalStrings === void 0 ? void 0 : $5b160d28a433310d$var$cachedGlobalStrings[packageName];
51
- if (!dictionary) throw new Error(`Strings for package "${packageName}" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`);
52
- return dictionary;
53
- }
54
- constructor(messages, defaultLocale = "en-US"){
55
- // Clone messages so we don't modify the original object.
56
- // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
57
- this.strings = Object.fromEntries(Object.entries(messages).filter(([, v])=>v));
58
- this.defaultLocale = defaultLocale;
59
- }
60
- }
61
- function $5b160d28a433310d$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
62
- // If there is an exact match, use it.
63
- if (strings[locale]) return strings[locale];
64
- // Attempt to find the closest match by language.
65
- // For example, if the locale is fr-CA (French Canadian), but there is only
66
- // an fr-FR (France) set of strings, use that.
67
- // This could be replaced with Intl.LocaleMatcher once it is supported.
68
- // https://github.com/tc39/proposal-intl-localematcher
69
- let language = $5b160d28a433310d$var$getLanguage(locale);
70
- if (strings[language]) return strings[language];
71
- for(let key in strings){
72
- if (key.startsWith(language + "-")) return strings[key];
73
- }
74
- // Nothing close, use english.
75
- return strings[defaultLocale];
76
- }
77
- function $5b160d28a433310d$var$getLanguage(locale) {
78
- // @ts-ignore
79
- if (Intl.Locale) // @ts-ignore
80
- return new Intl.Locale(locale).language;
81
- return locale.split("-")[0];
82
- }
83
-
1
+ import {LocalizedStringDictionary as $5b160d28a433310d$export$c17fa47878dc55b6} from "./LocalizedStringDictionary.module.js";
2
+ import {LocalizedStringFormatter as $6db58dc88e78b024$export$2f817fcdc4b89ae0} from "./LocalizedStringFormatter.module.js";
84
3
 
85
4
  /*
86
5
  * Copyright 2022 Adobe. All rights reserved.
@@ -92,46 +11,7 @@ function $5b160d28a433310d$var$getLanguage(locale) {
92
11
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
93
12
  * OF ANY KIND, either express or implied. See the License for the specific language
94
13
  * governing permissions and limitations under the License.
95
- */ const $6db58dc88e78b024$var$pluralRulesCache = new Map();
96
- const $6db58dc88e78b024$var$numberFormatCache = new Map();
97
- class $6db58dc88e78b024$export$2f817fcdc4b89ae0 {
98
- /** Formats a localized string for the given key with the provided variables. */ format(key, variables) {
99
- let message = this.strings.getStringForLocale(key, this.locale);
100
- return typeof message === "function" ? message(variables, this) : message;
101
- }
102
- plural(count, options, type = "cardinal") {
103
- let opt = options["=" + count];
104
- if (opt) return typeof opt === "function" ? opt() : opt;
105
- let key = this.locale + ":" + type;
106
- let pluralRules = $6db58dc88e78b024$var$pluralRulesCache.get(key);
107
- if (!pluralRules) {
108
- pluralRules = new Intl.PluralRules(this.locale, {
109
- type: type
110
- });
111
- $6db58dc88e78b024$var$pluralRulesCache.set(key, pluralRules);
112
- }
113
- let selected = pluralRules.select(count);
114
- opt = options[selected] || options.other;
115
- return typeof opt === "function" ? opt() : opt;
116
- }
117
- number(value) {
118
- let numberFormat = $6db58dc88e78b024$var$numberFormatCache.get(this.locale);
119
- if (!numberFormat) {
120
- numberFormat = new Intl.NumberFormat(this.locale);
121
- $6db58dc88e78b024$var$numberFormatCache.set(this.locale, numberFormat);
122
- }
123
- return numberFormat.format(value);
124
- }
125
- select(options, value) {
126
- let opt = options[value] || options.other;
127
- return typeof opt === "function" ? opt() : opt;
128
- }
129
- constructor(locale, strings){
130
- this.locale = locale;
131
- this.strings = strings;
132
- }
133
- }
134
-
14
+ */
135
15
 
136
16
 
137
17
 
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAQD,MAAM,qCAAe,OAAO,GAAG,CAAC;AAChC,MAAM,sCAAgB,OAAO,GAAG,CAAC;AACjC,IAAI,4CAAuG;AAMpG,MAAM;IAaX,6DAA6D,GAC7D,mBAAmB,GAAM,EAAE,MAAc,EAAK;QAC5C,IAAI,UAAU,IAAI,CAAC,mBAAmB,CAAC;QACvC,IAAI,SAAS,OAAO,CAAC,IAAI;QACzB,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,OAAO,OAAO,CAAC;QAG1E,OAAO;IACT;IAEA,wDAAwD,GACxD,oBAAoB,MAAc,EAAgB;QAChD,IAAI,UAAU,IAAI,CAAC,OAAO,CAAC,OAAO;QAClC,IAAI,CAAC,SAAS;YACZ,UAAU,0CAAoB,QAAQ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G,CAAC,IAAI,CAAC,MAAM,EAAE;QACrC;QACA,OAAO,aAAa,MAAM,CAAC;IAC7B;IAEU,OAAO,OAAuC,EAAE,KAAa,EAAE;QACvE,IAAI,MAAM,OAAO,CAAC,MAAM,IAAI,QAAQ,KAAK;QACzC,OAAO,OAAO,QAAQ,aAAa,QAAQ;IAC7C;IAzCA,YAAY,MAAc,EAAE,OAAwC,CAAE;QACpE,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,OAAO,GAAG;IACjB;AAuCF;","sources":["packages/@internationalized/string/src/index.ts","packages/@internationalized/string/src/LocalizedStringDictionary.ts","packages/@internationalized/string/src/LocalizedStringFormatter.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {Variables, LocalizedString} from './LocalizedStringFormatter';\nexport type {LocalizedStrings} from './LocalizedStringDictionary';\nexport {LocalizedStringDictionary} from './LocalizedStringDictionary';\nexport {LocalizedStringFormatter} from './LocalizedStringFormatter';\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedString} from './LocalizedStringFormatter';\n\nexport type LocalizedStrings<K extends string, T extends LocalizedString> = {\n [lang: string]: Record<K, T>\n};\n\nconst localeSymbol = Symbol.for('react-aria.i18n.locale');\nconst stringsSymbol = Symbol.for('react-aria.i18n.strings');\nlet cachedGlobalStrings: {[packageName: string]: LocalizedStringDictionary<any, any>} | null | undefined = undefined;\n\n/**\n * Stores a mapping of localized strings. Can be used to find the\n * closest available string for a given locale.\n */\nexport class LocalizedStringDictionary<K extends string = string, T extends LocalizedString = string> {\n private strings: LocalizedStrings<K, T>;\n private defaultLocale: string;\n\n constructor(messages: LocalizedStrings<K, T>, defaultLocale: string = 'en-US') {\n // Clone messages so we don't modify the original object.\n // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.\n this.strings = Object.fromEntries(\n Object.entries(messages).filter(([, v]) => v)\n );\n this.defaultLocale = defaultLocale;\n }\n\n /** Returns a localized string for the given key and locale. */\n getStringForLocale(key: K, locale: string): T {\n let strings = this.getStringsForLocale(locale);\n let string = strings[key];\n if (!string) {\n throw new Error(`Could not find intl message ${key} in ${locale} locale`);\n }\n\n return string;\n }\n\n /** Returns all localized strings for the given locale. */\n getStringsForLocale(locale: string): Record<K, T> {\n let strings = this.strings[locale];\n if (!strings) {\n strings = getStringsForLocale(locale, this.strings, this.defaultLocale);\n this.strings[locale] = strings;\n }\n\n return strings;\n }\n\n static getGlobalDictionaryForPackage<K extends string = string, T extends LocalizedString = string>(packageName: string): LocalizedStringDictionary<K, T> | null {\n if (typeof window === 'undefined') {\n return null;\n }\n\n let locale = window[localeSymbol];\n if (cachedGlobalStrings === undefined) {\n let globalStrings = window[stringsSymbol];\n if (!globalStrings) {\n return null;\n }\n\n cachedGlobalStrings = {};\n for (let pkg in globalStrings) {\n cachedGlobalStrings[pkg] = new LocalizedStringDictionary({[locale]: globalStrings[pkg]}, locale);\n }\n }\n\n let dictionary = cachedGlobalStrings?.[packageName];\n if (!dictionary) {\n throw new Error(`Strings for package \"${packageName}\" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`);\n }\n\n return dictionary;\n }\n}\n\nfunction getStringsForLocale<K extends string, T extends LocalizedString>(locale: string, strings: LocalizedStrings<K, T>, defaultLocale = 'en-US') {\n // If there is an exact match, use it.\n if (strings[locale]) {\n return strings[locale];\n }\n\n // Attempt to find the closest match by language.\n // For example, if the locale is fr-CA (French Canadian), but there is only\n // an fr-FR (France) set of strings, use that.\n // This could be replaced with Intl.LocaleMatcher once it is supported.\n // https://github.com/tc39/proposal-intl-localematcher\n let language = getLanguage(locale);\n if (strings[language]) {\n return strings[language];\n }\n\n for (let key in strings) {\n if (key.startsWith(language + '-')) {\n return strings[key];\n }\n }\n\n // Nothing close, use english.\n return strings[defaultLocale];\n}\n\nfunction getLanguage(locale: string) {\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n return new Intl.Locale(locale).language;\n }\n\n return locale.split('-')[0];\n}\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedStringDictionary} from './LocalizedStringDictionary';\n\nexport type Variables = Record<string, string | number | boolean> | undefined;\nexport type LocalizedString = string | ((args: Variables, formatter?: LocalizedStringFormatter<any, any>) => string);\ntype InternalString = string | (() => string);\n\nconst pluralRulesCache = new Map<string, Intl.PluralRules>();\nconst numberFormatCache = new Map<string, Intl.NumberFormat>();\n\n/**\n * Formats localized strings from a LocalizedStringDictionary. Supports interpolating variables,\n * selecting the correct pluralization, and formatting numbers for the locale.\n */\nexport class LocalizedStringFormatter<K extends string = string, T extends LocalizedString = string> {\n private locale: string;\n private strings: LocalizedStringDictionary<K, T>;\n\n constructor(locale: string, strings: LocalizedStringDictionary<K, T>) {\n this.locale = locale;\n this.strings = strings;\n }\n\n /** Formats a localized string for the given key with the provided variables. */\n format(key: K, variables?: Variables): string {\n let message = this.strings.getStringForLocale(key, this.locale);\n return typeof message === 'function' ? message(variables, this) : message;\n }\n\n protected plural(count: number, options: Record<string, InternalString>, type: Intl.PluralRuleType = 'cardinal') {\n let opt = options['=' + count];\n if (opt) {\n return typeof opt === 'function' ? opt() : opt;\n }\n\n let key = this.locale + ':' + type;\n let pluralRules = pluralRulesCache.get(key);\n if (!pluralRules) {\n pluralRules = new Intl.PluralRules(this.locale, {type});\n pluralRulesCache.set(key, pluralRules);\n }\n\n let selected = pluralRules.select(count);\n opt = options[selected] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n\n protected number(value: number) {\n let numberFormat = numberFormatCache.get(this.locale);\n if (!numberFormat) {\n numberFormat = new Intl.NumberFormat(this.locale);\n numberFormatCache.set(this.locale, numberFormat);\n }\n return numberFormat.format(value);\n }\n\n protected select(options: Record<string, InternalString>, value: string) {\n let opt = options[value] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@internationalized/string/src/index.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {Variables, LocalizedString} from './LocalizedStringFormatter';\nexport type {LocalizedStrings} from './LocalizedStringDictionary';\nexport {LocalizedStringDictionary} from './LocalizedStringDictionary';\nexport {LocalizedStringFormatter} from './LocalizedStringFormatter';\n"],"names":[],"version":3,"file":"module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internationalized/string",
3
- "version": "3.2.2-nightly.4552+64ed13090",
3
+ "version": "3.2.2-nightly.4558+c5e4b3701",
4
4
  "description": "Internationalized string formatting and locale negotiation",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -27,5 +27,5 @@
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "64ed13090ce77cc0e4cb4cd5602e75f655bff6bb"
30
+ "gitHead": "c5e4b3701fdb89eb551f1b3697ac253f06ef68fa"
31
31
  }