@pistonite/pure 0.26.1 → 0.26.2
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/package.json +1 -1
- package/src/pref/locale.ts +17 -4
package/package.json
CHANGED
package/src/pref/locale.ts
CHANGED
|
@@ -224,14 +224,27 @@ export const setLocale = (newLocale: string): boolean => {
|
|
|
224
224
|
export const convertToSupportedLocale = (
|
|
225
225
|
newLocale: string,
|
|
226
226
|
): string | undefined => {
|
|
227
|
-
|
|
227
|
+
return convertToSupportedLocaleIn(newLocale, supportedLocales);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* See {@link convertToSupportedLocale}
|
|
232
|
+
*
|
|
233
|
+
* This takes the supported locale array so it can be used
|
|
234
|
+
* outside of the locale system
|
|
235
|
+
*/
|
|
236
|
+
export const convertToSupportedLocaleIn = (
|
|
237
|
+
newLocale: string,
|
|
238
|
+
supportedLocalesToCheck: string[] | readonly string[],
|
|
239
|
+
): string | undefined => {
|
|
240
|
+
if (supportedLocalesToCheck.includes(newLocale)) {
|
|
228
241
|
return newLocale;
|
|
229
242
|
}
|
|
230
243
|
const language = newLocale.split("-", 2)[0];
|
|
231
|
-
const len =
|
|
244
|
+
const len = supportedLocalesToCheck.length;
|
|
232
245
|
for (let i = 0; i < len; i++) {
|
|
233
|
-
if (
|
|
234
|
-
return
|
|
246
|
+
if (supportedLocalesToCheck[i].startsWith(language)) {
|
|
247
|
+
return supportedLocalesToCheck[i];
|
|
235
248
|
}
|
|
236
249
|
}
|
|
237
250
|
return undefined;
|