@internationalized/string 3.2.9 → 3.2.10
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/private/LocalizedStringDictionary.cjs +11 -0
- package/dist/private/LocalizedStringDictionary.cjs.map +1 -1
- package/dist/private/LocalizedStringDictionary.js +11 -0
- package/dist/private/LocalizedStringDictionary.js.map +1 -1
- package/dist/private/LocalizedStringDictionary.mjs +11 -0
- package/dist/private/LocalizedStringDictionary.mjs.map +1 -1
- package/package.json +2 -2
- package/src/LocalizedStringDictionary.ts +19 -0
|
@@ -63,6 +63,11 @@ function $2f953b27181a8377$var$getStringsForLocale(locale, strings, defaultLocal
|
|
|
63
63
|
// This could be replaced with Intl.LocaleMatcher once it is supported.
|
|
64
64
|
// https://github.com/tc39/proposal-intl-localematcher
|
|
65
65
|
let language = $2f953b27181a8377$var$getLanguage(locale);
|
|
66
|
+
// If the locale has an explicit script (e.g. sr-Latn-RS), prefer a
|
|
67
|
+
// language-script match (sr-Latn) over a language-only match (sr), since
|
|
68
|
+
// those may represent entirely different scripts.
|
|
69
|
+
let script = $2f953b27181a8377$var$getScript(locale);
|
|
70
|
+
if (script && strings[`${language}-${script}`]) return strings[`${language}-${script}`];
|
|
66
71
|
if (strings[language]) return strings[language];
|
|
67
72
|
for(let key in strings){
|
|
68
73
|
if (key.startsWith(language + '-')) return strings[key];
|
|
@@ -76,6 +81,12 @@ function $2f953b27181a8377$var$getLanguage(locale) {
|
|
|
76
81
|
return new Intl.Locale(locale).language;
|
|
77
82
|
return locale.split('-')[0];
|
|
78
83
|
}
|
|
84
|
+
function $2f953b27181a8377$var$getScript(locale) {
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
if (Intl.Locale) // @ts-ignore
|
|
87
|
+
return new Intl.Locale(locale).script;
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
79
90
|
|
|
80
91
|
|
|
81
92
|
//# sourceMappingURL=LocalizedStringDictionary.cjs.map
|
|
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;IACb,IAAI,KAAK,MAAM,EACb,aAAa;IACb,OAAO,IAAI,KAAK,MAAM,CAAC,QAAQ,QAAQ;IAGzC,OAAO,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE;AAC7B;AAEA,SAAS,gCAAU,MAAc;IAC/B,aAAa;IACb,IAAI,KAAK,MAAM,EACb,aAAa;IACb,OAAO,IAAI,KAAK,MAAM,CAAC,QAAQ,MAAM;IAGvC,OAAO;AACT","sources":["packages/@internationalized/string/src/LocalizedStringDictionary.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedString} from './LocalizedStringFormatter';\n\nexport type LocalizedStrings<K extends string, T extends LocalizedString> = {\n [lang: string]: Record<K, T>;\n};\n\nconst localeSymbol = Symbol.for('react-aria.i18n.locale');\nconst stringsSymbol = Symbol.for('react-aria.i18n.strings');\nlet cachedGlobalStrings:\n | {[packageName: string]: LocalizedStringDictionary<any, any>}\n | null\n | 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<\n K extends string = string,\n T extends LocalizedString = string\n> {\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(Object.entries(messages).filter(([, v]) => v));\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<\n K extends string = string,\n T extends LocalizedString = string\n >(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(\n {[locale]: globalStrings[pkg]},\n locale\n );\n }\n }\n\n let dictionary = cachedGlobalStrings?.[packageName];\n if (!dictionary) {\n throw new Error(\n `Strings for package \"${packageName}\" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`\n );\n }\n\n return dictionary;\n }\n}\n\nfunction getStringsForLocale<K extends string, T extends LocalizedString>(\n locale: string,\n strings: LocalizedStrings<K, T>,\n defaultLocale = 'en-US'\n) {\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\n // If the locale has an explicit script (e.g. sr-Latn-RS), prefer a\n // language-script match (sr-Latn) over a language-only match (sr), since\n // those may represent entirely different scripts.\n let script = getScript(locale);\n if (script && strings[`${language}-${script}`]) {\n return strings[`${language}-${script}`];\n }\n\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\nfunction getScript(locale: string) {\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n return new Intl.Locale(locale).script;\n }\n\n return undefined;\n}\n"],"names":[],"version":3,"file":"LocalizedStringDictionary.cjs.map"}
|
|
@@ -57,6 +57,11 @@ function $a9f502cbcdb3951f$var$getStringsForLocale(locale, strings, defaultLocal
|
|
|
57
57
|
// This could be replaced with Intl.LocaleMatcher once it is supported.
|
|
58
58
|
// https://github.com/tc39/proposal-intl-localematcher
|
|
59
59
|
let language = $a9f502cbcdb3951f$var$getLanguage(locale);
|
|
60
|
+
// If the locale has an explicit script (e.g. sr-Latn-RS), prefer a
|
|
61
|
+
// language-script match (sr-Latn) over a language-only match (sr), since
|
|
62
|
+
// those may represent entirely different scripts.
|
|
63
|
+
let script = $a9f502cbcdb3951f$var$getScript(locale);
|
|
64
|
+
if (script && strings[`${language}-${script}`]) return strings[`${language}-${script}`];
|
|
60
65
|
if (strings[language]) return strings[language];
|
|
61
66
|
for(let key in strings){
|
|
62
67
|
if (key.startsWith(language + '-')) return strings[key];
|
|
@@ -70,6 +75,12 @@ function $a9f502cbcdb3951f$var$getLanguage(locale) {
|
|
|
70
75
|
return new Intl.Locale(locale).language;
|
|
71
76
|
return locale.split('-')[0];
|
|
72
77
|
}
|
|
78
|
+
function $a9f502cbcdb3951f$var$getScript(locale) {
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
if (Intl.Locale) // @ts-ignore
|
|
81
|
+
return new Intl.Locale(locale).script;
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
73
84
|
|
|
74
85
|
|
|
75
86
|
export {$a9f502cbcdb3951f$export$c17fa47878dc55b6 as LocalizedStringDictionary};
|
|
@@ -1 +1 @@
|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jC,aAAa;IACb,IAAI,KAAK,MAAM,EACb,aAAa;IACb,OAAO,IAAI,KAAK,MAAM,CAAC,QAAQ,QAAQ;IAGzC,OAAO,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE;AAC7B;AAEA,SAAS,gCAAU,MAAc;IAC/B,aAAa;IACb,IAAI,KAAK,MAAM,EACb,aAAa;IACb,OAAO,IAAI,KAAK,MAAM,CAAC,QAAQ,MAAM;IAGvC,OAAO;AACT","sources":["packages/@internationalized/string/src/LocalizedStringDictionary.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedString} from './LocalizedStringFormatter';\n\nexport type LocalizedStrings<K extends string, T extends LocalizedString> = {\n [lang: string]: Record<K, T>;\n};\n\nconst localeSymbol = Symbol.for('react-aria.i18n.locale');\nconst stringsSymbol = Symbol.for('react-aria.i18n.strings');\nlet cachedGlobalStrings:\n | {[packageName: string]: LocalizedStringDictionary<any, any>}\n | null\n | 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<\n K extends string = string,\n T extends LocalizedString = string\n> {\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(Object.entries(messages).filter(([, v]) => v));\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<\n K extends string = string,\n T extends LocalizedString = string\n >(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(\n {[locale]: globalStrings[pkg]},\n locale\n );\n }\n }\n\n let dictionary = cachedGlobalStrings?.[packageName];\n if (!dictionary) {\n throw new Error(\n `Strings for package \"${packageName}\" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`\n );\n }\n\n return dictionary;\n }\n}\n\nfunction getStringsForLocale<K extends string, T extends LocalizedString>(\n locale: string,\n strings: LocalizedStrings<K, T>,\n defaultLocale = 'en-US'\n) {\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\n // If the locale has an explicit script (e.g. sr-Latn-RS), prefer a\n // language-script match (sr-Latn) over a language-only match (sr), since\n // those may represent entirely different scripts.\n let script = getScript(locale);\n if (script && strings[`${language}-${script}`]) {\n return strings[`${language}-${script}`];\n }\n\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\nfunction getScript(locale: string) {\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n return new Intl.Locale(locale).script;\n }\n\n return undefined;\n}\n"],"names":[],"version":3,"file":"LocalizedStringDictionary.js.map"}
|
|
@@ -57,6 +57,11 @@ function $a747a10fe70a57da$var$getStringsForLocale(locale, strings, defaultLocal
|
|
|
57
57
|
// This could be replaced with Intl.LocaleMatcher once it is supported.
|
|
58
58
|
// https://github.com/tc39/proposal-intl-localematcher
|
|
59
59
|
let language = $a747a10fe70a57da$var$getLanguage(locale);
|
|
60
|
+
// If the locale has an explicit script (e.g. sr-Latn-RS), prefer a
|
|
61
|
+
// language-script match (sr-Latn) over a language-only match (sr), since
|
|
62
|
+
// those may represent entirely different scripts.
|
|
63
|
+
let script = $a747a10fe70a57da$var$getScript(locale);
|
|
64
|
+
if (script && strings[`${language}-${script}`]) return strings[`${language}-${script}`];
|
|
60
65
|
if (strings[language]) return strings[language];
|
|
61
66
|
for(let key in strings){
|
|
62
67
|
if (key.startsWith(language + '-')) return strings[key];
|
|
@@ -70,6 +75,12 @@ function $a747a10fe70a57da$var$getLanguage(locale) {
|
|
|
70
75
|
return new Intl.Locale(locale).language;
|
|
71
76
|
return locale.split('-')[0];
|
|
72
77
|
}
|
|
78
|
+
function $a747a10fe70a57da$var$getScript(locale) {
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
if (Intl.Locale) // @ts-ignore
|
|
81
|
+
return new Intl.Locale(locale).script;
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
73
84
|
|
|
74
85
|
|
|
75
86
|
export {$a747a10fe70a57da$export$c17fa47878dc55b6 as LocalizedStringDictionary};
|
|
@@ -1 +1 @@
|
|
|
1
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ACb,OAAO,IAAI,KAAK,MAAM,CAAC,QAAQ,QAAQ;IAGzC,OAAO,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE;AAC7B;AAEA,SAAS,gCAAU,MAAc;IAC/B,aAAa;IACb,IAAI,KAAK,MAAM,EACb,aAAa;IACb,OAAO,IAAI,KAAK,MAAM,CAAC,QAAQ,MAAM;IAGvC,OAAO;AACT","sources":["packages/@internationalized/string/src/LocalizedStringDictionary.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedString} from './LocalizedStringFormatter';\n\nexport type LocalizedStrings<K extends string, T extends LocalizedString> = {\n [lang: string]: Record<K, T>;\n};\n\nconst localeSymbol = Symbol.for('react-aria.i18n.locale');\nconst stringsSymbol = Symbol.for('react-aria.i18n.strings');\nlet cachedGlobalStrings:\n | {[packageName: string]: LocalizedStringDictionary<any, any>}\n | null\n | 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<\n K extends string = string,\n T extends LocalizedString = string\n> {\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(Object.entries(messages).filter(([, v]) => v));\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<\n K extends string = string,\n T extends LocalizedString = string\n >(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(\n {[locale]: globalStrings[pkg]},\n locale\n );\n }\n }\n\n let dictionary = cachedGlobalStrings?.[packageName];\n if (!dictionary) {\n throw new Error(\n `Strings for package \"${packageName}\" were not included by LocalizedStringProvider. Please add it to the list passed to createLocalizedStringDictionary.`\n );\n }\n\n return dictionary;\n }\n}\n\nfunction getStringsForLocale<K extends string, T extends LocalizedString>(\n locale: string,\n strings: LocalizedStrings<K, T>,\n defaultLocale = 'en-US'\n) {\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\n // If the locale has an explicit script (e.g. sr-Latn-RS), prefer a\n // language-script match (sr-Latn) over a language-only match (sr), since\n // those may represent entirely different scripts.\n let script = getScript(locale);\n if (script && strings[`${language}-${script}`]) {\n return strings[`${language}-${script}`];\n }\n\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\nfunction getScript(locale: string) {\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n return new Intl.Locale(locale).script;\n }\n\n return undefined;\n}\n"],"names":[],"version":3,"file":"LocalizedStringDictionary.mjs.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internationalized/string",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.10",
|
|
4
4
|
"description": "Internationalized string formatting and locale negotiation",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"includeNodeModules": false
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "5ecb3333001313e83898cd07644227897e3bae1f"
|
|
50
50
|
}
|
|
@@ -114,6 +114,15 @@ function getStringsForLocale<K extends string, T extends LocalizedString>(
|
|
|
114
114
|
// This could be replaced with Intl.LocaleMatcher once it is supported.
|
|
115
115
|
// https://github.com/tc39/proposal-intl-localematcher
|
|
116
116
|
let language = getLanguage(locale);
|
|
117
|
+
|
|
118
|
+
// If the locale has an explicit script (e.g. sr-Latn-RS), prefer a
|
|
119
|
+
// language-script match (sr-Latn) over a language-only match (sr), since
|
|
120
|
+
// those may represent entirely different scripts.
|
|
121
|
+
let script = getScript(locale);
|
|
122
|
+
if (script && strings[`${language}-${script}`]) {
|
|
123
|
+
return strings[`${language}-${script}`];
|
|
124
|
+
}
|
|
125
|
+
|
|
117
126
|
if (strings[language]) {
|
|
118
127
|
return strings[language];
|
|
119
128
|
}
|
|
@@ -137,3 +146,13 @@ function getLanguage(locale: string) {
|
|
|
137
146
|
|
|
138
147
|
return locale.split('-')[0];
|
|
139
148
|
}
|
|
149
|
+
|
|
150
|
+
function getScript(locale: string) {
|
|
151
|
+
// @ts-ignore
|
|
152
|
+
if (Intl.Locale) {
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
return new Intl.Locale(locale).script;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|