mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
generate i18n on build
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
// 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
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,31 +0,0 @@
|
||||
// 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'),
|
||||
nl: () => import('./nl'),
|
||||
no: () => import('./no'),
|
||||
pl: () => import('./pl'),
|
||||
se: () => import('./se'),
|
||||
}
|
||||
|
||||
const updateDictionary = (locale: Locales, dictionary: Partial<Translations>): Translations =>
|
||||
loadedLocales[locale] = { ...loadedLocales[locale], ...dictionary }
|
||||
|
||||
export const importLocaleAsync = async (locale: Locales): Promise<Translations> =>
|
||||
(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))
|
||||
@@ -1,34 +0,0 @@
|
||||
// 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'
|
||||
import nl from './nl'
|
||||
import no from './no'
|
||||
import pl from './pl'
|
||||
import se from './se'
|
||||
|
||||
const localeTranslations = {
|
||||
de,
|
||||
en,
|
||||
nl,
|
||||
no,
|
||||
pl,
|
||||
se,
|
||||
}
|
||||
|
||||
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))
|
||||
@@ -1,39 +0,0 @@
|
||||
// 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 type { LocaleTranslationFunctions, TranslateByString } from 'typesafe-i18n'
|
||||
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',
|
||||
'nl',
|
||||
'no',
|
||||
'pl',
|
||||
'se'
|
||||
]
|
||||
|
||||
export const isLocale = (locale: string): locale is Locales => locales.includes(locale as Locales)
|
||||
|
||||
export const loadedLocales: Record<Locales, Translations> = {} as Record<Locales, Translations>
|
||||
|
||||
export const loadedFormatters: Record<Locales, Formatters> = {} as Record<Locales, Formatters>
|
||||
|
||||
export const i18nString = (locale: Locales): TranslateByString => initI18nString<Locales, Formatters>(locale, loadedFormatters[locale])
|
||||
|
||||
export const i18nObject = (locale: Locales): TranslationFunctions =>
|
||||
initI18nObject<Locales, Translations, TranslationFunctions, Formatters>(
|
||||
locale,
|
||||
loadedLocales[locale],
|
||||
loadedFormatters[locale]
|
||||
)
|
||||
|
||||
export const i18n = (): LocaleTranslationFunctions<Locales, Translations, TranslationFunctions> =>
|
||||
initI18n<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters)
|
||||
|
||||
export const detectLocale = (...detectors: LocaleDetector[]): Locales => detectLocaleFn<Locales>(baseLocale, locales, ...detectors)
|
||||
@@ -20,16 +20,17 @@ def flagExists(flag):
|
||||
|
||||
def buildWeb():
|
||||
os.chdir("interface")
|
||||
print("Building interface with npm")
|
||||
print("Building web interface...")
|
||||
try:
|
||||
env.Execute("npm install")
|
||||
env.Execute("npx typesafe-i18n --no-watch")
|
||||
env.Execute("npm run build")
|
||||
buildPath = Path("build")
|
||||
wwwPath = Path("../data/www")
|
||||
if wwwPath.exists() and wwwPath.is_dir():
|
||||
rmtree(wwwPath)
|
||||
if not flagExists("PROGMEM_WWW"):
|
||||
print("Copying interface to data directory")
|
||||
print("Copying web files to data directory")
|
||||
copytree(buildPath, wwwPath)
|
||||
for currentpath, folders, files in os.walk(wwwPath):
|
||||
for file in files:
|
||||
@@ -40,4 +41,4 @@ def buildWeb():
|
||||
if (len(BUILD_TARGETS) == 0 or "upload" in BUILD_TARGETS):
|
||||
buildWeb()
|
||||
else:
|
||||
print("Skipping build interface step for target(s): " + ", ".join(BUILD_TARGETS))
|
||||
print("Skipping build web interface for target(s): " + ", ".join(BUILD_TARGETS))
|
||||
Reference in New Issue
Block a user