Default to lang in catalog when browser preference unavailable

When strings aren't available for the browser's preferred locale,
default to one with strings to avoid displaying raw javascript
variables.
This commit is contained in:
Jake McDermott 2020-12-21 09:33:38 -05:00
parent 3077cb9802
commit 8db88e979e
No known key found for this signature in database
GPG Key ID: 0E56ED990CDFCB4F

View File

@ -30,7 +30,12 @@ const ProtectedRoute = ({ children, ...rest }) =>
function App() {
const catalogs = { en, ja };
const language = getLanguageWithoutRegionCode(navigator);
let language = getLanguageWithoutRegionCode(navigator);
if (!Object.keys(catalogs).includes(language)) {
// If there isn't a string catalog available for the browser's
// preferred language, default to one that has strings.
language = 'en';
}
const match = useRouteMatch();
const { hash, search, pathname } = useLocation();