From 76c45623a07c67c7b1a1e602949dd2fe88ba284d Mon Sep 17 00:00:00 2001 From: Lei Nelissen Date: Tue, 9 Mar 2021 22:21:41 +0100 Subject: [PATCH] Fix launch crash on devices without fallback languages --- src/localisation/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/localisation/index.ts b/src/localisation/index.ts index a3f7276..3f1b8c6 100644 --- a/src/localisation/index.ts +++ b/src/localisation/index.ts @@ -11,11 +11,16 @@ const localeGetters: Record object> = { }; // Have RNLocalize pick the best locale from the languages on offer -const locale = findBestAvailableLanguage(Object.keys(localeGetters)); +let locale = findBestAvailableLanguage(Object.keys(localeGetters)); // Check if the locale is correctly picked if (!locale || !locale.languageTag) { - throw new Error('Invalid locale selected'); + // Some users might not list English as a fallback language, and hence might not + // be assigned a locale. In this case, we'll just default to English. + locale = { + languageTag: 'en', + isRTL: false, + }; } // Set the key-value pairs for the different languages you want to support.