@internationalized/string 3.2.2-nightly.4513 → 3.2.2-nightly.4514
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.
- package/dist/import.mjs +2 -3
- package/dist/main.js +2 -3
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -3
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/LocalizedStringDictionary.ts +4 -1
package/dist/import.mjs
CHANGED
|
@@ -53,9 +53,8 @@ class $5b160d28a433310d$export$c17fa47878dc55b6 {
|
|
|
53
53
|
}
|
|
54
54
|
constructor(messages, defaultLocale = "en-US"){
|
|
55
55
|
// Clone messages so we don't modify the original object.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
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));
|
|
59
58
|
this.defaultLocale = defaultLocale;
|
|
60
59
|
}
|
|
61
60
|
}
|
package/dist/main.js
CHANGED
|
@@ -60,9 +60,8 @@ class $f80be5fd4d03dda9$export$c17fa47878dc55b6 {
|
|
|
60
60
|
}
|
|
61
61
|
constructor(messages, defaultLocale = "en-US"){
|
|
62
62
|
// Clone messages so we don't modify the original object.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
};
|
|
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));
|
|
66
65
|
this.defaultLocale = defaultLocale;
|
|
67
66
|
}
|
|
68
67
|
}
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAQD,MAAM,qCAAe,OAAO,GAAG,CAAC;AAChC,MAAM,sCAAgB,OAAO,GAAG,CAAC;AACjC,IAAI,4C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CAAiB,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 this.strings = {...messages};\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;;;;;;;;;;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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I,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"}
|
package/dist/module.js
CHANGED
|
@@ -53,9 +53,8 @@ class $5b160d28a433310d$export$c17fa47878dc55b6 {
|
|
|
53
53
|
}
|
|
54
54
|
constructor(messages, defaultLocale = "en-US"){
|
|
55
55
|
// Clone messages so we don't modify the original object.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
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));
|
|
59
58
|
this.defaultLocale = defaultLocale;
|
|
60
59
|
}
|
|
61
60
|
}
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAQD,MAAM,qCAAe,OAAO,GAAG,CAAC;AAChC,MAAM,sCAAgB,OAAO,GAAG,CAAC;AACjC,IAAI,4CAAuG;AAMpG,MAAM;IAUX,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,gEAA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AAE,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/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 this.strings = {...messages};\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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,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":"module.js.map"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAcA,6BAA6B,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,eAAe,IAAI;IAC1E,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;CAC7B,CAAC;AAMF;;;GAGG;AACH,uCAAuC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,eAAe,GAAG,MAAM;gBAItF,QAAQ,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,GAAE,MAAgB;
|
|
1
|
+
{"mappings":"AAcA,6BAA6B,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,eAAe,IAAI;IAC1E,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;CAC7B,CAAC;AAMF;;;GAGG;AACH,uCAAuC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,eAAe,GAAG,MAAM;gBAItF,QAAQ,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,GAAE,MAAgB;IAS7E,+DAA+D;IAC/D,kBAAkB,CAAC,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;IAU7C,0DAA0D;IAC1D,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAUjD,MAAM,CAAC,6BAA6B,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,eAAe,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,0BAA0B,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI;CAyBjK;ACxED,wBAAwB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,SAAS,CAAC;AAC9E,8BAA8B,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,yBAAyB,GAAG,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC,CAAC;AACrH,sBAAsB,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;AAK9C;;;GAGG;AACH,sCAAsC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,eAAe,GAAG,MAAM;gBAIrF,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,0BAA0B,CAAC,EAAE,CAAC,CAAC;IAKpE,gFAAgF;IAChF,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM;IAK7C,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,IAAI,GAAE,KAAK,cAA2B;IAkB/G,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM;IAS9B,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,KAAK,EAAE,MAAM;CAIxE","sources":["packages/@internationalized/string/src/packages/@internationalized/string/src/LocalizedStringDictionary.ts","packages/@internationalized/string/src/packages/@internationalized/string/src/LocalizedStringFormatter.ts","packages/@internationalized/string/src/packages/@internationalized/string/src/index.ts","packages/@internationalized/string/src/index.ts"],"sourcesContent":[null,null,null,"/*\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":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internationalized/string",
|
|
3
|
-
"version": "3.2.2-nightly.
|
|
3
|
+
"version": "3.2.2-nightly.4514+f6a664ba9",
|
|
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": "
|
|
30
|
+
"gitHead": "f6a664ba900c3e6307a0f9461241aa3b2397efeb"
|
|
31
31
|
}
|
|
@@ -30,7 +30,10 @@ export class LocalizedStringDictionary<K extends string = string, T extends Loca
|
|
|
30
30
|
|
|
31
31
|
constructor(messages: LocalizedStrings<K, T>, defaultLocale: string = 'en-US') {
|
|
32
32
|
// Clone messages so we don't modify the original object.
|
|
33
|
-
|
|
33
|
+
// Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
|
|
34
|
+
this.strings = Object.fromEntries(
|
|
35
|
+
Object.entries(messages).filter(([, v]) => v)
|
|
36
|
+
);
|
|
34
37
|
this.defaultLocale = defaultLocale;
|
|
35
38
|
}
|
|
36
39
|
|