Skip to content

Commit

Permalink
fix: ensure translations for strings are replaced at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Nov 18, 2022
1 parent 3edc8b5 commit 393ffb9
Showing 1 changed file with 61 additions and 60 deletions.
121 changes: 61 additions & 60 deletions src/components/OpenFileDialog/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

0 comments on commit 393ffb9

Please sign in to comment.