Skip to content

Commit

Permalink
(fix) O3-4455 : Update translated workspace title once rendered (#1289)
Browse files Browse the repository at this point in the history
Co-authored-by: Vineet Sharma <[email protected]>
  • Loading branch information
Muppasanipraneeth and vasharma05 authored Feb 18, 2025
1 parent eb8a851 commit 52f5fa1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Suspense, useCallback, useContext, useMemo } from 'react';
import React, { Suspense, useCallback, useContext, useEffect, useMemo } from 'react';
import classNames from 'classnames';
import { Header, HeaderGlobalAction, HeaderGlobalBar, HeaderMenuButton, HeaderName } from '@carbon/react';
import { DownToBottom, Maximize, Minimize } from '@carbon/react/icons';
Expand Down Expand Up @@ -148,6 +148,17 @@ function Workspace({ workspaceInstance, additionalWorkspaceProps }: WorkspacePro
const currentGroupName = workspaceGroup?.name;
const isMaximized = workspaceWindowState === 'maximized';

// Translate the workspace title
// The workspace title is a translation key whose translation resides in the workspace module.
// Since the workspace module is not loaded at the time of workspace registration, we need to translate it here
// when the workspace is actually rendered and the workspace module along with its translations are loaded.
useEffect(() => {
const translatedTitle = t(workspaceInstance.title);
if (translatedTitle !== workspaceInstance.title) {
workspaceInstance.setTitle(translatedTitle);
}
}, [workspaceInstance.title, t, workspaceInstance.setTitle]);

// We use the feature name of the app containing the workspace in order to set the extension
// slot name. We can't use contextKey for this because we don't want the slot name to be
// different for different patients, but we do want it to be different for different apps.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('workspace system', () => {
expect(prompt).toBeTruthy();
expect(prompt.title).toMatch(/unsaved changes/i);
expect(prompt.body).toMatch(
'There may be unsaved changes in Allergies. Please save them before opening another workspace.',
'There may be unsaved changes in "Allergies". Please save them before opening another workspace.',
);
expect(prompt.confirmText).toMatch(/Open anyway/i);

Expand Down Expand Up @@ -179,7 +179,7 @@ describe('workspace system', () => {
expect(prompt).toBeTruthy();
expect(prompt.title).toMatch(/unsaved changes/i);
expect(prompt.body).toMatch(
'There may be unsaved changes in Allergies. Please save them before opening another workspace.',
'There may be unsaved changes in "Allergies". Please save them before opening another workspace.',
);
expect(prompt.confirmText).toMatch(/Open anyway/i);

Expand Down Expand Up @@ -287,7 +287,7 @@ describe('workspace system', () => {
const prompt = store.getState().prompt as Prompt;
expect(prompt).toBeTruthy();
expect(prompt.body).toMatch(
'There may be unsaved changes in Conditions. Please save them before opening another workspace.',
'There may be unsaved changes in "Conditions". Please save them before opening another workspace.',
);
// Closing the conditions workspace because it cannot be hidden

Expand All @@ -301,7 +301,7 @@ describe('workspace system', () => {

expect(prompt2).toBeTruthy();
expect(prompt2.body).toMatch(
'There may be unsaved changes in Allergies. Please save them before opening another workspace.',
'There may be unsaved changes in "Allergies". Please save them before opening another workspace.',
);

prompt2.onConfirm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ export function showWorkspacePrompts(
title: getCoreTranslation('unsavedChangesTitleText', 'Unsaved changes'),
body: getCoreTranslation(
'unsavedChangesInWorkspace',
'There may be unsaved changes in {{workspaceName}}. Please save them before opening another workspace.',
'There may be unsaved changes in "{{workspaceName}}". Please save them before opening another workspace.',
{ workspaceName: workspaceTitle },
),
onConfirm: () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/esm-translations/src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const workspaceTranslations = {
openAnyway: 'Open anyway',
unsavedChangesInOpenedWorkspace: `You may have unsaved changes in the opened workspace. Do you want to discard these changes?`,
unsavedChangesInWorkspace:
'There may be unsaved changes in {{workspaceName}}. Please save them before opening another workspace.',
'There may be unsaved changes in "{{workspaceName}}". Please save them before opening another workspace.',
unsavedChangesTitleText: 'Unsaved changes',
workspaceHeader: 'Workspace header',
};
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/esm-translations/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"stateProvince": "State",
"toggleDevTools": "Toggle dev tools",
"unknown": "Unknown",
"unsavedChangesInWorkspace": "There are unsaved changes in {{workspaceName}}. Please save them before opening another workspace.",
"unsavedChangesInWorkspace": "There may be unsaved changes in \"{{workspaceName}}\". Please save them before opening another workspace.",
"unsavedChangesTitleText": "Unsaved changes",
"workspaceHeader": "Workspace header"
}

0 comments on commit 52f5fa1

Please sign in to comment.