mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
Multi-language/I18n support #22
This commit is contained in:
49
interface/src/i18n/de/index.ts
Normal file
49
interface/src/i18n/de/index.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import type { Translation } from '../i18n-types';
|
||||
|
||||
const de: Translation = {
|
||||
LANGUAGE: 'Sprache',
|
||||
IS_REQUIRED: 'ist nötig',
|
||||
SIGN_IN: 'Einloggen',
|
||||
USERNAME: 'Nutzername',
|
||||
PASSWORD: 'Passwort',
|
||||
DASHBOARD: 'Armaturenbrett',
|
||||
SETTINGS: 'Einstellungen',
|
||||
HELP: 'Hilfe',
|
||||
LOGGED_IN: 'Eingeloggt als {name}',
|
||||
PLEASE_SIGNIN: 'Bitte einloggen, um fortzufahren',
|
||||
UPLOAD_SUCCESSFUL: 'Hochladen erfolgreich',
|
||||
INVALID_LOGIN: 'Ungültige Login Daten',
|
||||
NETWORK_CONNECTION: 'Netzwerkverbindung',
|
||||
SECURITY: 'Sicherheit',
|
||||
NETWORK_TIME: 'Netzwerkzeit',
|
||||
ONOFF_CAP: 'AN/AUS',
|
||||
ONOFF: 'an/aus',
|
||||
TYPE: 'Typ',
|
||||
DESCRIPTION: 'Bezeichnung',
|
||||
ENTITIES: 'Entitäten',
|
||||
REFRESH: 'Aktualisierung',
|
||||
EXPORT: 'Export',
|
||||
ENTITY_NAME: 'Entitätsname',
|
||||
VALUE: 'Wert',
|
||||
SHOW_FAV: 'nur Favoriten anzeigen',
|
||||
DEVICE_SENSOR_DATA: 'Device und Sensordaten',
|
||||
DEVICES_SENSORS: 'Devices & Sensoren',
|
||||
ATTACHED_SENSORS: 'Angeschlossene EMS-ESP Sensoren',
|
||||
RUN_COMMAND: 'Befehl ausführen',
|
||||
CHANGE_VALUE: 'Wert ändern',
|
||||
CANCEL: 'Absagen',
|
||||
RESET: 'Zurücksetzen',
|
||||
SEND: 'Senden',
|
||||
SAVE: 'Speichern',
|
||||
REMOVE: 'Entfernen',
|
||||
PROBLEM_UPDATING: 'Problem beim Aktualisieren',
|
||||
ACCESS_DENIED: 'Zugriff abgelehnt',
|
||||
ANALOG_SENSOR: 'Analoger Sensor {cmd}',
|
||||
TEMP_SENSOR: 'Temperatursensor {cmd}',
|
||||
WRITE_COMMAND: 'Befehl schreiben {cmd}',
|
||||
EMS_BUS_WARNING:
|
||||
'EMS-Bus getrennt. Wenn diese Warnung nach einigen Sekunden immer noch besteht, überprüfen Sie bitte die Einstellungen und das Board-Profil',
|
||||
EMS_BUS_SCANNING: 'Scannen nach EMS devices...'
|
||||
};
|
||||
|
||||
export default de;
|
||||
49
interface/src/i18n/en/index.ts
Normal file
49
interface/src/i18n/en/index.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import type { BaseTranslation } from '../i18n-types';
|
||||
|
||||
const en: BaseTranslation = {
|
||||
LANGUAGE: 'Language',
|
||||
IS_REQUIRED: 'is required',
|
||||
SIGN_IN: 'Sign In',
|
||||
USERNAME: 'Username',
|
||||
PASSWORD: 'Password',
|
||||
DASHBOARD: 'Dashboard',
|
||||
SETTINGS: 'Settings',
|
||||
HELP: 'Help',
|
||||
LOGGED_IN: 'Logged in as {name}',
|
||||
PLEASE_SIGNIN: 'Please sign in to continue',
|
||||
UPLOAD_SUCCESSFUL: 'Upload successful',
|
||||
INVALID_LOGIN: 'Invalid login details',
|
||||
NETWORK_CONNECTION: 'Network Connection',
|
||||
SECURITY: 'Security',
|
||||
NETWORK_TIME: 'Network Time',
|
||||
ONOFF_CAP: 'ON/OFF',
|
||||
ONOFF: 'on/off',
|
||||
TYPE: 'Type',
|
||||
DESCRIPTION: 'Description',
|
||||
ENTITIES: 'Entities',
|
||||
REFRESH: 'Refresh',
|
||||
EXPORT: 'Export',
|
||||
ENTITY_NAME: 'Entity Name',
|
||||
VALUE: 'Value',
|
||||
SHOW_FAV: 'only show favorites',
|
||||
DEVICE_SENSOR_DATA: 'Device and Sensor Data',
|
||||
DEVICES_SENSORS: 'Devices & Sensors',
|
||||
ATTACHED_SENSORS: 'Attached EMS-ESP Sensors',
|
||||
RUN_COMMAND: 'Call Command',
|
||||
CHANGE_VALUE: 'Change Value',
|
||||
CANCEL: 'Cancel',
|
||||
RESET: 'Reset',
|
||||
SEND: 'Send',
|
||||
SAVE: 'Save',
|
||||
REMOVE: 'Remove',
|
||||
PROBLEM_UPDATING: 'Problem updating',
|
||||
ACCESS_DENIED: 'Access Denied',
|
||||
ANALOG_SENSOR: 'Analog Sensor {cmd}',
|
||||
TEMP_SENSOR: 'Temperature Sensor {cmd}',
|
||||
WRITE_COMMAND: 'Write command {cmd}',
|
||||
EMS_BUS_WARNING:
|
||||
'EMS bus disconnected. If this warning still persists after a few seconds please check settings and board profile',
|
||||
EMS_BUS_SCANNING: 'Scanning for EMS devices...'
|
||||
};
|
||||
|
||||
export default en;
|
||||
11
interface/src/i18n/formatters.ts
Normal file
11
interface/src/i18n/formatters.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { FormattersInitializer } from 'typesafe-i18n';
|
||||
import type { Locales, Formatters } from './i18n-types';
|
||||
import { date } from 'typesafe-i18n/formatters';
|
||||
|
||||
export const initFormatters: FormattersInitializer<Locales, Formatters> = (locale: Locales) => {
|
||||
const formatters: Formatters = {
|
||||
weekday: date(locale, { weekday: 'long' })
|
||||
};
|
||||
|
||||
return formatters;
|
||||
};
|
||||
16
interface/src/i18n/i18n-react.tsx
Normal file
16
interface/src/i18n/i18n-react.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
|
||||
/* eslint-disable */
|
||||
|
||||
import { useContext } from 'react'
|
||||
import { initI18nReact } from 'typesafe-i18n/react'
|
||||
import type { I18nContextType } from 'typesafe-i18n/react'
|
||||
import type { Formatters, Locales, TranslationFunctions, Translations } from './i18n-types'
|
||||
import { loadedFormatters, loadedLocales } from './i18n-util'
|
||||
|
||||
const { component: TypesafeI18n, context: I18nContext } = initI18nReact<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters)
|
||||
|
||||
const useI18nContext = (): I18nContextType<Locales, Translations, TranslationFunctions> => useContext(I18nContext)
|
||||
|
||||
export { I18nContext, useI18nContext }
|
||||
|
||||
export default TypesafeI18n
|
||||
362
interface/src/i18n/i18n-types.ts
Normal file
362
interface/src/i18n/i18n-types.ts
Normal file
@@ -0,0 +1,362 @@
|
||||
// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
|
||||
/* eslint-disable */
|
||||
import type { BaseTranslation as BaseTranslationType, LocalizedString, RequiredParams } from 'typesafe-i18n'
|
||||
|
||||
export type BaseTranslation = BaseTranslationType
|
||||
export type BaseLocale = 'en'
|
||||
|
||||
export type Locales =
|
||||
| 'de'
|
||||
| 'en'
|
||||
|
||||
export type Translation = RootTranslation
|
||||
|
||||
export type Translations = RootTranslation
|
||||
|
||||
type RootTranslation = {
|
||||
/**
|
||||
* Language
|
||||
*/
|
||||
LANGUAGE: string
|
||||
/**
|
||||
* is required
|
||||
*/
|
||||
IS_REQUIRED: string
|
||||
/**
|
||||
* Sign In
|
||||
*/
|
||||
SIGN_IN: string
|
||||
/**
|
||||
* Username
|
||||
*/
|
||||
USERNAME: string
|
||||
/**
|
||||
* Password
|
||||
*/
|
||||
PASSWORD: string
|
||||
/**
|
||||
* Dashboard
|
||||
*/
|
||||
DASHBOARD: string
|
||||
/**
|
||||
* Settings
|
||||
*/
|
||||
SETTINGS: string
|
||||
/**
|
||||
* Help
|
||||
*/
|
||||
HELP: string
|
||||
/**
|
||||
* Logged in as {name}
|
||||
* @param {unknown} name
|
||||
*/
|
||||
LOGGED_IN: RequiredParams<'name'>
|
||||
/**
|
||||
* Please sign in to continue
|
||||
*/
|
||||
PLEASE_SIGNIN: string
|
||||
/**
|
||||
* Upload successful
|
||||
*/
|
||||
UPLOAD_SUCCESSFUL: string
|
||||
/**
|
||||
* Invalid login details
|
||||
*/
|
||||
INVALID_LOGIN: string
|
||||
/**
|
||||
* Network Connection
|
||||
*/
|
||||
NETWORK_CONNECTION: string
|
||||
/**
|
||||
* Security
|
||||
*/
|
||||
SECURITY: string
|
||||
/**
|
||||
* Network Time
|
||||
*/
|
||||
NETWORK_TIME: string
|
||||
/**
|
||||
* ON/OFF
|
||||
*/
|
||||
ONOFF_CAP: string
|
||||
/**
|
||||
* on/off
|
||||
*/
|
||||
ONOFF: string
|
||||
/**
|
||||
* Type
|
||||
*/
|
||||
TYPE: string
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
DESCRIPTION: string
|
||||
/**
|
||||
* Entities
|
||||
*/
|
||||
ENTITIES: string
|
||||
/**
|
||||
* Refresh
|
||||
*/
|
||||
REFRESH: string
|
||||
/**
|
||||
* Export
|
||||
*/
|
||||
EXPORT: string
|
||||
/**
|
||||
* Entity Name
|
||||
*/
|
||||
ENTITY_NAME: string
|
||||
/**
|
||||
* Value
|
||||
*/
|
||||
VALUE: string
|
||||
/**
|
||||
* only show favorites
|
||||
*/
|
||||
SHOW_FAV: string
|
||||
/**
|
||||
* Device and Sensor Data
|
||||
*/
|
||||
DEVICE_SENSOR_DATA: string
|
||||
/**
|
||||
* Devices & Sensors
|
||||
*/
|
||||
DEVICES_SENSORS: string
|
||||
/**
|
||||
* Attached EMS-ESP Sensors
|
||||
*/
|
||||
ATTACHED_SENSORS: string
|
||||
/**
|
||||
* Call Command
|
||||
*/
|
||||
RUN_COMMAND: string
|
||||
/**
|
||||
* Change Value
|
||||
*/
|
||||
CHANGE_VALUE: string
|
||||
/**
|
||||
* Cancel
|
||||
*/
|
||||
CANCEL: string
|
||||
/**
|
||||
* Reset
|
||||
*/
|
||||
RESET: string
|
||||
/**
|
||||
* Send
|
||||
*/
|
||||
SEND: string
|
||||
/**
|
||||
* Save
|
||||
*/
|
||||
SAVE: string
|
||||
/**
|
||||
* Remove
|
||||
*/
|
||||
REMOVE: string
|
||||
/**
|
||||
* Problem updating
|
||||
*/
|
||||
PROBLEM_UPDATING: string
|
||||
/**
|
||||
* Access Denied
|
||||
*/
|
||||
ACCESS_DENIED: string
|
||||
/**
|
||||
* Analog Sensor {cmd}
|
||||
* @param {unknown} cmd
|
||||
*/
|
||||
ANALOG_SENSOR: RequiredParams<'cmd'>
|
||||
/**
|
||||
* Temperature Sensor {cmd}
|
||||
* @param {unknown} cmd
|
||||
*/
|
||||
TEMP_SENSOR: RequiredParams<'cmd'>
|
||||
/**
|
||||
* Write command {cmd}
|
||||
* @param {unknown} cmd
|
||||
*/
|
||||
WRITE_COMMAND: RequiredParams<'cmd'>
|
||||
/**
|
||||
* EMS bus disconnected. If this warning still persists after a few seconds please check settings and board profile
|
||||
*/
|
||||
EMS_BUS_WARNING: string
|
||||
/**
|
||||
* Scanning for EMS devices...
|
||||
*/
|
||||
EMS_BUS_SCANNING: string
|
||||
}
|
||||
|
||||
export type TranslationFunctions = {
|
||||
/**
|
||||
* Language
|
||||
*/
|
||||
LANGUAGE: () => LocalizedString
|
||||
/**
|
||||
* is required
|
||||
*/
|
||||
IS_REQUIRED: () => LocalizedString
|
||||
/**
|
||||
* Sign In
|
||||
*/
|
||||
SIGN_IN: () => LocalizedString
|
||||
/**
|
||||
* Username
|
||||
*/
|
||||
USERNAME: () => LocalizedString
|
||||
/**
|
||||
* Password
|
||||
*/
|
||||
PASSWORD: () => LocalizedString
|
||||
/**
|
||||
* Dashboard
|
||||
*/
|
||||
DASHBOARD: () => LocalizedString
|
||||
/**
|
||||
* Settings
|
||||
*/
|
||||
SETTINGS: () => LocalizedString
|
||||
/**
|
||||
* Help
|
||||
*/
|
||||
HELP: () => LocalizedString
|
||||
/**
|
||||
* Logged in as {name}
|
||||
*/
|
||||
LOGGED_IN: (arg: { name: unknown }) => LocalizedString
|
||||
/**
|
||||
* Please sign in to continue
|
||||
*/
|
||||
PLEASE_SIGNIN: () => LocalizedString
|
||||
/**
|
||||
* Upload successful
|
||||
*/
|
||||
UPLOAD_SUCCESSFUL: () => LocalizedString
|
||||
/**
|
||||
* Invalid login details
|
||||
*/
|
||||
INVALID_LOGIN: () => LocalizedString
|
||||
/**
|
||||
* Network Connection
|
||||
*/
|
||||
NETWORK_CONNECTION: () => LocalizedString
|
||||
/**
|
||||
* Security
|
||||
*/
|
||||
SECURITY: () => LocalizedString
|
||||
/**
|
||||
* Network Time
|
||||
*/
|
||||
NETWORK_TIME: () => LocalizedString
|
||||
/**
|
||||
* ON/OFF
|
||||
*/
|
||||
ONOFF_CAP: () => LocalizedString
|
||||
/**
|
||||
* on/off
|
||||
*/
|
||||
ONOFF: () => LocalizedString
|
||||
/**
|
||||
* Type
|
||||
*/
|
||||
TYPE: () => LocalizedString
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
DESCRIPTION: () => LocalizedString
|
||||
/**
|
||||
* Entities
|
||||
*/
|
||||
ENTITIES: () => LocalizedString
|
||||
/**
|
||||
* Refresh
|
||||
*/
|
||||
REFRESH: () => LocalizedString
|
||||
/**
|
||||
* Export
|
||||
*/
|
||||
EXPORT: () => LocalizedString
|
||||
/**
|
||||
* Entity Name
|
||||
*/
|
||||
ENTITY_NAME: () => LocalizedString
|
||||
/**
|
||||
* Value
|
||||
*/
|
||||
VALUE: () => LocalizedString
|
||||
/**
|
||||
* only show favorites
|
||||
*/
|
||||
SHOW_FAV: () => LocalizedString
|
||||
/**
|
||||
* Device and Sensor Data
|
||||
*/
|
||||
DEVICE_SENSOR_DATA: () => LocalizedString
|
||||
/**
|
||||
* Devices & Sensors
|
||||
*/
|
||||
DEVICES_SENSORS: () => LocalizedString
|
||||
/**
|
||||
* Attached EMS-ESP Sensors
|
||||
*/
|
||||
ATTACHED_SENSORS: () => LocalizedString
|
||||
/**
|
||||
* Call Command
|
||||
*/
|
||||
RUN_COMMAND: () => LocalizedString
|
||||
/**
|
||||
* Change Value
|
||||
*/
|
||||
CHANGE_VALUE: () => LocalizedString
|
||||
/**
|
||||
* Cancel
|
||||
*/
|
||||
CANCEL: () => LocalizedString
|
||||
/**
|
||||
* Reset
|
||||
*/
|
||||
RESET: () => LocalizedString
|
||||
/**
|
||||
* Send
|
||||
*/
|
||||
SEND: () => LocalizedString
|
||||
/**
|
||||
* Save
|
||||
*/
|
||||
SAVE: () => LocalizedString
|
||||
/**
|
||||
* Remove
|
||||
*/
|
||||
REMOVE: () => LocalizedString
|
||||
/**
|
||||
* Problem updating
|
||||
*/
|
||||
PROBLEM_UPDATING: () => LocalizedString
|
||||
/**
|
||||
* Access Denied
|
||||
*/
|
||||
ACCESS_DENIED: () => LocalizedString
|
||||
/**
|
||||
* Analog Sensor {cmd}
|
||||
*/
|
||||
ANALOG_SENSOR: (arg: { cmd: unknown }) => LocalizedString
|
||||
/**
|
||||
* Temperature Sensor {cmd}
|
||||
*/
|
||||
TEMP_SENSOR: (arg: { cmd: unknown }) => LocalizedString
|
||||
/**
|
||||
* Write command {cmd}
|
||||
*/
|
||||
WRITE_COMMAND: (arg: { cmd: unknown }) => LocalizedString
|
||||
/**
|
||||
* EMS bus disconnected. If this warning still persists after a few seconds please check settings and board profile
|
||||
*/
|
||||
EMS_BUS_WARNING: () => LocalizedString
|
||||
/**
|
||||
* Scanning for EMS devices...
|
||||
*/
|
||||
EMS_BUS_SCANNING: () => LocalizedString
|
||||
}
|
||||
|
||||
export type Formatters = {}
|
||||
27
interface/src/i18n/i18n-util.async.ts
Normal file
27
interface/src/i18n/i18n-util.async.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
|
||||
/* eslint-disable */
|
||||
|
||||
import { initFormatters } from './formatters'
|
||||
import type { Locales, Translations } from './i18n-types'
|
||||
import { loadedFormatters, loadedLocales, locales } from './i18n-util'
|
||||
|
||||
const localeTranslationLoaders = {
|
||||
de: () => import('./de'),
|
||||
en: () => import('./en'),
|
||||
}
|
||||
|
||||
const updateDictionary = (locale: Locales, dictionary: Partial<Translations>) =>
|
||||
loadedLocales[locale] = { ...loadedLocales[locale], ...dictionary }
|
||||
|
||||
export const importLocaleAsync = async (locale: Locales) =>
|
||||
(await localeTranslationLoaders[locale]()).default as unknown as Translations
|
||||
|
||||
export const loadLocaleAsync = async (locale: Locales): Promise<void> => {
|
||||
updateDictionary(locale, await importLocaleAsync(locale))
|
||||
loadFormatters(locale)
|
||||
}
|
||||
|
||||
export const loadAllLocalesAsync = (): Promise<void[]> => Promise.all(locales.map(loadLocaleAsync))
|
||||
|
||||
export const loadFormatters = (locale: Locales): void =>
|
||||
void (loadedFormatters[locale] = initFormatters(locale))
|
||||
26
interface/src/i18n/i18n-util.sync.ts
Normal file
26
interface/src/i18n/i18n-util.sync.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
|
||||
/* eslint-disable */
|
||||
|
||||
import { initFormatters } from './formatters'
|
||||
import type { Locales, Translations } from './i18n-types'
|
||||
import { loadedFormatters, loadedLocales, locales } from './i18n-util'
|
||||
|
||||
import de from './de'
|
||||
import en from './en'
|
||||
|
||||
const localeTranslations = {
|
||||
de,
|
||||
en,
|
||||
}
|
||||
|
||||
export const loadLocale = (locale: Locales): void => {
|
||||
if (loadedLocales[locale]) return
|
||||
|
||||
loadedLocales[locale] = localeTranslations[locale] as unknown as Translations
|
||||
loadFormatters(locale)
|
||||
}
|
||||
|
||||
export const loadAllLocales = (): void => locales.forEach(loadLocale)
|
||||
|
||||
export const loadFormatters = (locale: Locales): void =>
|
||||
void (loadedFormatters[locale] = initFormatters(locale))
|
||||
31
interface/src/i18n/i18n-util.ts
Normal file
31
interface/src/i18n/i18n-util.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
|
||||
/* eslint-disable */
|
||||
|
||||
import { i18n as initI18n, i18nObject as initI18nObject, i18nString as initI18nString } from 'typesafe-i18n'
|
||||
import type { LocaleDetector } from 'typesafe-i18n/detectors'
|
||||
import { detectLocale as detectLocaleFn } from 'typesafe-i18n/detectors'
|
||||
import type { Formatters, Locales, Translations, TranslationFunctions } from './i18n-types'
|
||||
|
||||
export const baseLocale: Locales = 'en'
|
||||
|
||||
export const locales: Locales[] = [
|
||||
'de',
|
||||
'en'
|
||||
]
|
||||
|
||||
export const loadedLocales = {} as Record<Locales, Translations>
|
||||
|
||||
export const loadedFormatters = {} as Record<Locales, Formatters>
|
||||
|
||||
export const i18nString = (locale: Locales) => initI18nString<Locales, Formatters>(locale, loadedFormatters[locale])
|
||||
|
||||
export const i18nObject = (locale: Locales) =>
|
||||
initI18nObject<Locales, Translations, TranslationFunctions, Formatters>(
|
||||
locale,
|
||||
loadedLocales[locale],
|
||||
loadedFormatters[locale]
|
||||
)
|
||||
|
||||
export const i18n = () => initI18n<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters)
|
||||
|
||||
export const detectLocale = (...detectors: LocaleDetector[]) => detectLocaleFn<Locales>(baseLocale, locales, ...detectors)
|
||||
Reference in New Issue
Block a user