From 7122e878a5c0fe51104f0cf8cec14e4432d4ad74 Mon Sep 17 00:00:00 2001 From: proddy Date: Sat, 27 Aug 2022 13:02:04 +0200 Subject: [PATCH] upload translations --- CHANGELOG_LATEST.md | 4 ++ .../src/components/upload/useFileUpload.ts | 10 +++-- interface/src/i18n/de/index.ts | 7 ++- interface/src/i18n/en/index.ts | 7 ++- interface/src/i18n/i18n-types.ts | 44 ++++++++++++++++++- interface/src/project/HelpInformation.tsx | 2 +- interface/src/utils/useRest.ts | 14 +++--- 7 files changed, 75 insertions(+), 13 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 6d6ec4d4f..731ba3454 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -10,8 +10,12 @@ ## Changed +- Discovery in HomeAssistant don't work with custom base topic. [#596](https://github.com/emsesp/EMS-ESP32/issues/596) + ## **BREAKING CHANGES:** +- MQTT Discovery (Home Assistant) entity names are now prefixed with the hostname, e.g. `select.thermostat_hc1_mode` becomes `select.emsesp_thermostat_hc1_mode`. You will need to recreate any custom dashboards. + # [3.4.2] ## Added diff --git a/interface/src/components/upload/useFileUpload.ts b/interface/src/components/upload/useFileUpload.ts index 0cc12b1aa..aaa588ac3 100644 --- a/interface/src/components/upload/useFileUpload.ts +++ b/interface/src/components/upload/useFileUpload.ts @@ -5,11 +5,15 @@ import { useSnackbar } from 'notistack'; import { extractErrorMessage } from '../../utils'; import { FileUploadConfig } from '../../api/endpoints'; +import { useI18nContext } from '../../i18n/i18n-react'; + interface MediaUploadOptions { upload: (file: File, config?: FileUploadConfig) => AxiosPromise; } const useFileUpload = ({ upload }: MediaUploadOptions) => { + const { LL } = useI18nContext(); + const { enqueueSnackbar } = useSnackbar(); const [uploading, setUploading] = useState(false); const [uploadProgress, setUploadProgress] = useState(); @@ -42,13 +46,13 @@ const useFileUpload = ({ upload }: MediaUploadOptions) => { cancelToken: cancelToken.token }); resetUploadingStates(); - enqueueSnackbar('File uploaded', { variant: 'success' }); + enqueueSnackbar(LL.UPLOAD() + ' ' + LL.SUCCESSFUL(), { variant: 'success' }); } catch (error: unknown) { if (axios.isCancel(error)) { - enqueueSnackbar('Upload aborted', { variant: 'warning' }); + enqueueSnackbar(LL.UPLOAD() + ' ' + LL.ABORTED(), { variant: 'warning' }); } else { resetUploadingStates(); - enqueueSnackbar(extractErrorMessage(error, 'Upload failed'), { variant: 'error' }); + enqueueSnackbar(extractErrorMessage(error, LL.UPLOAD() + ' ' + LL.FAILED()), { variant: 'error' }); } } }; diff --git a/interface/src/i18n/de/index.ts b/interface/src/i18n/de/index.ts index 2974fc768..3249d7f89 100644 --- a/interface/src/i18n/de/index.ts +++ b/interface/src/i18n/de/index.ts @@ -9,6 +9,7 @@ const de: Translation = { PASSWORD: 'Passwort', DASHBOARD: 'Armaturenbrett', SETTINGS: 'Einstellungen', + SAVED: 'gespeichert', HELP: 'Hilfe', LOGGED_IN: 'Eingeloggt als {name}', PLEASE_SIGNIN: 'Bitte einloggen, um fortzufahren', @@ -142,7 +143,11 @@ const de: Translation = { HELP_INFORMATION_7: 'um eine neue Funktion anzufordern oder einen Fehler zu melden', HELP_INFORMATION_8: 'Überzeugen Sie sich auch', HELP_INFORMATION_9: 'und hängen Sie Ihre Systemdetails für eine schnellere Antwort an', - HELP_INFORMATION_10: 'EMS-ESP wird immer ein kostenloses Open-Source-Projekt sein. Bitte erwägen Sie, es mit einem ' + HELP_INFORMATION_10: 'EMS-ESP wird immer ein kostenloses Open-Source-Projekt sein. Bitte erwägen Sie, es mit einem', + UPLOAD: 'Hochladen', + ABORTED: 'abgebrochen', + FAILED: 'gescheitert', + SUCCESSFUL: 'erfolgreich' }; export default de; diff --git a/interface/src/i18n/en/index.ts b/interface/src/i18n/en/index.ts index 55b42ee6a..6b43b07e8 100644 --- a/interface/src/i18n/en/index.ts +++ b/interface/src/i18n/en/index.ts @@ -9,6 +9,7 @@ const en: BaseTranslation = { PASSWORD: 'Password', DASHBOARD: 'Dashboard', SETTINGS: 'Settings', + SAVED: 'saved', HELP: 'Help', LOGGED_IN: 'Logged in as {name}', PLEASE_SIGNIN: 'Please sign in to continue', @@ -142,7 +143,11 @@ const en: BaseTranslation = { HELP_INFORMATION_7: 'for requesting a new feature or reporting a bug', HELP_INFORMATION_8: 'Make sure you also', HELP_INFORMATION_9: 'and attach your system details for a faster response', - HELP_INFORMATION_10: 'EMS-ESP will always be a free and open-source project. Please consider supporting it with a ' + HELP_INFORMATION_10: 'EMS-ESP will always be a free and open-source project. Please consider supporting it with a', + UPLOAD: 'Upload', + ABORTED: 'aborted', + FAILED: 'failed', + SUCCESSFUL: 'successful' }; export default en; diff --git a/interface/src/i18n/i18n-types.ts b/interface/src/i18n/i18n-types.ts index bab8bbd9d..38d2a2e2e 100644 --- a/interface/src/i18n/i18n-types.ts +++ b/interface/src/i18n/i18n-types.ts @@ -46,6 +46,10 @@ type RootTranslation = { * Settings */ SETTINGS: string + /** + * saved + */ + SAVED: string /** * Help */ @@ -572,9 +576,25 @@ type RootTranslation = { */ HELP_INFORMATION_9: string /** - * EMS-ESP will always be a free and open-source project. Please consider supporting it with a + * EMS-ESP will always be a free and open-source project. Please consider supporting it with a */ HELP_INFORMATION_10: string + /** + * Upload + */ + UPLOAD: string + /** + * aborted + */ + ABORTED: string + /** + * failed + */ + FAILED: string + /** + * successful + */ + SUCCESSFUL: string } export type TranslationFunctions = { @@ -610,6 +630,10 @@ export type TranslationFunctions = { * Settings */ SETTINGS: () => LocalizedString + /** + * saved + */ + SAVED: () => LocalizedString /** * Help */ @@ -1125,9 +1149,25 @@ export type TranslationFunctions = { */ HELP_INFORMATION_9: () => LocalizedString /** - * EMS-ESP will always be a free and open-source project. Please consider supporting it with a + * EMS-ESP will always be a free and open-source project. Please consider supporting it with a */ HELP_INFORMATION_10: () => LocalizedString + /** + * Upload + */ + UPLOAD: () => LocalizedString + /** + * aborted + */ + ABORTED: () => LocalizedString + /** + * failed + */ + FAILED: () => LocalizedString + /** + * successful + */ + SUCCESSFUL: () => LocalizedString } export type Formatters = {} diff --git a/interface/src/project/HelpInformation.tsx b/interface/src/project/HelpInformation.tsx index 65392e5f9..8c0f6562f 100644 --- a/interface/src/project/HelpInformation.tsx +++ b/interface/src/project/HelpInformation.tsx @@ -114,7 +114,7 @@ const HelpInformation: FC = () => { - {LL.HELP_INFORMATION_10()} + {LL.HELP_INFORMATION_10()}  {'GitHub'} diff --git a/interface/src/utils/useRest.ts b/interface/src/utils/useRest.ts index e889e4521..a615f215e 100644 --- a/interface/src/utils/useRest.ts +++ b/interface/src/utils/useRest.ts @@ -4,12 +4,16 @@ import { AxiosPromise } from 'axios'; import { extractErrorMessage } from '.'; +import { useI18nContext } from '../i18n/i18n-react'; + export interface RestRequestOptions { read: () => AxiosPromise; update?: (value: D) => AxiosPromise; } export const useRest = ({ read, update }: RestRequestOptions) => { + const { LL } = useI18nContext(); + const { enqueueSnackbar } = useSnackbar(); const [saving, setSaving] = useState(false); @@ -23,11 +27,11 @@ export const useRest = ({ read, update }: RestRequestOptions) => { try { setData((await read()).data); } catch (error: unknown) { - const message = extractErrorMessage(error, 'Problem loading data'); + const message = extractErrorMessage(error, LL.PROBLEM_LOADING()); enqueueSnackbar(message, { variant: 'error' }); setErrorMessage(message); } - }, [read, enqueueSnackbar]); + }, [read, enqueueSnackbar, LL]); const save = useCallback( async (toSave: D) => { @@ -43,17 +47,17 @@ export const useRest = ({ read, update }: RestRequestOptions) => { if (response.status === 202) { setRestartNeeded(true); } else { - enqueueSnackbar('Settings saved', { variant: 'success' }); + enqueueSnackbar(LL.SETTINGS() + ' ' + LL.SAVED(), { variant: 'success' }); } } catch (error: unknown) { - const message = extractErrorMessage(error, 'Problem saving data'); + const message = extractErrorMessage(error, LL.PROBLEM_UPDATING()); enqueueSnackbar(message, { variant: 'error' }); setErrorMessage(message); } finally { setSaving(false); } }, - [update, enqueueSnackbar] + [update, enqueueSnackbar, LL] ); const saveData = () => data && save(data);