Skip to content

Commit

Permalink
Merge pull request openshift#12697 from rhamilto/OCPBUGS-5940
Browse files Browse the repository at this point in the history
OCPBUGS-5940: Wait with CRD/model translation until i18n bundles are loaded
  • Loading branch information
openshift-merge-robot authored Apr 1, 2023
2 parents e728b10 + de1cd51 commit 44b1440
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion frontend/@types/console/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ declare interface Window {
};
windowError?: string;
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: Function;
store?: {}; // Redux store
i18n?: {}; // i18next instance, only available in development builds for debugging
store?: {}; // Redux store, only available in development builds for debugging
pluginStore?: {}; // Console plugin store
loadPluginEntry?: Function;
Cypress?: {};
Expand Down
20 changes: 20 additions & 0 deletions frontend/public/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import { dateTimeFormatter, fromNow } from './components/utils/datetime';
const params = new URLSearchParams(window.location.search);
const pseudolocalizationEnabled = params.get('pseudolocalization') === 'true';

let resolvedLoading;

export const loading = new Promise((resolve) => {
resolvedLoading = resolve;
});

export const init = () => {
i18n
.use(new Pseudo({ enabled: pseudolocalizationEnabled, wrapped: true }))
Expand Down Expand Up @@ -95,7 +101,21 @@ export const init = () => {
// eslint-disable-next-line no-console
console.error(window.windowError);
},
})
// Update loading promise and pass values and errors to the caller
.then((value) => {
resolvedLoading(true);
return value;
})
.catch((error) => {
resolvedLoading(false);
throw error;
});
};

if (process.env.NODE_ENV !== 'production') {
// Expose i18next for debugging
window.i18n = i18n;
}

export default i18n;
7 changes: 7 additions & 0 deletions frontend/public/module/k8s/get-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { API_DISCOVERY_RESOURCES_LOCAL_STORAGE_KEY } from '@console/shared/src/constants';
import { fetchURL } from '../../graphql/client';
import { pluginStore } from '../../plugins';
import { loading as i18nLoading } from '../../i18n';

const ADMIN_RESOURCES = new Set([
'roles',
Expand Down Expand Up @@ -154,7 +155,13 @@ export const getResources = () =>
.concat(['/api/v1'])
.map((p) => fetchURL<APIResourceList>(p).catch((err) => err));

// Wait also until the known translation bundles are resolved
all.push(i18nLoading);

return Promise.all(all).then((data) => {
// Drop i18nLoading promise (resolved loaded state)
data.pop();

const resourceSet = new Set<string>();
const namespacedSet = new Set<string>();
data.forEach(
Expand Down

0 comments on commit 44b1440

Please sign in to comment.