From dc8006757a3c7db6351665a360b5831f58effd6d Mon Sep 17 00:00:00 2001 From: Jessica Steurer <70719005+jay-steurer@users.noreply.github.com> Date: Wed, 15 Mar 2023 08:31:26 -0300 Subject: [PATCH] Revert "Adds support for a pseudolocalization and lang query params (#13661)" This reverts commit 7f1750324fb4144298f70aba3ca763ef6ac615e0. --- awx/ui/src/App.js | 17 +++++++++-------- awx/ui/src/i18nLoader.js | 15 +-------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/awx/ui/src/App.js b/awx/ui/src/App.js index 21ca5a0b4f..5f35ecfbc2 100644 --- a/awx/ui/src/App.js +++ b/awx/ui/src/App.js @@ -28,7 +28,7 @@ import { getLanguageWithoutRegionCode } from 'util/language'; import Metrics from 'screens/Metrics'; import SubscriptionEdit from 'screens/Setting/Subscription/SubscriptionEdit'; import useTitle from 'hooks/useTitle'; -import { dynamicActivate } from './i18nLoader'; +import { dynamicActivate, locales } from './i18nLoader'; import getRouteConfig from './routeConfig'; import { SESSION_REDIRECT_URL } from './constants'; @@ -139,15 +139,16 @@ export function ProtectedRoute({ children, ...rest }) { function App() { const history = useHistory(); const { hash, search, pathname } = useLocation(); - const searchParams = Object.fromEntries(new URLSearchParams(search)); - const pseudolocalization = - searchParams.pseudolocalization === 'true' || false; - const language = - searchParams.lang || getLanguageWithoutRegionCode(navigator) || 'en'; + let language = getLanguageWithoutRegionCode(navigator); + if (!Object.keys(locales).includes(language)) { + // If there isn't a string catalog available for the browser's + // preferred language, default to one that has strings. + language = 'en'; + } useEffect(() => { - dynamicActivate(language, pseudolocalization); - }, [language, pseudolocalization]); + dynamicActivate(language); + }, [language]); useTitle(); diff --git a/awx/ui/src/i18nLoader.js b/awx/ui/src/i18nLoader.js index 9662f3592a..4c039b406f 100644 --- a/awx/ui/src/i18nLoader.js +++ b/awx/ui/src/i18nLoader.js @@ -27,21 +27,8 @@ i18n.loadLocaleData({ * We do a dynamic import of just the catalog that we need * @param locale any locale string */ -export async function dynamicActivate(locale, pseudolocalization = false) { +export async function dynamicActivate(locale) { const { messages } = await import(`./locales/${locale}/messages`); - - if (pseudolocalization) { - Object.keys(messages).forEach((key) => { - if (Array.isArray(messages[key])) { - // t`Foo ${param}` -> ["Foo ", ['param']] => [">>", "Foo ", ['param'], "<<"] - messages[key] = ['»', ...messages[key], '«']; - } else { - // simple string - messages[key] = `»${messages[key]}«`; - } - }); - } - i18n.load(locale, messages); i18n.activate(locale); }