upload translations

This commit is contained in:
proddy
2022-08-27 13:02:04 +02:00
parent c8848a9e76
commit 7122e878a5
7 changed files with 75 additions and 13 deletions

View File

@@ -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

View File

@@ -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<void>;
}
const useFileUpload = ({ upload }: MediaUploadOptions) => {
const { LL } = useI18nContext();
const { enqueueSnackbar } = useSnackbar();
const [uploading, setUploading] = useState<boolean>(false);
const [uploadProgress, setUploadProgress] = useState<ProgressEvent>();
@@ -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' });
}
}
};

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 = {}

View File

@@ -114,7 +114,7 @@ const HelpInformation: FC = () => {
<Box border={1} p={1} mt={4}>
<Typography align="center" variant="h6" color="orange">
{LL.HELP_INFORMATION_10()}
{LL.HELP_INFORMATION_10()}&nbsp;
<Link href="https://github.com/emsesp/EMS-ESP32" color="primary">
{'GitHub'}
</Link>

View File

@@ -4,12 +4,16 @@ import { AxiosPromise } from 'axios';
import { extractErrorMessage } from '.';
import { useI18nContext } from '../i18n/i18n-react';
export interface RestRequestOptions<D> {
read: () => AxiosPromise<D>;
update?: (value: D) => AxiosPromise<D>;
}
export const useRest = <D>({ read, update }: RestRequestOptions<D>) => {
const { LL } = useI18nContext();
const { enqueueSnackbar } = useSnackbar();
const [saving, setSaving] = useState<boolean>(false);
@@ -23,11 +27,11 @@ export const useRest = <D>({ read, update }: RestRequestOptions<D>) => {
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 = <D>({ read, update }: RestRequestOptions<D>) => {
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);