@internationalized/message 3.1.3-nightly.4552 → 3.1.3-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,59 @@
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, "MessageDictionary", () => $9a5a7b8408290694$export$64839e615120df17);
7
+ /*
8
+ * Copyright 2020 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
+ */ class $9a5a7b8408290694$export$64839e615120df17 {
18
+ getStringForLocale(key, locale) {
19
+ let strings = this.messages[locale];
20
+ if (!strings) {
21
+ strings = $9a5a7b8408290694$var$getStringsForLocale(locale, this.messages, this.defaultLocale);
22
+ this.messages[locale] = strings;
23
+ }
24
+ let string = strings[key];
25
+ if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
26
+ return string;
27
+ }
28
+ constructor(messages, defaultLocale = "en-US"){
29
+ // Clone messages so we don't modify the original object.
30
+ // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
31
+ this.messages = Object.fromEntries(Object.entries(messages).filter(([, v])=>v));
32
+ this.defaultLocale = defaultLocale;
33
+ }
34
+ }
35
+ function $9a5a7b8408290694$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
36
+ // If there is an exact match, use it.
37
+ if (strings[locale]) return strings[locale];
38
+ // Attempt to find the closest match by language.
39
+ // For example, if the locale is fr-CA (French Canadian), but there is only
40
+ // an fr-FR (France) set of strings, use that.
41
+ // This could be replaced with Intl.LocaleMatcher once it is supported.
42
+ // https://github.com/tc39/proposal-intl-localematcher
43
+ let language = $9a5a7b8408290694$var$getLanguage(locale);
44
+ if (strings[language]) return strings[language];
45
+ for(let key in strings){
46
+ if (key.startsWith(language + "-")) return strings[key];
47
+ }
48
+ // Nothing close, use english.
49
+ return strings[defaultLocale];
50
+ }
51
+ function $9a5a7b8408290694$var$getLanguage(locale) {
52
+ // @ts-ignore
53
+ if (Intl.Locale) // @ts-ignore
54
+ return new Intl.Locale(locale).language;
55
+ return locale.split("-")[0];
56
+ }
57
+
58
+
59
+ //# sourceMappingURL=MessageDictionary.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAYM,MAAM;IAaX,mBAAmB,GAAW,EAAE,MAAc,EAAE;QAC9C,IAAI,UAAU,IAAI,CAAC,QAAQ,CAAC,OAAO;QACnC,IAAI,CAAC,SAAS;YACZ,UAAU,0CAAoB,QAAQ,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa;YACvE,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG;QAC1B;QAEA,IAAI,SAAS,OAAO,CAAC,IAAI;QACzB,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,OAAO,OAAO,CAAC;QAG1E,OAAO;IACT;IAtBA,YAAY,QAA0B,EAAE,gBAAwB,OAAO,CAAE;QACvE,yDAAyD;QACzD,uGAAuG;QACvG,IAAI,CAAC,QAAQ,GAAG,OAAO,WAAW,CAChC,OAAO,OAAO,CAAC,UAAU,MAAM,CAAC,CAAC,GAAG,EAAE,GAAK;QAE7C,IAAI,CAAC,aAAa,GAAG;IACvB;AAgBF;AAEA,SAAS,0CAAoB,MAAc,EAAE,OAAyB,EAAE,gBAAgB,OAAO;IAC7F,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/message/src/MessageDictionary.ts"],"sourcesContent":["/*\n * Copyright 2020 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 LocalizedStrings = {\n [lang: string]: {\n [key: string]: string\n }\n};\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 MessageDictionary {\n private messages: LocalizedStrings;\n private defaultLocale: string;\n\n constructor(messages: LocalizedStrings, 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.messages = Object.fromEntries(\n Object.entries(messages).filter(([, v]) => v)\n );\n this.defaultLocale = defaultLocale;\n }\n\n getStringForLocale(key: string, locale: string) {\n let strings = this.messages[locale];\n if (!strings) {\n strings = getStringsForLocale(locale, this.messages, this.defaultLocale);\n this.messages[locale] = strings;\n }\n\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\nfunction getStringsForLocale(locale: string, strings: LocalizedStrings, 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":"MessageDictionary.main.js.map"}
@@ -0,0 +1,54 @@
1
+ /*
2
+ * Copyright 2020 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
+ */ class $d6fd23bc337660df$export$64839e615120df17 {
12
+ getStringForLocale(key, locale) {
13
+ let strings = this.messages[locale];
14
+ if (!strings) {
15
+ strings = $d6fd23bc337660df$var$getStringsForLocale(locale, this.messages, this.defaultLocale);
16
+ this.messages[locale] = strings;
17
+ }
18
+ let string = strings[key];
19
+ if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
20
+ return string;
21
+ }
22
+ constructor(messages, defaultLocale = "en-US"){
23
+ // Clone messages so we don't modify the original object.
24
+ // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
25
+ this.messages = Object.fromEntries(Object.entries(messages).filter(([, v])=>v));
26
+ this.defaultLocale = defaultLocale;
27
+ }
28
+ }
29
+ function $d6fd23bc337660df$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
30
+ // If there is an exact match, use it.
31
+ if (strings[locale]) return strings[locale];
32
+ // Attempt to find the closest match by language.
33
+ // For example, if the locale is fr-CA (French Canadian), but there is only
34
+ // an fr-FR (France) set of strings, use that.
35
+ // This could be replaced with Intl.LocaleMatcher once it is supported.
36
+ // https://github.com/tc39/proposal-intl-localematcher
37
+ let language = $d6fd23bc337660df$var$getLanguage(locale);
38
+ if (strings[language]) return strings[language];
39
+ for(let key in strings){
40
+ if (key.startsWith(language + "-")) return strings[key];
41
+ }
42
+ // Nothing close, use english.
43
+ return strings[defaultLocale];
44
+ }
45
+ function $d6fd23bc337660df$var$getLanguage(locale) {
46
+ // @ts-ignore
47
+ if (Intl.Locale) // @ts-ignore
48
+ return new Intl.Locale(locale).language;
49
+ return locale.split("-")[0];
50
+ }
51
+
52
+
53
+ export {$d6fd23bc337660df$export$64839e615120df17 as MessageDictionary};
54
+ //# sourceMappingURL=MessageDictionary.mjs.map
@@ -0,0 +1,54 @@
1
+ /*
2
+ * Copyright 2020 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
+ */ class $d6fd23bc337660df$export$64839e615120df17 {
12
+ getStringForLocale(key, locale) {
13
+ let strings = this.messages[locale];
14
+ if (!strings) {
15
+ strings = $d6fd23bc337660df$var$getStringsForLocale(locale, this.messages, this.defaultLocale);
16
+ this.messages[locale] = strings;
17
+ }
18
+ let string = strings[key];
19
+ if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
20
+ return string;
21
+ }
22
+ constructor(messages, defaultLocale = "en-US"){
23
+ // Clone messages so we don't modify the original object.
24
+ // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
25
+ this.messages = Object.fromEntries(Object.entries(messages).filter(([, v])=>v));
26
+ this.defaultLocale = defaultLocale;
27
+ }
28
+ }
29
+ function $d6fd23bc337660df$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
30
+ // If there is an exact match, use it.
31
+ if (strings[locale]) return strings[locale];
32
+ // Attempt to find the closest match by language.
33
+ // For example, if the locale is fr-CA (French Canadian), but there is only
34
+ // an fr-FR (France) set of strings, use that.
35
+ // This could be replaced with Intl.LocaleMatcher once it is supported.
36
+ // https://github.com/tc39/proposal-intl-localematcher
37
+ let language = $d6fd23bc337660df$var$getLanguage(locale);
38
+ if (strings[language]) return strings[language];
39
+ for(let key in strings){
40
+ if (key.startsWith(language + "-")) return strings[key];
41
+ }
42
+ // Nothing close, use english.
43
+ return strings[defaultLocale];
44
+ }
45
+ function $d6fd23bc337660df$var$getLanguage(locale) {
46
+ // @ts-ignore
47
+ if (Intl.Locale) // @ts-ignore
48
+ return new Intl.Locale(locale).language;
49
+ return locale.split("-")[0];
50
+ }
51
+
52
+
53
+ export {$d6fd23bc337660df$export$64839e615120df17 as MessageDictionary};
54
+ //# sourceMappingURL=MessageDictionary.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAYM,MAAM;IAaX,mBAAmB,GAAW,EAAE,MAAc,EAAE;QAC9C,IAAI,UAAU,IAAI,CAAC,QAAQ,CAAC,OAAO;QACnC,IAAI,CAAC,SAAS;YACZ,UAAU,0CAAoB,QAAQ,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa;YACvE,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG;QAC1B;QAEA,IAAI,SAAS,OAAO,CAAC,IAAI;QACzB,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,OAAO,OAAO,CAAC;QAG1E,OAAO;IACT;IAtBA,YAAY,QAA0B,EAAE,gBAAwB,OAAO,CAAE;QACvE,yDAAyD;QACzD,uGAAuG;QACvG,IAAI,CAAC,QAAQ,GAAG,OAAO,WAAW,CAChC,OAAO,OAAO,CAAC,UAAU,MAAM,CAAC,CAAC,GAAG,EAAE,GAAK;QAE7C,IAAI,CAAC,aAAa,GAAG;IACvB;AAgBF;AAEA,SAAS,0CAAoB,MAAc,EAAE,OAAyB,EAAE,gBAAgB,OAAO;IAC7F,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/message/src/MessageDictionary.ts"],"sourcesContent":["/*\n * Copyright 2020 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 LocalizedStrings = {\n [lang: string]: {\n [key: string]: string\n }\n};\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 MessageDictionary {\n private messages: LocalizedStrings;\n private defaultLocale: string;\n\n constructor(messages: LocalizedStrings, 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.messages = Object.fromEntries(\n Object.entries(messages).filter(([, v]) => v)\n );\n this.defaultLocale = defaultLocale;\n }\n\n getStringForLocale(key: string, locale: string) {\n let strings = this.messages[locale];\n if (!strings) {\n strings = getStringsForLocale(locale, this.messages, this.defaultLocale);\n this.messages[locale] = strings;\n }\n\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\nfunction getStringsForLocale(locale: string, strings: LocalizedStrings, 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":"MessageDictionary.module.js.map"}
@@ -0,0 +1,48 @@
1
+ var $f4V3v$intlmessageformat = require("intl-messageformat");
2
+
3
+
4
+ function $parcel$interopDefault(a) {
5
+ return a && a.__esModule ? a.default : a;
6
+ }
7
+
8
+ function $parcel$export(e, n, v, s) {
9
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
10
+ }
11
+
12
+ $parcel$export(module.exports, "MessageFormatter", () => $7a31ee9993c13f0b$export$526ebc05ff964723);
13
+ /*
14
+ * Copyright 2020 Adobe. All rights reserved.
15
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License. You may obtain a copy
17
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software distributed under
20
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
+ * OF ANY KIND, either express or implied. See the License for the specific language
22
+ * governing permissions and limitations under the License.
23
+ */
24
+ class $7a31ee9993c13f0b$export$526ebc05ff964723 {
25
+ format(key, variables) {
26
+ let message = this.cache[key];
27
+ if (!message) {
28
+ let msg = this.messages.getStringForLocale(key, this.locale);
29
+ if (!msg) throw new Error(`Could not find intl message ${key} in ${this.locale} locale`);
30
+ message = new (0, ($parcel$interopDefault($f4V3v$intlmessageformat)))(msg, this.locale);
31
+ this.cache[key] = message;
32
+ }
33
+ let varCopy;
34
+ if (variables) varCopy = Object.keys(variables).reduce((acc, key)=>{
35
+ acc[key] = variables[key] == null ? false : variables[key];
36
+ return acc;
37
+ }, {});
38
+ return message.format(varCopy);
39
+ }
40
+ constructor(locale, messages){
41
+ this.locale = locale;
42
+ this.messages = messages;
43
+ this.cache = {};
44
+ }
45
+ }
46
+
47
+
48
+ //# sourceMappingURL=MessageFormatter.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AASM,MAAM;IAWX,OAAiB,GAAW,EAAE,SAA6G,EAAE;QAC3I,IAAI,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI;QAC7B,IAAI,CAAC,SAAS;YACZ,IAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC,MAAM;YAC3D,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YAG/E,UAAU,IAAI,CAAA,GAAA,kDAAgB,EAAE,KAAK,IAAI,CAAC,MAAM;YAChD,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG;QACpB;QACA,IAAI;QACJ,IAAI,WACF,UAAU,OAAO,IAAI,CAAC,WAAW,MAAM,CAAC,CAAC,KAAK;YAC5C,GAAG,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,IAAI,OAAO,QAAQ,SAAS,CAAC,IAAI;YAC1D,OAAO;QACT,GAAG,CAAC;QAGN,OAAO,QAAQ,MAAM,CAAC;IACxB;IA1BA,YAAY,MAAc,EAAE,QAA2B,CAAE;QACvD,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,KAAK,GAAG,CAAC;IAChB;AAuBF","sources":["packages/@internationalized/message/src/MessageFormatter.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {FormatXMLElementFn, PrimitiveType} from 'intl-messageformat/src/formatters';\nimport IntlMessageFormat from 'intl-messageformat';\nimport {MessageDictionary} from './MessageDictionary';\n\n/**\n * Formats ICU Message strings to create localized strings from a MessageDictionary.\n */\nexport class MessageFormatter {\n private locale: string;\n private messages: MessageDictionary;\n private cache: {[key: string]: IntlMessageFormat};\n\n constructor(locale: string, messages: MessageDictionary) {\n this.locale = locale;\n this.messages = messages;\n this.cache = {};\n }\n\n format<T = void>(key: string, variables: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined) {\n let message = this.cache[key];\n if (!message) {\n let msg = this.messages.getStringForLocale(key, this.locale);\n if (!msg) {\n throw new Error(`Could not find intl message ${key} in ${this.locale} locale`);\n }\n\n message = new IntlMessageFormat(msg, this.locale);\n this.cache[key] = message;\n }\n let varCopy: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined;\n if (variables) {\n varCopy = Object.keys(variables).reduce((acc, key) => {\n acc[key] = variables[key] == null ? false : variables[key];\n return acc;\n }, {});\n }\n\n return message.format(varCopy);\n }\n}\n"],"names":[],"version":3,"file":"MessageFormatter.main.js.map"}
@@ -0,0 +1,39 @@
1
+ import $9UXlH$intlmessageformat from "intl-messageformat";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ class $972eb555d604f491$export$526ebc05ff964723 {
15
+ format(key, variables) {
16
+ let message = this.cache[key];
17
+ if (!message) {
18
+ let msg = this.messages.getStringForLocale(key, this.locale);
19
+ if (!msg) throw new Error(`Could not find intl message ${key} in ${this.locale} locale`);
20
+ message = new (0, $9UXlH$intlmessageformat)(msg, this.locale);
21
+ this.cache[key] = message;
22
+ }
23
+ let varCopy;
24
+ if (variables) varCopy = Object.keys(variables).reduce((acc, key)=>{
25
+ acc[key] = variables[key] == null ? false : variables[key];
26
+ return acc;
27
+ }, {});
28
+ return message.format(varCopy);
29
+ }
30
+ constructor(locale, messages){
31
+ this.locale = locale;
32
+ this.messages = messages;
33
+ this.cache = {};
34
+ }
35
+ }
36
+
37
+
38
+ export {$972eb555d604f491$export$526ebc05ff964723 as MessageFormatter};
39
+ //# sourceMappingURL=MessageFormatter.mjs.map
@@ -0,0 +1,39 @@
1
+ import $9UXlH$intlmessageformat from "intl-messageformat";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ class $972eb555d604f491$export$526ebc05ff964723 {
15
+ format(key, variables) {
16
+ let message = this.cache[key];
17
+ if (!message) {
18
+ let msg = this.messages.getStringForLocale(key, this.locale);
19
+ if (!msg) throw new Error(`Could not find intl message ${key} in ${this.locale} locale`);
20
+ message = new (0, $9UXlH$intlmessageformat)(msg, this.locale);
21
+ this.cache[key] = message;
22
+ }
23
+ let varCopy;
24
+ if (variables) varCopy = Object.keys(variables).reduce((acc, key)=>{
25
+ acc[key] = variables[key] == null ? false : variables[key];
26
+ return acc;
27
+ }, {});
28
+ return message.format(varCopy);
29
+ }
30
+ constructor(locale, messages){
31
+ this.locale = locale;
32
+ this.messages = messages;
33
+ this.cache = {};
34
+ }
35
+ }
36
+
37
+
38
+ export {$972eb555d604f491$export$526ebc05ff964723 as MessageFormatter};
39
+ //# sourceMappingURL=MessageFormatter.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AASM,MAAM;IAWX,OAAiB,GAAW,EAAE,SAA6G,EAAE;QAC3I,IAAI,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI;QAC7B,IAAI,CAAC,SAAS;YACZ,IAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC,MAAM;YAC3D,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YAG/E,UAAU,IAAI,CAAA,GAAA,wBAAgB,EAAE,KAAK,IAAI,CAAC,MAAM;YAChD,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG;QACpB;QACA,IAAI;QACJ,IAAI,WACF,UAAU,OAAO,IAAI,CAAC,WAAW,MAAM,CAAC,CAAC,KAAK;YAC5C,GAAG,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,IAAI,OAAO,QAAQ,SAAS,CAAC,IAAI;YAC1D,OAAO;QACT,GAAG,CAAC;QAGN,OAAO,QAAQ,MAAM,CAAC;IACxB;IA1BA,YAAY,MAAc,EAAE,QAA2B,CAAE;QACvD,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,KAAK,GAAG,CAAC;IAChB;AAuBF","sources":["packages/@internationalized/message/src/MessageFormatter.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {FormatXMLElementFn, PrimitiveType} from 'intl-messageformat/src/formatters';\nimport IntlMessageFormat from 'intl-messageformat';\nimport {MessageDictionary} from './MessageDictionary';\n\n/**\n * Formats ICU Message strings to create localized strings from a MessageDictionary.\n */\nexport class MessageFormatter {\n private locale: string;\n private messages: MessageDictionary;\n private cache: {[key: string]: IntlMessageFormat};\n\n constructor(locale: string, messages: MessageDictionary) {\n this.locale = locale;\n this.messages = messages;\n this.cache = {};\n }\n\n format<T = void>(key: string, variables: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined) {\n let message = this.cache[key];\n if (!message) {\n let msg = this.messages.getStringForLocale(key, this.locale);\n if (!msg) {\n throw new Error(`Could not find intl message ${key} in ${this.locale} locale`);\n }\n\n message = new IntlMessageFormat(msg, this.locale);\n this.cache[key] = message;\n }\n let varCopy: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined;\n if (variables) {\n varCopy = Object.keys(variables).reduce((acc, key) => {\n acc[key] = variables[key] == null ? false : variables[key];\n return acc;\n }, {});\n }\n\n return message.format(varCopy);\n }\n}\n"],"names":[],"version":3,"file":"MessageFormatter.module.js.map"}
package/dist/import.mjs CHANGED
@@ -1,66 +1,5 @@
1
- import $1DoQa$intlmessageformat from "intl-messageformat";
2
-
3
- /*
4
- * Copyright 2020 Adobe. All rights reserved.
5
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License. You may obtain a copy
7
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software distributed under
10
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
- * OF ANY KIND, either express or implied. See the License for the specific language
12
- * governing permissions and limitations under the License.
13
- */ /*
14
- * Copyright 2020 Adobe. All rights reserved.
15
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
- * you may not use this file except in compliance with the License. You may obtain a copy
17
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software distributed under
20
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
- * OF ANY KIND, either express or implied. See the License for the specific language
22
- * governing permissions and limitations under the License.
23
- */ class $d6fd23bc337660df$export$64839e615120df17 {
24
- getStringForLocale(key, locale) {
25
- let strings = this.messages[locale];
26
- if (!strings) {
27
- strings = $d6fd23bc337660df$var$getStringsForLocale(locale, this.messages, this.defaultLocale);
28
- this.messages[locale] = strings;
29
- }
30
- let string = strings[key];
31
- if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
32
- return string;
33
- }
34
- constructor(messages, defaultLocale = "en-US"){
35
- // Clone messages so we don't modify the original object.
36
- // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
37
- this.messages = Object.fromEntries(Object.entries(messages).filter(([, v])=>v));
38
- this.defaultLocale = defaultLocale;
39
- }
40
- }
41
- function $d6fd23bc337660df$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
42
- // If there is an exact match, use it.
43
- if (strings[locale]) return strings[locale];
44
- // Attempt to find the closest match by language.
45
- // For example, if the locale is fr-CA (French Canadian), but there is only
46
- // an fr-FR (France) set of strings, use that.
47
- // This could be replaced with Intl.LocaleMatcher once it is supported.
48
- // https://github.com/tc39/proposal-intl-localematcher
49
- let language = $d6fd23bc337660df$var$getLanguage(locale);
50
- if (strings[language]) return strings[language];
51
- for(let key in strings){
52
- if (key.startsWith(language + "-")) return strings[key];
53
- }
54
- // Nothing close, use english.
55
- return strings[defaultLocale];
56
- }
57
- function $d6fd23bc337660df$var$getLanguage(locale) {
58
- // @ts-ignore
59
- if (Intl.Locale) // @ts-ignore
60
- return new Intl.Locale(locale).language;
61
- return locale.split("-")[0];
62
- }
63
-
1
+ import {MessageDictionary as $d6fd23bc337660df$export$64839e615120df17} from "./MessageDictionary.mjs";
2
+ import {MessageFormatter as $972eb555d604f491$export$526ebc05ff964723} from "./MessageFormatter.mjs";
64
3
 
65
4
  /*
66
5
  * Copyright 2020 Adobe. All rights reserved.
@@ -73,29 +12,6 @@ function $d6fd23bc337660df$var$getLanguage(locale) {
73
12
  * OF ANY KIND, either express or implied. See the License for the specific language
74
13
  * governing permissions and limitations under the License.
75
14
  */
76
- class $972eb555d604f491$export$526ebc05ff964723 {
77
- format(key, variables) {
78
- let message = this.cache[key];
79
- if (!message) {
80
- let msg = this.messages.getStringForLocale(key, this.locale);
81
- if (!msg) throw new Error(`Could not find intl message ${key} in ${this.locale} locale`);
82
- message = new (0, $1DoQa$intlmessageformat)(msg, this.locale);
83
- this.cache[key] = message;
84
- }
85
- let varCopy;
86
- if (variables) varCopy = Object.keys(variables).reduce((acc, key)=>{
87
- acc[key] = variables[key] == null ? false : variables[key];
88
- return acc;
89
- }, {});
90
- return message.format(varCopy);
91
- }
92
- constructor(locale, messages){
93
- this.locale = locale;
94
- this.messages = messages;
95
- this.cache = {};
96
- }
97
- }
98
-
99
15
 
100
16
 
101
17
 
package/dist/main.js CHANGED
@@ -1,78 +1,13 @@
1
- var $g9nQA$intlmessageformat = require("intl-messageformat");
1
+ var $9a5a7b8408290694$exports = require("./MessageDictionary.main.js");
2
+ var $7a31ee9993c13f0b$exports = require("./MessageFormatter.main.js");
2
3
 
3
4
 
4
5
  function $parcel$export(e, n, v, s) {
5
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
7
  }
7
8
 
8
- function $parcel$interopDefault(a) {
9
- return a && a.__esModule ? a.default : a;
10
- }
11
-
12
- $parcel$export(module.exports, "MessageDictionary", () => $9a5a7b8408290694$export$64839e615120df17);
13
- $parcel$export(module.exports, "MessageFormatter", () => $7a31ee9993c13f0b$export$526ebc05ff964723);
14
- /*
15
- * Copyright 2020 Adobe. All rights reserved.
16
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
17
- * you may not use this file except in compliance with the License. You may obtain a copy
18
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software distributed under
21
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
22
- * OF ANY KIND, either express or implied. See the License for the specific language
23
- * governing permissions and limitations under the License.
24
- */ /*
25
- * Copyright 2020 Adobe. All rights reserved.
26
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
27
- * you may not use this file except in compliance with the License. You may obtain a copy
28
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
29
- *
30
- * Unless required by applicable law or agreed to in writing, software distributed under
31
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
32
- * OF ANY KIND, either express or implied. See the License for the specific language
33
- * governing permissions and limitations under the License.
34
- */ class $9a5a7b8408290694$export$64839e615120df17 {
35
- getStringForLocale(key, locale) {
36
- let strings = this.messages[locale];
37
- if (!strings) {
38
- strings = $9a5a7b8408290694$var$getStringsForLocale(locale, this.messages, this.defaultLocale);
39
- this.messages[locale] = strings;
40
- }
41
- let string = strings[key];
42
- if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
43
- return string;
44
- }
45
- constructor(messages, defaultLocale = "en-US"){
46
- // Clone messages so we don't modify the original object.
47
- // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
48
- this.messages = Object.fromEntries(Object.entries(messages).filter(([, v])=>v));
49
- this.defaultLocale = defaultLocale;
50
- }
51
- }
52
- function $9a5a7b8408290694$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
53
- // If there is an exact match, use it.
54
- if (strings[locale]) return strings[locale];
55
- // Attempt to find the closest match by language.
56
- // For example, if the locale is fr-CA (French Canadian), but there is only
57
- // an fr-FR (France) set of strings, use that.
58
- // This could be replaced with Intl.LocaleMatcher once it is supported.
59
- // https://github.com/tc39/proposal-intl-localematcher
60
- let language = $9a5a7b8408290694$var$getLanguage(locale);
61
- if (strings[language]) return strings[language];
62
- for(let key in strings){
63
- if (key.startsWith(language + "-")) return strings[key];
64
- }
65
- // Nothing close, use english.
66
- return strings[defaultLocale];
67
- }
68
- function $9a5a7b8408290694$var$getLanguage(locale) {
69
- // @ts-ignore
70
- if (Intl.Locale) // @ts-ignore
71
- return new Intl.Locale(locale).language;
72
- return locale.split("-")[0];
73
- }
74
-
75
-
9
+ $parcel$export(module.exports, "MessageDictionary", () => $9a5a7b8408290694$exports.MessageDictionary);
10
+ $parcel$export(module.exports, "MessageFormatter", () => $7a31ee9993c13f0b$exports.MessageFormatter);
76
11
  /*
77
12
  * Copyright 2020 Adobe. All rights reserved.
78
13
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -84,29 +19,6 @@ function $9a5a7b8408290694$var$getLanguage(locale) {
84
19
  * OF ANY KIND, either express or implied. See the License for the specific language
85
20
  * governing permissions and limitations under the License.
86
21
  */
87
- class $7a31ee9993c13f0b$export$526ebc05ff964723 {
88
- format(key, variables) {
89
- let message = this.cache[key];
90
- if (!message) {
91
- let msg = this.messages.getStringForLocale(key, this.locale);
92
- if (!msg) throw new Error(`Could not find intl message ${key} in ${this.locale} locale`);
93
- message = new (0, ($parcel$interopDefault($g9nQA$intlmessageformat)))(msg, this.locale);
94
- this.cache[key] = message;
95
- }
96
- let varCopy;
97
- if (variables) varCopy = Object.keys(variables).reduce((acc, key)=>{
98
- acc[key] = variables[key] == null ? false : variables[key];
99
- return acc;
100
- }, {});
101
- return message.format(varCopy);
102
- }
103
- constructor(locale, messages){
104
- this.locale = locale;
105
- this.messages = messages;
106
- this.cache = {};
107
- }
108
- }
109
-
110
22
 
111
23
 
112
24
 
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAYM,MAAM;IAaX,mBAAmB,GAAW,EAAE,MAAc,EAAE;QAC9C,IAAI,UAAU,IAAI,CAAC,QAAQ,CAAC,OAAO;QACnC,IAAI,CAAC,SAAS;YACZ,UAAU,0CAAoB,QAAQ,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa;YACvE,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG;QAC1B;QAEA,IAAI,SAAS,OAAO,CAAC,IAAI;QACzB,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,OAAO,OAAO,CAAC;QAG1E,OAAO;IACT;IAtBA,YAAY,QAA0B,EAAE,gBAAwB,OAAO,CAAE;QACvE,yDAAyD;QACzD,uGAAuG;QACvG,IAAI,CAAC,QAAQ,GAAG,OAAO,WAAW,CAChC,OAAO,OAAO,CAAC,UAAU,MAAM,CAAC,CAAC,GAAG,EAAE,GAAK;QAE7C,IAAI,CAAC,aAAa,GAAG;IACvB;AAgBF;AAEA,SAAS,0CAAoB,MAAc,EAAE,OAAyB,EAAE,gBAAgB,OAAO;IAC7F,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;;CD3EC;AEVD;;;;;;;;;;CAUC;AASM,MAAM;IAWX,OAAiB,GAAW,EAAE,SAA6G,EAAE;QAC3I,IAAI,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI;QAC7B,IAAI,CAAC,SAAS;YACZ,IAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC,MAAM;YAC3D,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YAG/E,UAAU,IAAI,CAAA,GAAA,kDAAgB,EAAE,KAAK,IAAI,CAAC,MAAM;YAChD,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG;QACpB;QACA,IAAI;QACJ,IAAI,WACF,UAAU,OAAO,IAAI,CAAC,WAAW,MAAM,CAAC,CAAC,KAAK;YAC5C,GAAG,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,IAAI,OAAO,QAAQ,SAAS,CAAC,IAAI;YAC1D,OAAO;QACT,GAAG,CAAC;QAGN,OAAO,QAAQ,MAAM,CAAC;IACxB;IA1BA,YAAY,MAAc,EAAE,QAA2B,CAAE;QACvD,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,KAAK,GAAG,CAAC;IAChB;AAuBF;","sources":["packages/@internationalized/message/src/index.ts","packages/@internationalized/message/src/MessageDictionary.ts","packages/@internationalized/message/src/MessageFormatter.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {LocalizedStrings} from './MessageDictionary';\nexport {MessageDictionary} from './MessageDictionary';\nexport {MessageFormatter} from './MessageFormatter';\n","/*\n * Copyright 2020 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 LocalizedStrings = {\n [lang: string]: {\n [key: string]: string\n }\n};\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 MessageDictionary {\n private messages: LocalizedStrings;\n private defaultLocale: string;\n\n constructor(messages: LocalizedStrings, 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.messages = Object.fromEntries(\n Object.entries(messages).filter(([, v]) => v)\n );\n this.defaultLocale = defaultLocale;\n }\n\n getStringForLocale(key: string, locale: string) {\n let strings = this.messages[locale];\n if (!strings) {\n strings = getStringsForLocale(locale, this.messages, this.defaultLocale);\n this.messages[locale] = strings;\n }\n\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\nfunction getStringsForLocale(locale: string, strings: LocalizedStrings, 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 2020 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 {FormatXMLElementFn, PrimitiveType} from 'intl-messageformat/src/formatters';\nimport IntlMessageFormat from 'intl-messageformat';\nimport {MessageDictionary} from './MessageDictionary';\n\n/**\n * Formats ICU Message strings to create localized strings from a MessageDictionary.\n */\nexport class MessageFormatter {\n private locale: string;\n private messages: MessageDictionary;\n private cache: {[key: string]: IntlMessageFormat};\n\n constructor(locale: string, messages: MessageDictionary) {\n this.locale = locale;\n this.messages = messages;\n this.cache = {};\n }\n\n format<T = void>(key: string, variables: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined) {\n let message = this.cache[key];\n if (!message) {\n let msg = this.messages.getStringForLocale(key, this.locale);\n if (!msg) {\n throw new Error(`Could not find intl message ${key} in ${this.locale} locale`);\n }\n\n message = new IntlMessageFormat(msg, this.locale);\n this.cache[key] = message;\n }\n let varCopy: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined;\n if (variables) {\n varCopy = Object.keys(variables).reduce((acc, key) => {\n acc[key] = variables[key] == null ? false : variables[key];\n return acc;\n }, {});\n }\n\n return message.format(varCopy);\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@internationalized/message/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {LocalizedStrings} from './MessageDictionary';\nexport {MessageDictionary} from './MessageDictionary';\nexport {MessageFormatter} from './MessageFormatter';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,66 +1,5 @@
1
- import $1DoQa$intlmessageformat from "intl-messageformat";
2
-
3
- /*
4
- * Copyright 2020 Adobe. All rights reserved.
5
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License. You may obtain a copy
7
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software distributed under
10
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
- * OF ANY KIND, either express or implied. See the License for the specific language
12
- * governing permissions and limitations under the License.
13
- */ /*
14
- * Copyright 2020 Adobe. All rights reserved.
15
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
- * you may not use this file except in compliance with the License. You may obtain a copy
17
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software distributed under
20
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
- * OF ANY KIND, either express or implied. See the License for the specific language
22
- * governing permissions and limitations under the License.
23
- */ class $d6fd23bc337660df$export$64839e615120df17 {
24
- getStringForLocale(key, locale) {
25
- let strings = this.messages[locale];
26
- if (!strings) {
27
- strings = $d6fd23bc337660df$var$getStringsForLocale(locale, this.messages, this.defaultLocale);
28
- this.messages[locale] = strings;
29
- }
30
- let string = strings[key];
31
- if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
32
- return string;
33
- }
34
- constructor(messages, defaultLocale = "en-US"){
35
- // Clone messages so we don't modify the original object.
36
- // Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
37
- this.messages = Object.fromEntries(Object.entries(messages).filter(([, v])=>v));
38
- this.defaultLocale = defaultLocale;
39
- }
40
- }
41
- function $d6fd23bc337660df$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
42
- // If there is an exact match, use it.
43
- if (strings[locale]) return strings[locale];
44
- // Attempt to find the closest match by language.
45
- // For example, if the locale is fr-CA (French Canadian), but there is only
46
- // an fr-FR (France) set of strings, use that.
47
- // This could be replaced with Intl.LocaleMatcher once it is supported.
48
- // https://github.com/tc39/proposal-intl-localematcher
49
- let language = $d6fd23bc337660df$var$getLanguage(locale);
50
- if (strings[language]) return strings[language];
51
- for(let key in strings){
52
- if (key.startsWith(language + "-")) return strings[key];
53
- }
54
- // Nothing close, use english.
55
- return strings[defaultLocale];
56
- }
57
- function $d6fd23bc337660df$var$getLanguage(locale) {
58
- // @ts-ignore
59
- if (Intl.Locale) // @ts-ignore
60
- return new Intl.Locale(locale).language;
61
- return locale.split("-")[0];
62
- }
63
-
1
+ import {MessageDictionary as $d6fd23bc337660df$export$64839e615120df17} from "./MessageDictionary.module.js";
2
+ import {MessageFormatter as $972eb555d604f491$export$526ebc05ff964723} from "./MessageFormatter.module.js";
64
3
 
65
4
  /*
66
5
  * Copyright 2020 Adobe. All rights reserved.
@@ -73,29 +12,6 @@ function $d6fd23bc337660df$var$getLanguage(locale) {
73
12
  * OF ANY KIND, either express or implied. See the License for the specific language
74
13
  * governing permissions and limitations under the License.
75
14
  */
76
- class $972eb555d604f491$export$526ebc05ff964723 {
77
- format(key, variables) {
78
- let message = this.cache[key];
79
- if (!message) {
80
- let msg = this.messages.getStringForLocale(key, this.locale);
81
- if (!msg) throw new Error(`Could not find intl message ${key} in ${this.locale} locale`);
82
- message = new (0, $1DoQa$intlmessageformat)(msg, this.locale);
83
- this.cache[key] = message;
84
- }
85
- let varCopy;
86
- if (variables) varCopy = Object.keys(variables).reduce((acc, key)=>{
87
- acc[key] = variables[key] == null ? false : variables[key];
88
- return acc;
89
- }, {});
90
- return message.format(varCopy);
91
- }
92
- constructor(locale, messages){
93
- this.locale = locale;
94
- this.messages = messages;
95
- this.cache = {};
96
- }
97
- }
98
-
99
15
 
100
16
 
101
17
 
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAYM,MAAM;IAaX,mBAAmB,GAAW,EAAE,MAAc,EAAE;QAC9C,IAAI,UAAU,IAAI,CAAC,QAAQ,CAAC,OAAO;QACnC,IAAI,CAAC,SAAS;YACZ,UAAU,0CAAoB,QAAQ,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa;YACvE,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG;QAC1B;QAEA,IAAI,SAAS,OAAO,CAAC,IAAI;QACzB,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,OAAO,OAAO,CAAC;QAG1E,OAAO;IACT;IAtBA,YAAY,QAA0B,EAAE,gBAAwB,OAAO,CAAE;QACvE,yDAAyD;QACzD,uGAAuG;QACvG,IAAI,CAAC,QAAQ,GAAG,OAAO,WAAW,CAChC,OAAO,OAAO,CAAC,UAAU,MAAM,CAAC,CAAC,GAAG,EAAE,GAAK;QAE7C,IAAI,CAAC,aAAa,GAAG;IACvB;AAgBF;AAEA,SAAS,0CAAoB,MAAc,EAAE,OAAyB,EAAE,gBAAgB,OAAO;IAC7F,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;;CD3EC;AEVD;;;;;;;;;;CAUC;AASM,MAAM;IAWX,OAAiB,GAAW,EAAE,SAA6G,EAAE;QAC3I,IAAI,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI;QAC7B,IAAI,CAAC,SAAS;YACZ,IAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC,MAAM;YAC3D,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YAG/E,UAAU,IAAI,CAAA,GAAA,wBAAgB,EAAE,KAAK,IAAI,CAAC,MAAM;YAChD,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG;QACpB;QACA,IAAI;QACJ,IAAI,WACF,UAAU,OAAO,IAAI,CAAC,WAAW,MAAM,CAAC,CAAC,KAAK;YAC5C,GAAG,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,IAAI,OAAO,QAAQ,SAAS,CAAC,IAAI;YAC1D,OAAO;QACT,GAAG,CAAC;QAGN,OAAO,QAAQ,MAAM,CAAC;IACxB;IA1BA,YAAY,MAAc,EAAE,QAA2B,CAAE;QACvD,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,KAAK,GAAG,CAAC;IAChB;AAuBF;","sources":["packages/@internationalized/message/src/index.ts","packages/@internationalized/message/src/MessageDictionary.ts","packages/@internationalized/message/src/MessageFormatter.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {LocalizedStrings} from './MessageDictionary';\nexport {MessageDictionary} from './MessageDictionary';\nexport {MessageFormatter} from './MessageFormatter';\n","/*\n * Copyright 2020 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 LocalizedStrings = {\n [lang: string]: {\n [key: string]: string\n }\n};\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 MessageDictionary {\n private messages: LocalizedStrings;\n private defaultLocale: string;\n\n constructor(messages: LocalizedStrings, 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.messages = Object.fromEntries(\n Object.entries(messages).filter(([, v]) => v)\n );\n this.defaultLocale = defaultLocale;\n }\n\n getStringForLocale(key: string, locale: string) {\n let strings = this.messages[locale];\n if (!strings) {\n strings = getStringsForLocale(locale, this.messages, this.defaultLocale);\n this.messages[locale] = strings;\n }\n\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\nfunction getStringsForLocale(locale: string, strings: LocalizedStrings, 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 2020 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 {FormatXMLElementFn, PrimitiveType} from 'intl-messageformat/src/formatters';\nimport IntlMessageFormat from 'intl-messageformat';\nimport {MessageDictionary} from './MessageDictionary';\n\n/**\n * Formats ICU Message strings to create localized strings from a MessageDictionary.\n */\nexport class MessageFormatter {\n private locale: string;\n private messages: MessageDictionary;\n private cache: {[key: string]: IntlMessageFormat};\n\n constructor(locale: string, messages: MessageDictionary) {\n this.locale = locale;\n this.messages = messages;\n this.cache = {};\n }\n\n format<T = void>(key: string, variables: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined) {\n let message = this.cache[key];\n if (!message) {\n let msg = this.messages.getStringForLocale(key, this.locale);\n if (!msg) {\n throw new Error(`Could not find intl message ${key} in ${this.locale} locale`);\n }\n\n message = new IntlMessageFormat(msg, this.locale);\n this.cache[key] = message;\n }\n let varCopy: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined;\n if (variables) {\n varCopy = Object.keys(variables).reduce((acc, key) => {\n acc[key] = variables[key] == null ? false : variables[key];\n return acc;\n }, {});\n }\n\n return message.format(varCopy);\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@internationalized/message/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {LocalizedStrings} from './MessageDictionary';\nexport {MessageDictionary} from './MessageDictionary';\nexport {MessageFormatter} from './MessageFormatter';\n"],"names":[],"version":3,"file":"module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internationalized/message",
3
- "version": "3.1.3-nightly.4552+64ed13090",
3
+ "version": "3.1.3-nightly.4558+c5e4b3701",
4
4
  "description": "Internationalized message formatting and locale negotiation",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -28,5 +28,5 @@
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
- "gitHead": "64ed13090ce77cc0e4cb4cd5602e75f655bff6bb"
31
+ "gitHead": "c5e4b3701fdb89eb551f1b3697ac253f06ef68fa"
32
32
  }