Skip to content

Commit

Permalink
Merge branch 'feat(i18n)/enhanced-i18n-support' of https://github.com…
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelpisarev committed Nov 3, 2023
2 parents f9f16bc + cb885ea commit 8596553
Show file tree
Hide file tree
Showing 27 changed files with 194 additions and 67 deletions.
9 changes: 9 additions & 0 deletions platform/i18n/src/locales/en-US/ErrorBoundary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Context": "Context",
"Error": "Error",
"Error Message": "Error Message",
"Something went wrong": "Something went wrong",
"in": "in",
"Sorry, something went wrong there. Try again.": "Sorry, something went wrong there. Try again.",
"Stack Trace": "Stack Trace"
}
6 changes: 6 additions & 0 deletions platform/i18n/src/locales/en-US/HotkeysValidators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Field can't be empty": "Field can't be empty",
"Hotkey is already in use": "{{pressedKeys}} already used in \"{{action}}\"",
"It's not possible to define only modifier keys (ctrl, alt and shift) as a shortcut": "It's not possible to define only modifier keys (ctrl, alt and shift) as a shortcut",
"Shortcut combination is not allowed": "{{pressedKeys}} shortcut combination is not allowed"
}
18 changes: 18 additions & 0 deletions platform/i18n/src/locales/en-US/SegmentationTable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Active": "Active",
"Add new segmentation": "Add new segmentation",
"Add segment": "Add segment",
"Add segmentation": "Add segmentation",
"Delete": "Delete",
"Display inactive segmentations": "Display inactive segmentations",
"Export DICOM SEG": "Export DICOM SEG",
"Download DICOM SEG": "Download DICOM SEG",
"Download DICOM RTSTRUCT": "Download DICOM RTSTRUCT",
"Fill": "Fill",
"Inactive segmentations": "Inactive segmentations",
"Opacity": "Opacity",
"Outline": "Outline",
"Rename": "Rename",
"Segmentation": "Segmentation",
"Size": "Size"
}
3 changes: 3 additions & 0 deletions platform/i18n/src/locales/en-US/StudyItem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Tracked series": "Tracked series"
}
14 changes: 8 additions & 6 deletions platform/i18n/src/locales/en-US/StudyList.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
"ClearFilters": "Clear Filters",
"Description": "Description",
"Empty": "Empty",
"Filter list to 100 studies or less to enable sorting": "Filter the list to 100 studies or less to enable sorting",
"Instances": "Instances",
"MRN": "MRN",
"NumOfStudiesHiggerThan100Message": "Filter the list to 100 studies or less to enable sorting",
"Modality": "Modality",
"MRN": "MRN",
"Next": "Next >",
"No studies available": "No studies available",
"Number of studies": "Number of studies",
"Page": "Page",
"PatientName": "Patient Name",
"Previous": "< Back",
"Page": "Page",
"Next": "Next >",
"Results per page": "Results per page",
"Number of studies": "Studies",
"StudyDate": "Study Date",
"StudyList": "Study List"
"StudyList": "Study List",
"Upload": "Upload"
}
4 changes: 4 additions & 0 deletions platform/i18n/src/locales/en-US/TooltipClipboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Copied": "Copied",
"Failed to copy": "Failed to copy"
}
10 changes: 10 additions & 0 deletions platform/i18n/src/locales/en-US/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import CineDialog from './CineDialog.json';
import Common from './Common.json';
import DataSourceConfiguration from './DataSourceConfiguration.json';
import DatePicker from './DatePicker.json';
import ErrorBoundary from './ErrorBoundary.json';
import Header from './Header.json';
import HotkeysValidators from './HotkeysValidators.json';
import MeasurementTable from './MeasurementTable.json';
import SegmentationTable from './SegmentationTable.json';
import SidePanel from './SidePanel.json';
import StudyBrowser from './StudyBrowser.json';
import StudyItem from './StudyItem.json';
import StudyList from './StudyList.json';
import TooltipClipboard from './TooltipClipboard.json';
import UserPreferencesModal from './UserPreferencesModal.json';
import ViewportDownloadForm from './ViewportDownloadForm.json';
import Messages from './Messages.json';
Expand All @@ -21,11 +26,16 @@ export default {
Common,
DataSourceConfiguration,
DatePicker,
ErrorBoundary,
Header,
HotkeysValidators,
MeasurementTable,
SegmentationTable,
SidePanel,
StudyBrowser,
StudyItem,
StudyList,
TooltipClipboard,
UserPreferencesModal,
ViewportDownloadForm,
Messages,
Expand Down
2 changes: 1 addition & 1 deletion platform/i18n/src/locales/es/StudyList.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"ClearFilters": "Limpiar filtros",
"Description": "Descripción",
"Empty": "vacío",
"Filter list to 100 studies or less to enable sorting": "Filtre la lista a 100 estudios o menos para habilitar la clasificación",
"Instances": "Instancias",
"MRN": "MRN",
"NumOfStudiesHiggerThan100Message": "Filtre la lista a 100 estudios o menos para habilitar la clasificación",
"Modality": "Modalidad",
"PatientName": "Nombre paciente",
"Previous": "< Anterior",
Expand Down
9 changes: 9 additions & 0 deletions platform/i18n/src/locales/test-LNG/ErrorBoundary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Context": "Test Context",
"Error": "Test Error",
"Error Message": "Test Error Message",
"Something went wrong": "Test Something went wrong",
"in": "in",
"Sorry, something went wrong there. Try again.": "Test Sorry, something went wrong there. Try again.",
"Stack Trace": "Test Stack Trace"
}
6 changes: 6 additions & 0 deletions platform/i18n/src/locales/test-LNG/HotkeysValidators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Field can't be empty": "Test Field can't be empty",
"Hotkey is already in use": "Test {{pressedKeys}} already used in \"{{action}}\"",
"It's not possible to define only modifier keys (ctrl, alt and shift) as a shortcut": "Test It's not possible to define only modifier keys (ctrl, alt and shift) as a shortcut",
"Shortcut combination is not allowed": "Test {{pressedKeys}} shortcut combination is not allowed"
}
18 changes: 18 additions & 0 deletions platform/i18n/src/locales/test-LNG/SegmentationTable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Active": "Test Active",
"Add new segmentation": "Test Add new segmentation",
"Add segment": "Test Add segment",
"Add segmentation": "Test Add segmentation",
"Delete": "Test Delete",
"Display inactive segmentations": "Test Display inactive segmentations",
"Export DICOM SEG": "Test Export DICOM SEG",
"Download DICOM SEG": "Test Download DICOM SEG",
"Download DICOM RTSTRUCT": "Test Download DICOM RTSTRUCT",
"Fill": "Test Fill",
"Inactive segmentations": "Test Inactive segmentations",
"Opacity": "Test Opacity",
"Outline": "Test Outline",
"Rename": "Test Rename",
"Segmentation": "Test Segmentation",
"Size": "Test Size"
}
3 changes: 3 additions & 0 deletions platform/i18n/src/locales/test-LNG/StudyItem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Tracked series": "Test Tracked series"
}
16 changes: 9 additions & 7 deletions platform/i18n/src/locales/test-LNG/StudyList.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
{
"Previous": "Test < Previous",
"AccessionNumber": "Test Accession #",
"Accession": "Test Accession",
"Next >": "Test Next >",
"< Previous": "Test < Previous",
"Results per page": "Test Results per page",
"Description": "Test Description",
"Empty": "Test Empty",
"Filter list to 100 studies or less to enable sorting": "Test Filter list to 100 studies or less to enable sorting",
"Instances": "Test Instances",
"MRN": "Test MRN",
"Modality": "Test Modality",
"Next": "Test Next >",
"No studies available": "Test No studies available",
"Number of studies": "Test Number of studies",
"PatientName": "Test PatientName",
"Patient Name": "Test Patient Name",
"Description": "Test Description",
"Results per page": "Test Results per page",
"StudyDate": "Test Study Date",
"Study date": "Test Study Date",
"Number of studies": "Test Studies",
"Series": "Test Series",
"Instances": "Test Instances",
"Study List": "Test Study List",
"Study list": "Test Study list",
"Filter list to 100 studies or less to enable sorting": "Test Filter list to 100 studies or less to enable sorting"
"Upload": "Test Upload"
}
4 changes: 4 additions & 0 deletions platform/i18n/src/locales/test-LNG/TooltipClipboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Copied": "Test Copied",
"Failed to copy": "Test Failed to copy"
}
32 changes: 21 additions & 11 deletions platform/i18n/src/locales/test-LNG/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import Buttons from './Buttons.json';
import CineDialog from './CineDialog.json';
import Common from './Common.json';
import DatePicker from './DatePicker.json';
import ErrorBoundary from './ErrorBoundary.json';
import Header from './Header.json';
import HotkeysValidators from './HotkeysValidators.json';
import MeasurementTable from './MeasurementTable.json';
import Modals from './Modals.json';
import Modes from './Modes.json';
import PatientInfo from './PatientInfo.json';
import SegmentationTable from './SegmentationTable.json';
import SidePanel from './SidePanel.json';
import StudyBrowser from './StudyBrowser.json';
import StudyItem from './StudyItem.json';
import StudyList from './StudyList.json';
import ToolTip from './ToolTip.json';
import TooltipClipboard from './TooltipClipboard.json';
import UserPreferencesModal from './UserPreferencesModal.json';
import ViewportDownloadForm from './ViewportDownloadForm.json';
import ToolTip from './ToolTip.json';
import StudyBrowser from './StudyBrowser.json';
import SidePanel from './SidePanel.json';
import PatientInfo from './PatientInfo.json';
import Modes from './Modes.json';
import Modals from './Modals.json';

export default {
'test-LNG': {
Expand All @@ -22,16 +27,21 @@ export default {
CineDialog,
Common,
DatePicker,
ErrorBoundary,
Header,
HotkeysValidators,
MeasurementTable,
Modals,
Modes,
PatientInfo,
SegmentationTable,
SidePanel,
StudyBrowser,
StudyItem,
StudyList,
UserPreferencesModal,
ViewportDownloadForm,
ToolTip,
StudyBrowser,
PatientInfo,
Modes,
SidePanel,
Modals,
TooltipClipboard,
},
};
8 changes: 4 additions & 4 deletions platform/i18n/src/locales/zh/StudyList.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"Empty": "",
"Filter list to 100 studies or less to enable sorting": "将检查列表过滤到 100 个或更少以启用排序",
"Modality": "成像设备",
"PatientName": "患者姓名",
"StudyDate": "检查日期",
Expand All @@ -14,14 +15,13 @@
"Instances": "图像数",
"Accession": "检查号",
"Results per page": "每页条数",
"< Previous": "上一页",
"Next >": "下一页",
"Previous": "上一页",
"Next": "下一页",
"Page": "页码",
"Start Date": "开始日期",
"Series": "序列",
"No studies available": "没有数据",
"Loading...": "加载中...",
"Select...": "选择...",
"InstitutionName": "检查机构",
"Filter list to 100 studies or less to enable sorting": "将检查列表过滤到 100 个或更少以启用排序"
"InstitutionName": "检查机构"
}
4 changes: 3 additions & 1 deletion platform/ui/src/components/EmptyStudies/EmptyStudies.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { useTranslation } from 'react-i18next';

import Icon from '../Icon';
import Typography from '../Typography';

// TODO: Add loading spinner to OHIF + use it here.
const EmptyStudies = ({ className }) => {
const { t } = useTranslation('StudyList');
return (
<div className={classnames('inline-flex flex-col items-center', className)}>
<Icon
Expand All @@ -17,7 +19,7 @@ const EmptyStudies = ({ className }) => {
className="text-primary-light"
variant="h5"
>
{'No studies available'}
{t('No studies available')}
</Typography>
</div>
);
Expand Down
15 changes: 9 additions & 6 deletions platform/ui/src/components/ErrorBoundary/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from 'react';
import { ErrorBoundary as ReactErrorBoundary } from 'react-error-boundary';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
import i18n from 'i18next';

import Modal from '../Modal';
import Icon from '../Icon';
Expand All @@ -9,9 +11,10 @@ import IconButton from '../IconButton';
const isProduction = process.env.NODE_ENV === 'production';

const DefaultFallback = ({ error, context, resetErrorBoundary, fallbackRoute }) => {
const { t } = useTranslation('ErrorBoundary');
const [showDetails, setShowDetails] = useState(false);
const title = `Something went wrong${!isProduction && ` in ${context}`}.`;
const subtitle = `Sorry, something went wrong there. Try again.`;
const title = `${t('Something went wrong')}${!isProduction && ` ${t('in')} ${context}`}.`;
const subtitle = t('Sorry, something went wrong there. Try again.');
return (
<div
className="ErrorFallback bg-primary-dark h-full w-full"
Expand All @@ -21,8 +24,8 @@ const DefaultFallback = ({ error, context, resetErrorBoundary, fallbackRoute })
<p className="text-primary-light text-base">{subtitle}</p>
{!isProduction && (
<div className="bg-secondary-dark mt-5 space-y-2 rounded-md p-5 font-mono">
<p className="text-primary-light">Context: {context}</p>
<p className="text-primary-light">Error Message: {error.message}</p>
<p className="text-primary-light">{t('Context')}: {context}</p>
<p className="text-primary-light">{t('Error Message')}: {error.message}</p>

<IconButton
variant="contained"
Expand All @@ -32,7 +35,7 @@ const DefaultFallback = ({ error, context, resetErrorBoundary, fallbackRoute })
onClick={() => setShowDetails(!showDetails)}
>
<React.Fragment>
<div>{'Stack Trace'}</div>
<div>{t('Stack Trace')}</div>
<Icon
width="15px"
height="15px"
Expand Down Expand Up @@ -83,7 +86,7 @@ const ErrorBoundary = ({
closeButton
shouldCloseOnEsc
isOpen={isOpen}
title={'Something went wrong'}
title={i18n.t('ErrorBoundary:Error')}
onClose={() => {
setIsOpen(false);
if (fallbackRoute && typeof window !== 'undefined') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MODIFIER_KEYS, DISALLOWED_COMBINATIONS } from './hotkeysConfig';
import i18n from 'i18next';

const formatPressedKeys = pressedKeysArray => pressedKeysArray.join('+');

Expand All @@ -20,8 +21,8 @@ const findConflictingCommand = (hotkeys, currentCommandName, pressedKeys) => {
};

const ERROR_MESSAGES = {
MODIFIER: "It's not possible to define only modifier keys (ctrl, alt and shift) as a shortcut",
EMPTY: "Field can't be empty.",
MODIFIER: i18n.t('HotkeysValidators:It\'s not possible to define only modifier keys (ctrl, alt and shift) as a shortcut'),
EMPTY: i18n.t('HotkeysValidators:Field can\'t be empty'),
};

// VALIDATORS
Expand All @@ -46,7 +47,7 @@ const conflictingValidator = ({ commandName, pressedKeys, hotkeys }) => {

if (conflictingCommand) {
return {
error: `"${conflictingCommand.label}" is already using the "${pressedKeys}" shortcut.`,
error: i18n.t('HotkeysValidators:Hotkey is already in use', {action: conflictingCommand.label, pressedKeys: pressedKeys }),
};
}
};
Expand All @@ -62,7 +63,7 @@ const disallowedValidator = ({ pressedKeys = [] }) => {

if (hasDisallowedCombinations) {
return {
error: `"${formatPressedKeys(pressedKeys)}" shortcut combination is not allowed`,
error: i18n.t('HotkeysValidators:Shortcut combination is not allowed', {pressedKeys: formatPressedKeys(pressedKeys)}),
};
}
};
Expand Down
Loading

0 comments on commit 8596553

Please sign in to comment.