mirror of
https://github.com/ansible/awx.git
synced 2026-01-20 06:01:25 -03:30
Adds support for a pseudolocalization and lang query params (#13661)
* Adds support for a pseudolocalization query param to check to see whether a string has been marked for translation Adds support for a pseudolocalization query param to check to see whether a string has been marked for translation * Adds support for passing a lang param to force rendering in a particular language * Remove unused import
This commit is contained in:
parent
a63067da38
commit
7f1750324f
@ -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, locales } from './i18nLoader';
|
||||
import { dynamicActivate } from './i18nLoader';
|
||||
import getRouteConfig from './routeConfig';
|
||||
import { SESSION_REDIRECT_URL } from './constants';
|
||||
|
||||
@ -139,16 +139,15 @@ export function ProtectedRoute({ children, ...rest }) {
|
||||
function App() {
|
||||
const history = useHistory();
|
||||
const { hash, search, pathname } = useLocation();
|
||||
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';
|
||||
}
|
||||
const searchParams = Object.fromEntries(new URLSearchParams(search));
|
||||
const pseudolocalization =
|
||||
searchParams.pseudolocalization === 'true' || false;
|
||||
const language =
|
||||
searchParams.lang || getLanguageWithoutRegionCode(navigator) || 'en';
|
||||
|
||||
useEffect(() => {
|
||||
dynamicActivate(language);
|
||||
}, [language]);
|
||||
dynamicActivate(language, pseudolocalization);
|
||||
}, [language, pseudolocalization]);
|
||||
|
||||
useTitle();
|
||||
|
||||
|
||||
@ -27,8 +27,21 @@ i18n.loadLocaleData({
|
||||
* We do a dynamic import of just the catalog that we need
|
||||
* @param locale any locale string
|
||||
*/
|
||||
export async function dynamicActivate(locale) {
|
||||
export async function dynamicActivate(locale, pseudolocalization = false) {
|
||||
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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user