Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix i18n imports and usage #1380

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/AboutAOUnit/AboutAOUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
useDataMutation,
useTimeZoneConversion,
} from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import {
Button,
CircularLoader,
Expand All @@ -27,6 +26,7 @@ import React, {
forwardRef,
useImperativeHandle,
} from 'react'
import i18n from '../../locales/index.js'
import { formatList } from '../../modules/list.js'
import { RichTextParser } from '../RichText/index.js'
import styles from './styles/AboutAOUnit.style.js'
Expand Down
2 changes: 1 addition & 1 deletion src/components/AboutAOUnit/utils.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/components/CachedDataQueryProvider.js
Original file line number Diff line number Diff line change
@@ -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({})

Expand Down
2 changes: 1 addition & 1 deletion src/components/FileMenu/utils.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 } from '../../RichText/index.js'
import {
MessageEditorContainer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useDataMutation } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import { IconDelete16, colors } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useState } from 'react'
import i18n from '../../../locales/index.js'
import { MessageIconButton } from '../common/index.js'

const mutation = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 { RichTextEditor } from '../../RichText/index.js'
import { MessageEditorContainer, MessageButtonStrip } from '../common/index.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useDataQuery } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import {
Modal,
ModalActions,
Expand All @@ -16,6 +15,7 @@ import cx from 'classnames'
import PropTypes from 'prop-types'
import React, { useEffect, useState, useMemo } from 'react'
import css from 'styled-jsx/css'
import i18n from '../../../locales/index.js'
import { InterpretationThread } from './InterpretationThread.js'
import { useModalContentWidth } from './useModalContentWidth.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -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 } from '../../RichText/index.js'
import { MessageEditorContainer, MessageButtonStrip } from '../common/index.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useDataQuery } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import {
CircularLoader,
IconChevronDown24,
Expand All @@ -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'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import i18n from '@dhis2/d2-i18n'
import {
Button,
SharingDialog,
Expand All @@ -11,6 +10,7 @@ import {
} from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useState } from 'react'
import i18n from '../../../../locales/index.js'
import {
Message,
MessageStatsBar,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 { RichTextEditor } from '../../../RichText/index.js'
import {
MessageEditorContainer,
Expand Down
2 changes: 1 addition & 1 deletion src/components/OfflineTooltip.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useDhis2ConnectionStatus } 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 = ({
Expand Down
2 changes: 1 addition & 1 deletion src/components/OpenFileDialog/CreatedByFilter.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/components/OpenFileDialog/CustomSelectOption.js
Original file line number Diff line number Diff line change
@@ -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 = ({
Expand Down
2 changes: 1 addition & 1 deletion src/components/OpenFileDialog/NameFilter.js
Original file line number Diff line number Diff line change
@@ -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 }) => (
<Input
Expand Down
2 changes: 1 addition & 1 deletion src/components/OpenFileDialog/OpenFileDialog.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useDataQuery } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import {
Box,
Modal,
Expand All @@ -24,6 +23,7 @@ import React, {
useReducer,
useState,
} from 'react'
import i18n from '../../locales/index.js'
import {
VIS_TYPE_GROUP_ALL,
VIS_TYPE_GROUP_CHARTS,
Expand Down
2 changes: 1 addition & 1 deletion src/components/OpenFileDialog/PaginationControls.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import i18n from '@dhis2/d2-i18n'
import { Pagination } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React from 'react'
import i18n from '../../locales/index.js'

export const PaginationControls = ({ page, pager, onPageChange }) => (
<Pagination
Expand Down
2 changes: 1 addition & 1 deletion src/components/OpenFileDialog/VisTypeFilter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import i18n from '@dhis2/d2-i18n'
import { SingleSelect, colors } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React from 'react'
import i18n from '../../locales/index.js'
import {
getDisplayNameByVisType,
visTypeIcons,
Expand Down
123 changes: 62 additions & 61 deletions src/components/OpenFileDialog/utils.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of a weird sentence (I know this was already present): "Create a new to get started."

"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]
}
2 changes: 1 addition & 1 deletion src/components/Options/VisualizationOptions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import i18n from '@dhis2/d2-i18n'
import {
ButtonStrip,
Modal,
Expand All @@ -14,6 +13,7 @@ import {
} from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useState } from 'react'
import i18n from '../../locales/index.js'
import {
modalContent,
tabSection,
Expand Down
2 changes: 1 addition & 1 deletion src/components/RichText/Editor/Editor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import i18n from '@dhis2/d2-i18n'
import {
Button,
Popover,
Expand All @@ -14,6 +13,7 @@ import {
import cx from 'classnames'
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 { Parser } from '../Parser/Parser.js'
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useDataQuery } from '@dhis2/app-runtime'
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'

const query = {
locales: {
Expand Down
Loading
Loading