From 8db88e979ea56a7a33ed21abb258a8b2a5764cf8 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Mon, 21 Dec 2020 09:33:38 -0500 Subject: [PATCH] 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. --- awx/ui_next/src/App.jsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/awx/ui_next/src/App.jsx b/awx/ui_next/src/App.jsx index ffafd07dba..5833714d89 100644 --- a/awx/ui_next/src/App.jsx +++ b/awx/ui_next/src/App.jsx @@ -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();