From 3edc8b54cddad182199712fb42a045272d9b630f Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Fri, 18 Nov 2022 11:33:01 +0100 Subject: [PATCH 1/4] chore: fix i18n imports Make them all the same and import from locales/index.js to ensure the translations are always added. --- src/components/AboutAOUnit/AboutAOUnit.js | 2 +- src/components/AboutAOUnit/utils.js | 2 +- src/components/CachedDataQueryProvider.js | 2 +- src/components/FileMenu/utils.js | 2 +- src/components/Interpretations/InterpretationModal/Comment.js | 2 +- .../Interpretations/InterpretationModal/CommentAddForm.js | 2 +- .../Interpretations/InterpretationModal/CommentDeleteButton.js | 2 +- .../Interpretations/InterpretationModal/CommentUpdateForm.js | 2 +- .../Interpretations/InterpretationModal/InterpretationModal.js | 2 +- .../Interpretations/InterpretationsUnit/InterpretationForm.js | 2 +- .../Interpretations/InterpretationsUnit/InterpretationsUnit.js | 2 +- .../Interpretations/common/Interpretation/Interpretation.js | 2 +- .../common/Interpretation/InterpretationDeleteButton.js | 2 +- .../common/Interpretation/InterpretationSharingLink.js | 2 +- .../common/Interpretation/InterpretationUpdateForm.js | 2 +- .../Interpretations/common/RichTextEditor/RichTextEditor.js | 2 +- src/components/Interpretations/common/UserMention/UserList.js | 2 +- .../Interpretations/common/UserMention/UserMentionWrapper.js | 2 +- src/components/OfflineTooltip.js | 2 +- src/components/OpenFileDialog/CreatedByFilter.js | 2 +- src/components/OpenFileDialog/CustomSelectOption.js | 2 +- src/components/OpenFileDialog/NameFilter.js | 2 +- src/components/OpenFileDialog/OpenFileDialog.js | 2 +- src/components/OpenFileDialog/PaginationControls.js | 2 +- src/components/OpenFileDialog/VisTypeFilter.js | 2 +- src/components/OpenFileDialog/utils.js | 2 +- src/components/Options/VisualizationOptions.js | 2 +- .../TranslationDialog/TranslationModal/LocalesSelect.js | 2 +- .../TranslationDialog/TranslationModal/TranslationForm.js | 2 +- .../TranslationDialog/TranslationModal/TranslationModal.js | 2 +- .../TranslationModal/TranslationModalActions.js | 2 +- .../TranslationModal/useTranslationsResults.js | 2 +- 32 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/components/AboutAOUnit/AboutAOUnit.js b/src/components/AboutAOUnit/AboutAOUnit.js index 0fb7fb78e..ca0893011 100644 --- a/src/components/AboutAOUnit/AboutAOUnit.js +++ b/src/components/AboutAOUnit/AboutAOUnit.js @@ -1,5 +1,4 @@ import { useDataQuery, useDataMutation } from '@dhis2/app-runtime' -import i18n from '@dhis2/d2-i18n' import { Parser as RichTextParser } from '@dhis2/d2-ui-rich-text' import { Button, @@ -24,6 +23,7 @@ import React, { forwardRef, useImperativeHandle, } from 'react' +import i18n from '../../locales/index.js' import { formatList } from '../../modules/list.js' import styles from './styles/AboutAOUnit.style.js' import { getTranslatedString, AOTypeMap } from './utils.js' diff --git a/src/components/AboutAOUnit/utils.js b/src/components/AboutAOUnit/utils.js index eb0295cf6..b5874a5c5 100644 --- a/src/components/AboutAOUnit/utils.js +++ b/src/components/AboutAOUnit/utils.js @@ -1,4 +1,4 @@ -import i18n from '@dhis2/d2-i18n' +import i18n from '../../locales/index.js' export const AO_TYPE_VISUALIZATION = 'visualization' export const AO_TYPE_MAP = 'map' diff --git a/src/components/CachedDataQueryProvider.js b/src/components/CachedDataQueryProvider.js index 47646a1f1..32adc57d4 100644 --- a/src/components/CachedDataQueryProvider.js +++ b/src/components/CachedDataQueryProvider.js @@ -1,8 +1,8 @@ import { useDataQuery } from '@dhis2/app-runtime' -import i18n from '@dhis2/d2-i18n' import { Layer, CenteredContent, CircularLoader, NoticeBox } from '@dhis2/ui' import PropTypes from 'prop-types' import React, { createContext, useContext } from 'react' +import i18n from '../locales/index.js' const CachedDataQueryCtx = createContext({}) diff --git a/src/components/FileMenu/utils.js b/src/components/FileMenu/utils.js index 7cca04a9d..a513289e7 100644 --- a/src/components/FileMenu/utils.js +++ b/src/components/FileMenu/utils.js @@ -1,4 +1,4 @@ -import i18n from '@dhis2/d2-i18n' +import i18n from '../../locales/index.js' export const FILE_TYPE_EVENT_REPORT = 'eventReport' export const FILE_TYPE_VISUALIZATION = 'visualization' diff --git a/src/components/Interpretations/InterpretationModal/Comment.js b/src/components/Interpretations/InterpretationModal/Comment.js index 2e7e07637..f00f761c5 100644 --- a/src/components/Interpretations/InterpretationModal/Comment.js +++ b/src/components/Interpretations/InterpretationModal/Comment.js @@ -1,7 +1,7 @@ -import i18n from '@dhis2/d2-i18n' import { IconEdit16 } from '@dhis2/ui' import PropTypes from 'prop-types' import React, { useState } from 'react' +import i18n from '../../../locales/index.js' import { Message, MessageIconButton, MessageStatsBar } from '../common/index.js' import { CommentDeleteButton } from './CommentDeleteButton.js' import { CommentUpdateForm } from './CommentUpdateForm.js' diff --git a/src/components/Interpretations/InterpretationModal/CommentAddForm.js b/src/components/Interpretations/InterpretationModal/CommentAddForm.js index 9cae2d4a7..8de0fc376 100644 --- a/src/components/Interpretations/InterpretationModal/CommentAddForm.js +++ b/src/components/Interpretations/InterpretationModal/CommentAddForm.js @@ -1,8 +1,8 @@ import { useDataMutation } from '@dhis2/app-runtime' -import i18n from '@dhis2/d2-i18n' import { Button } from '@dhis2/ui' import PropTypes from 'prop-types' import React, { useRef, useState } from 'react' +import i18n from '../../../locales/index.js' import { RichTextEditor, MessageEditorContainer, diff --git a/src/components/Interpretations/InterpretationModal/CommentDeleteButton.js b/src/components/Interpretations/InterpretationModal/CommentDeleteButton.js index 228896126..6386c4bb7 100644 --- a/src/components/Interpretations/InterpretationModal/CommentDeleteButton.js +++ b/src/components/Interpretations/InterpretationModal/CommentDeleteButton.js @@ -1,8 +1,8 @@ import { useDataMutation } from '@dhis2/app-runtime' -import i18n from '@dhis2/d2-i18n' import { IconDelete16 } from '@dhis2/ui' import PropTypes from 'prop-types' import React from 'react' +import i18n from '../../../locales/index.js' import { MessageIconButton } from '../common/index.js' const mutation = { diff --git a/src/components/Interpretations/InterpretationModal/CommentUpdateForm.js b/src/components/Interpretations/InterpretationModal/CommentUpdateForm.js index 1b1dec89c..060e944ab 100644 --- a/src/components/Interpretations/InterpretationModal/CommentUpdateForm.js +++ b/src/components/Interpretations/InterpretationModal/CommentUpdateForm.js @@ -1,8 +1,8 @@ import { useDataMutation } from '@dhis2/app-runtime' -import i18n from '@dhis2/d2-i18n' import { Button, spacers, colors } from '@dhis2/ui' import PropTypes from 'prop-types' import React, { useState, useRef } from 'react' +import i18n from '../../../locales/index.js' import { MessageEditorContainer, RichTextEditor, diff --git a/src/components/Interpretations/InterpretationModal/InterpretationModal.js b/src/components/Interpretations/InterpretationModal/InterpretationModal.js index f2d693838..59602f10f 100644 --- a/src/components/Interpretations/InterpretationModal/InterpretationModal.js +++ b/src/components/Interpretations/InterpretationModal/InterpretationModal.js @@ -1,5 +1,4 @@ import { useDataQuery } from '@dhis2/app-runtime' -import i18n from '@dhis2/d2-i18n' import { Modal, ModalActions, @@ -16,6 +15,7 @@ import cx from 'classnames' import PropTypes from 'prop-types' import React, { useEffect, useState } from 'react' import css from 'styled-jsx/css' +import i18n from '../../../locales/index.js' import { InterpretationThread } from './InterpretationThread.js' import { useModalContentWidth } from './useModalContentWidth.js' diff --git a/src/components/Interpretations/InterpretationsUnit/InterpretationForm.js b/src/components/Interpretations/InterpretationsUnit/InterpretationForm.js index 67f95d0ad..b0d811553 100644 --- a/src/components/Interpretations/InterpretationsUnit/InterpretationForm.js +++ b/src/components/Interpretations/InterpretationsUnit/InterpretationForm.js @@ -1,8 +1,8 @@ import { useDataMutation } from '@dhis2/app-runtime' -import i18n from '@dhis2/d2-i18n' import { Button, Input } from '@dhis2/ui' import PropTypes from 'prop-types' import React, { useRef, useState } from 'react' +import i18n from '../../../locales/index.js' import { RichTextEditor, MessageEditorContainer, diff --git a/src/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js b/src/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js index 3a6d6d257..42ac08201 100644 --- a/src/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js +++ b/src/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js @@ -1,5 +1,4 @@ import { useDataQuery } from '@dhis2/app-runtime' -import i18n from '@dhis2/d2-i18n' import { CircularLoader, IconChevronDown24, @@ -16,6 +15,7 @@ import React, { useImperativeHandle, forwardRef, } from 'react' +import i18n from '../../../locales/index.js' import { InterpretationForm } from './InterpretationForm.js' import { InterpretationList } from './InterpretationList.js' diff --git a/src/components/Interpretations/common/Interpretation/Interpretation.js b/src/components/Interpretations/common/Interpretation/Interpretation.js index 736d78da5..2dc12ea53 100644 --- a/src/components/Interpretations/common/Interpretation/Interpretation.js +++ b/src/components/Interpretations/common/Interpretation/Interpretation.js @@ -1,4 +1,3 @@ -import i18n from '@dhis2/d2-i18n' import { Button, SharingDialog, @@ -9,6 +8,7 @@ import { } from '@dhis2/ui' import PropTypes from 'prop-types' import React, { useState } from 'react' +import i18n from '../../../../locales/index.js' import { Message, MessageStatsBar, MessageIconButton } from '../index.js' import { InterpretationDeleteButton } from './InterpretationDeleteButton.js' import { InterpretationUpdateForm } from './InterpretationUpdateForm.js' diff --git a/src/components/Interpretations/common/Interpretation/InterpretationDeleteButton.js b/src/components/Interpretations/common/Interpretation/InterpretationDeleteButton.js index cae57b00b..573b18ce3 100644 --- a/src/components/Interpretations/common/Interpretation/InterpretationDeleteButton.js +++ b/src/components/Interpretations/common/Interpretation/InterpretationDeleteButton.js @@ -1,8 +1,8 @@ import { useDataMutation } from '@dhis2/app-runtime' -import i18n from '@dhis2/d2-i18n' import { IconDelete16 } from '@dhis2/ui' import PropTypes from 'prop-types' import React from 'react' +import i18n from '../../../../locales/index.js' import { MessageIconButton } from '../index.js' const mutation = { diff --git a/src/components/Interpretations/common/Interpretation/InterpretationSharingLink.js b/src/components/Interpretations/common/Interpretation/InterpretationSharingLink.js index f13f6a94a..d381df6de 100644 --- a/src/components/Interpretations/common/Interpretation/InterpretationSharingLink.js +++ b/src/components/Interpretations/common/Interpretation/InterpretationSharingLink.js @@ -1,7 +1,7 @@ -import i18n from '@dhis2/d2-i18n' import { SharingDialog, colors, spacers } from '@dhis2/ui' import PropTypes from 'prop-types' import React, { useState } from 'react' +import i18n from '../../../../locales/index.js' const InterpretationSharingLink = ({ type, id }) => { const [showSharingDialog, setShowSharingDialog] = useState(false) diff --git a/src/components/Interpretations/common/Interpretation/InterpretationUpdateForm.js b/src/components/Interpretations/common/Interpretation/InterpretationUpdateForm.js index cf900fdf1..acc8f64b0 100644 --- a/src/components/Interpretations/common/Interpretation/InterpretationUpdateForm.js +++ b/src/components/Interpretations/common/Interpretation/InterpretationUpdateForm.js @@ -1,8 +1,8 @@ import { useDataMutation } from '@dhis2/app-runtime' -import i18n from '@dhis2/d2-i18n' import { Button, spacers, colors } from '@dhis2/ui' import PropTypes from 'prop-types' import React, { useState } from 'react' +import i18n from '../../../../locales/index.js' import { MessageEditorContainer, RichTextEditor, diff --git a/src/components/Interpretations/common/RichTextEditor/RichTextEditor.js b/src/components/Interpretations/common/RichTextEditor/RichTextEditor.js index ba2eba9fe..4d9ea52e4 100644 --- a/src/components/Interpretations/common/RichTextEditor/RichTextEditor.js +++ b/src/components/Interpretations/common/RichTextEditor/RichTextEditor.js @@ -1,4 +1,3 @@ -import i18n from '@dhis2/d2-i18n' import { Parser as RichTextParser } from '@dhis2/d2-ui-rich-text' import { Button, @@ -14,6 +13,7 @@ import { } from '@dhis2/ui' import PropTypes from 'prop-types' import React, { forwardRef, useRef, useEffect, useState } from 'react' +import i18n from '../../../../locales/index.js' import { UserMentionWrapper } from '../UserMention/UserMentionWrapper.js' import { convertCtrlKey, diff --git a/src/components/Interpretations/common/UserMention/UserList.js b/src/components/Interpretations/common/UserMention/UserList.js index 5aa04a844..8cc56e5c5 100644 --- a/src/components/Interpretations/common/UserMention/UserList.js +++ b/src/components/Interpretations/common/UserMention/UserList.js @@ -1,7 +1,7 @@ -import i18n from '@dhis2/d2-i18n' import { MenuItem } from '@dhis2/ui' import PropTypes from 'prop-types' import React from 'react' +import i18n from '../../../../locales/index.js' export const UserList = ({ users, selectedUserIndex, onUserClick, pager }) => { return ( diff --git a/src/components/Interpretations/common/UserMention/UserMentionWrapper.js b/src/components/Interpretations/common/UserMention/UserMentionWrapper.js index 394cc39bc..0fb4607d5 100644 --- a/src/components/Interpretations/common/UserMention/UserMentionWrapper.js +++ b/src/components/Interpretations/common/UserMention/UserMentionWrapper.js @@ -1,4 +1,3 @@ -import i18n from '@dhis2/d2-i18n' import { CenteredContent, CircularLoader, @@ -11,6 +10,7 @@ import { } from '@dhis2/ui' import PropTypes from 'prop-types' import React, { useState, useRef } from 'react' +import i18n from '../../../../locales/index.js' import { resolvedHeaderStyle, userMentionWrapperClasses, diff --git a/src/components/OfflineTooltip.js b/src/components/OfflineTooltip.js index 633e2011e..096ef120c 100644 --- a/src/components/OfflineTooltip.js +++ b/src/components/OfflineTooltip.js @@ -1,9 +1,9 @@ import { useOnlineStatus } from '@dhis2/app-runtime' -import i18n from '@dhis2/d2-i18n' import { Tooltip } from '@dhis2/ui' import cx from 'classnames' import PropTypes from 'prop-types' import React from 'react' +import i18n from '../locales/index.js' import { styles } from './styles/OfflineTooltip.style.js' const OfflineTooltip = ({ diff --git a/src/components/OpenFileDialog/CreatedByFilter.js b/src/components/OpenFileDialog/CreatedByFilter.js index b7bd74a43..ae43db1f3 100644 --- a/src/components/OpenFileDialog/CreatedByFilter.js +++ b/src/components/OpenFileDialog/CreatedByFilter.js @@ -1,7 +1,7 @@ -import i18n from '@dhis2/d2-i18n' import { SingleSelect, SingleSelectOption } from '@dhis2/ui' import PropTypes from 'prop-types' import React from 'react' +import i18n from '../../locales/index.js' // TODO change the "Created by" prefix to "Creator" or something that does not require a context for the translators diff --git a/src/components/OpenFileDialog/CustomSelectOption.js b/src/components/OpenFileDialog/CustomSelectOption.js index c920b26ce..f1dab7e5b 100644 --- a/src/components/OpenFileDialog/CustomSelectOption.js +++ b/src/components/OpenFileDialog/CustomSelectOption.js @@ -1,8 +1,8 @@ -import i18n from '@dhis2/d2-i18n' import { MenuDivider, Tooltip } from '@dhis2/ui' import cx from 'classnames' import PropTypes from 'prop-types' import React from 'react' +import i18n from '../../locales/index.js' import styles from './styles/CustomSelectOption.style.js' const CustomSelectOptionItem = ({ diff --git a/src/components/OpenFileDialog/NameFilter.js b/src/components/OpenFileDialog/NameFilter.js index 1b6f3b2e3..0e05aed71 100644 --- a/src/components/OpenFileDialog/NameFilter.js +++ b/src/components/OpenFileDialog/NameFilter.js @@ -1,7 +1,7 @@ -import i18n from '@dhis2/d2-i18n' import { Input } from '@dhis2/ui' import PropTypes from 'prop-types' import React from 'react' +import i18n from '../../locales/index.js' export const NameFilter = ({ dataTest, value, onChange }) => ( ( ( diff --git a/src/components/TranslationDialog/TranslationModal/useTranslationsResults.js b/src/components/TranslationDialog/TranslationModal/useTranslationsResults.js index bed37cf8e..844cc62d3 100644 --- a/src/components/TranslationDialog/TranslationModal/useTranslationsResults.js +++ b/src/components/TranslationDialog/TranslationModal/useTranslationsResults.js @@ -1,6 +1,6 @@ import { useAlert, useDataQuery } from '@dhis2/app-runtime' -import i18n from '@dhis2/d2-i18n' import { useRef } from 'react' +import i18n from '../../../locales/index.js' export const useTranslationsResults = ({ resource }) => { const translationsQueryRef = useRef({ From 393ffb9bd8982ca1f49a8d5fcdbfb76c79b84e8f Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Fri, 18 Nov 2022 11:34:24 +0100 Subject: [PATCH 2/4] fix: ensure translations for strings are replaced at runtime --- src/components/OpenFileDialog/utils.js | 121 +++++++++++++------------ 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/src/components/OpenFileDialog/utils.js b/src/components/OpenFileDialog/utils.js index 40941724e..43726a99e 100644 --- a/src/components/OpenFileDialog/utils.js +++ b/src/components/OpenFileDialog/utils.js @@ -18,65 +18,66 @@ export const AOTypeMap = { const NO_TYPE = 'NO_TYPE' -const texts = { - [NO_TYPE]: { - modalTitle: i18n.t('Open'), - loadingText: i18n.t('Loading'), - errorTitle: i18n.t("Couldn't load items"), - errorText: i18n.t( - 'There was a problem loading items. Try again or contact your system administrator.' - ), - noDataText: i18n.t('No items found. Create a new to get started.'), - noFilteredDataText: i18n.t( - "No items found. Try adjusting your search or filter options to find what you're looking for." - ), - newButtonLabel: i18n.t('Create new'), - }, +export const getTranslatedString = (type, key) => { + const texts = { + [NO_TYPE]: { + modalTitle: i18n.t('Open'), + loadingText: i18n.t('Loading'), + errorTitle: i18n.t("Couldn't load items"), + errorText: i18n.t( + 'There was a problem loading items. Try again or contact your system administrator.' + ), + noDataText: i18n.t('No items found. Create a new to get started.'), + noFilteredDataText: i18n.t( + "No items found. Try adjusting your search or filter options to find what you're looking for." + ), + newButtonLabel: i18n.t('Create new'), + }, - [AO_TYPE_VISUALIZATION]: { - modalTitle: i18n.t('Open a visualization'), - loadingText: i18n.t('Loading visualizations'), - errorTitle: i18n.t("Couldn't load visualizations"), - errorText: i18n.t( - 'There was a problem loading visualizations. Try again or contact your system administrator.' - ), - noDataText: i18n.t( - 'No visualizations found. Click New visualization to get started.' - ), - noFilteredDataText: i18n.t( - "No visualizations found. Try adjusting your search or filter options to find what you're looking for." - ), - newButtonLabel: i18n.t('New visualization'), - }, - [AO_TYPE_MAP]: { - modalTitle: i18n.t('Open a map'), - loadingText: i18n.t('Loading maps'), - errorTitle: i18n.t("Couldn't load maps"), - errorText: i18n.t( - 'There was a problem loading maps. Try again or contact your system administrator.' - ), - noDataText: i18n.t('No maps found. Click New map to get started.'), - noFilteredDataText: i18n.t( - "No maps found. Try adjusting your search or filter options to find what you're looking for." - ), - newButtonLabel: i18n.t('New map'), - }, - [AO_TYPE_EVENT_VISUALIZATION]: { - modalTitle: i18n.t('Open a line list'), - loadingText: i18n.t('Loading line lists'), - errorTitle: i18n.t("Couldn't load line lists"), - errorText: i18n.t( - 'There was a problem loading line lists. Try again or contact your system administrator.' - ), - noDataText: i18n.t( - 'No line lists found. Click New line list to get started.' - ), - noFilteredDataText: i18n.t( - "No line lists found. Try adjusting your search or filter options to find what you're looking for." - ), - newButtonLabel: i18n.t('New line list'), - }, -} + [AO_TYPE_VISUALIZATION]: { + modalTitle: i18n.t('Open a visualization'), + loadingText: i18n.t('Loading visualizations'), + errorTitle: i18n.t("Couldn't load visualizations"), + errorText: i18n.t( + 'There was a problem loading visualizations. Try again or contact your system administrator.' + ), + noDataText: i18n.t( + 'No visualizations found. Click New visualization to get started.' + ), + noFilteredDataText: i18n.t( + "No visualizations found. Try adjusting your search or filter options to find what you're looking for." + ), + newButtonLabel: i18n.t('New visualization'), + }, + [AO_TYPE_MAP]: { + modalTitle: i18n.t('Open a map'), + loadingText: i18n.t('Loading maps'), + errorTitle: i18n.t("Couldn't load maps"), + errorText: i18n.t( + 'There was a problem loading maps. Try again or contact your system administrator.' + ), + noDataText: i18n.t('No maps found. Click New map to get started.'), + noFilteredDataText: i18n.t( + "No maps found. Try adjusting your search or filter options to find what you're looking for." + ), + newButtonLabel: i18n.t('New map'), + }, + [AO_TYPE_EVENT_VISUALIZATION]: { + modalTitle: i18n.t('Open a line list'), + loadingText: i18n.t('Loading line lists'), + errorTitle: i18n.t("Couldn't load line lists"), + errorText: i18n.t( + 'There was a problem loading line lists. Try again or contact your system administrator.' + ), + noDataText: i18n.t( + 'No line lists found. Click New line list to get started.' + ), + noFilteredDataText: i18n.t( + "No line lists found. Try adjusting your search or filter options to find what you're looking for." + ), + newButtonLabel: i18n.t('New line list'), + }, + } -export const getTranslatedString = (type, key) => - (texts[type] || texts[NO_TYPE])[key] + return (texts[type] || texts[NO_TYPE])[key] +} From 492b568e780784d752deb84644ebaba3ff5156f1 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Fri, 1 Nov 2024 15:20:45 +0100 Subject: [PATCH 3/4] Revert "fix: ensure translations for strings are replaced at runtime" This reverts commit 393ffb9bd8982ca1f49a8d5fcdbfb76c79b84e8f. --- src/components/OpenFileDialog/utils.js | 121 ++++++++++++------------- 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/src/components/OpenFileDialog/utils.js b/src/components/OpenFileDialog/utils.js index 43726a99e..40941724e 100644 --- a/src/components/OpenFileDialog/utils.js +++ b/src/components/OpenFileDialog/utils.js @@ -18,66 +18,65 @@ export const AOTypeMap = { const NO_TYPE = 'NO_TYPE' -export const getTranslatedString = (type, key) => { - const texts = { - [NO_TYPE]: { - modalTitle: i18n.t('Open'), - loadingText: i18n.t('Loading'), - errorTitle: i18n.t("Couldn't load items"), - errorText: i18n.t( - 'There was a problem loading items. Try again or contact your system administrator.' - ), - noDataText: i18n.t('No items found. Create a new to get started.'), - noFilteredDataText: i18n.t( - "No items found. Try adjusting your search or filter options to find what you're looking for." - ), - newButtonLabel: i18n.t('Create new'), - }, - - [AO_TYPE_VISUALIZATION]: { - modalTitle: i18n.t('Open a visualization'), - loadingText: i18n.t('Loading visualizations'), - errorTitle: i18n.t("Couldn't load visualizations"), - errorText: i18n.t( - 'There was a problem loading visualizations. Try again or contact your system administrator.' - ), - noDataText: i18n.t( - 'No visualizations found. Click New visualization to get started.' - ), - noFilteredDataText: i18n.t( - "No visualizations found. Try adjusting your search or filter options to find what you're looking for." - ), - newButtonLabel: i18n.t('New visualization'), - }, - [AO_TYPE_MAP]: { - modalTitle: i18n.t('Open a map'), - loadingText: i18n.t('Loading maps'), - errorTitle: i18n.t("Couldn't load maps"), - errorText: i18n.t( - 'There was a problem loading maps. Try again or contact your system administrator.' - ), - noDataText: i18n.t('No maps found. Click New map to get started.'), - noFilteredDataText: i18n.t( - "No maps found. Try adjusting your search or filter options to find what you're looking for." - ), - newButtonLabel: i18n.t('New map'), - }, - [AO_TYPE_EVENT_VISUALIZATION]: { - modalTitle: i18n.t('Open a line list'), - loadingText: i18n.t('Loading line lists'), - errorTitle: i18n.t("Couldn't load line lists"), - errorText: i18n.t( - 'There was a problem loading line lists. Try again or contact your system administrator.' - ), - noDataText: i18n.t( - 'No line lists found. Click New line list to get started.' - ), - noFilteredDataText: i18n.t( - "No line lists found. Try adjusting your search or filter options to find what you're looking for." - ), - newButtonLabel: i18n.t('New line list'), - }, - } +const texts = { + [NO_TYPE]: { + modalTitle: i18n.t('Open'), + loadingText: i18n.t('Loading'), + errorTitle: i18n.t("Couldn't load items"), + errorText: i18n.t( + 'There was a problem loading items. Try again or contact your system administrator.' + ), + noDataText: i18n.t('No items found. Create a new to get started.'), + noFilteredDataText: i18n.t( + "No items found. Try adjusting your search or filter options to find what you're looking for." + ), + newButtonLabel: i18n.t('Create new'), + }, - return (texts[type] || texts[NO_TYPE])[key] + [AO_TYPE_VISUALIZATION]: { + modalTitle: i18n.t('Open a visualization'), + loadingText: i18n.t('Loading visualizations'), + errorTitle: i18n.t("Couldn't load visualizations"), + errorText: i18n.t( + 'There was a problem loading visualizations. Try again or contact your system administrator.' + ), + noDataText: i18n.t( + 'No visualizations found. Click New visualization to get started.' + ), + noFilteredDataText: i18n.t( + "No visualizations found. Try adjusting your search or filter options to find what you're looking for." + ), + newButtonLabel: i18n.t('New visualization'), + }, + [AO_TYPE_MAP]: { + modalTitle: i18n.t('Open a map'), + loadingText: i18n.t('Loading maps'), + errorTitle: i18n.t("Couldn't load maps"), + errorText: i18n.t( + 'There was a problem loading maps. Try again or contact your system administrator.' + ), + noDataText: i18n.t('No maps found. Click New map to get started.'), + noFilteredDataText: i18n.t( + "No maps found. Try adjusting your search or filter options to find what you're looking for." + ), + newButtonLabel: i18n.t('New map'), + }, + [AO_TYPE_EVENT_VISUALIZATION]: { + modalTitle: i18n.t('Open a line list'), + loadingText: i18n.t('Loading line lists'), + errorTitle: i18n.t("Couldn't load line lists"), + errorText: i18n.t( + 'There was a problem loading line lists. Try again or contact your system administrator.' + ), + noDataText: i18n.t( + 'No line lists found. Click New line list to get started.' + ), + noFilteredDataText: i18n.t( + "No line lists found. Try adjusting your search or filter options to find what you're looking for." + ), + newButtonLabel: i18n.t('New line list'), + }, } + +export const getTranslatedString = (type, key) => + (texts[type] || texts[NO_TYPE])[key] From 98a71935d10ba63fdba17b83bc6cc0f518fe86b1 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Fri, 1 Nov 2024 16:09:24 +0100 Subject: [PATCH 4/4] chore: fix more i18n imports --- src/components/DataDimension/Calculation/FormulaField.js | 2 +- src/components/PivotTable/PivotTableValueCell.js | 2 +- src/components/Toolbar/InterpretationsAndDetailsToggler.js | 2 +- src/components/Toolbar/UpdateButton.js | 2 +- src/modules/pivotTable/PivotTableEngine.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/DataDimension/Calculation/FormulaField.js b/src/components/DataDimension/Calculation/FormulaField.js index 388394deb..79cdcea82 100644 --- a/src/components/DataDimension/Calculation/FormulaField.js +++ b/src/components/DataDimension/Calculation/FormulaField.js @@ -1,10 +1,10 @@ -import i18n from '@dhis2/d2-i18n' import { Center, CircularLoader } from '@dhis2/ui' import { useDroppable } from '@dnd-kit/core' import { SortableContext } from '@dnd-kit/sortable' import PropTypes from 'prop-types' import React from 'react' import FormulaIcon from '../../../assets/FormulaIcon.js' +import i18n from '../../../locales/index.js' import DropZone from './DropZone.js' import FormulaItem from './FormulaItem.js' import styles from './styles/FormulaField.style.js' diff --git a/src/components/PivotTable/PivotTableValueCell.js b/src/components/PivotTable/PivotTableValueCell.js index f20fe554d..8d1619cb1 100644 --- a/src/components/PivotTable/PivotTableValueCell.js +++ b/src/components/PivotTable/PivotTableValueCell.js @@ -1,6 +1,6 @@ -import i18n from '@dhis2/d2-i18n' import PropTypes from 'prop-types' import React, { useRef } from 'react' +import i18n from '../../locales/index.js' import { applyLegendSet } from '../../modules/pivotTable/applyLegendSet.js' import { CELL_TYPE_VALUE } from '../../modules/pivotTable/pivotTableConstants.js' import { diff --git a/src/components/Toolbar/InterpretationsAndDetailsToggler.js b/src/components/Toolbar/InterpretationsAndDetailsToggler.js index 8bb8abeb3..ee8e7c6d5 100644 --- a/src/components/Toolbar/InterpretationsAndDetailsToggler.js +++ b/src/components/Toolbar/InterpretationsAndDetailsToggler.js @@ -1,7 +1,7 @@ -import i18n from '@dhis2/d2-i18n' import { IconChevronRight24, IconChevronLeft24 } from '@dhis2/ui' import PropTypes from 'prop-types' import React from 'react' +import i18n from '../../locales/index.js' import menuButtonStyles from './MenuButton.styles.js' export const InterpretationsAndDetailsToggler = ({ diff --git a/src/components/Toolbar/UpdateButton.js b/src/components/Toolbar/UpdateButton.js index fdfaa06e7..2ecab69ea 100644 --- a/src/components/Toolbar/UpdateButton.js +++ b/src/components/Toolbar/UpdateButton.js @@ -1,9 +1,9 @@ import { CircularLoader } from '@dhis2-ui/loader' -import i18n from '@dhis2/d2-i18n' import { colors } from '@dhis2/ui-constants' import { IconSync16 } from '@dhis2/ui-icons' import PropTypes from 'prop-types' import React from 'react' +import i18n from '../../locales/index.js' import menuButtonStyles from './MenuButton.styles.js' export const UpdateButton = ({ onClick, disabled, loading, dataTest }) => ( diff --git a/src/modules/pivotTable/PivotTableEngine.js b/src/modules/pivotTable/PivotTableEngine.js index ad798e686..a50d2737d 100644 --- a/src/modules/pivotTable/PivotTableEngine.js +++ b/src/modules/pivotTable/PivotTableEngine.js @@ -1,5 +1,5 @@ -import i18n from '@dhis2/d2-i18n' import times from 'lodash/times' +import i18n from '../../locales/index.js' import { DIMENSION_TYPE_DATA, DIMENSION_TYPE_DATA_ELEMENT_GROUP_SET,