@samitouri / QOSami-HFS / commits / c0248b6d

better code

Massimo Melina committed Dec 7, 2025 at 14:51 UTC c0248b6d38303be471c4a23503fe28d0172c949e
5 files changed +11 -9
frontend/src/i18n.ts
+2 -2
@@ -1,7 +1,7 @@
1 import { i18nFromTranslations } from '../../src/i18n'
2 -import { getHFS, urlParams } from '@hfs/shared'
2 +import { EMBEDDED_LANGUAGE, getHFS, urlParams } from '@hfs/shared'
3 import { state } from './state'
4
5 -const i18n = i18nFromTranslations(getHFS().lang || {})
5 +const i18n = i18nFromTranslations(getHFS().lang || {}, EMBEDDED_LANGUAGE)
6 i18n.state.disabled = !urlParams.lang && state.disableTranslation
7 export default i18n
\ No newline at end of file
src/cross-const.ts
+1
@@ -13,6 +13,7 @@ export const MTIME_CHECK = 'x-mtime-check'
13 export const PREVIOUS_TAG = 'previous'
14 export const ALLOW_SESSION_IP_CHANGE = 'allow_session_ip_change'
15 export const HIDE_IN_TESTS = 'hideInTests' // elements that have variable size, where masking would produce changes, must be hidden
16 +export const EMBEDDED_LANGUAGE = 'en' // frontend includes this language in the code, and not need to import the translation json
17
18 export const HTTP_OK = 200
19 export const HTTP_NO_CONTENT = 204
src/lang.ts
+1 -1
@@ -5,13 +5,13 @@ import { readFile } from 'fs/promises'
5 import { defineConfig } from './config'
6 import { watchLoad } from './watchLoad'
7 import EMBEDDED_TRANSLATIONS from './langs/embedded'
8 +import { EMBEDDED_LANGUAGE } from './const'
9 import { mapPlugins } from './plugins'
10 import { join } from 'path'
11 import _ from 'lodash'
12
13 const PREFIX = 'hfs-lang-'
14 const SUFFIX = '.json'
14 -const EMBEDDED_LANGUAGE = 'en'
15
16 export function code2file(code: string) {
17 return PREFIX + code.toLowerCase() + SUFFIX
src/plugins.ts
+3 -2
@@ -4,7 +4,8 @@ import glob from 'fast-glob'
4 import { watchLoad } from './watchLoad'
5 import _ from 'lodash'
6 import {
7 - API_VERSION, APP_PATH, COMPATIBLE_API_VERSION, HTTP_NOT_FOUND, IS_WINDOWS, MIME_AUTO, PLUGINS_PUB_URI
7 + API_VERSION, APP_PATH, COMPATIBLE_API_VERSION, IS_WINDOWS, MIME_AUTO, PLUGINS_PUB_URI, EMBEDDED_LANGUAGE,
8 + HTTP_NOT_FOUND,
9 } from './const'
10 import * as Const from './const'
11 import Koa from 'koa'
@@ -560,7 +561,7 @@ function watchPlugin(id: string, path: string) {
561 return ret
562 },
563 async i18n(ctx: any) {
563 - return i18nFromTranslations(await getLangData(ctx))
564 + return i18nFromTranslations(await getLangData(ctx), EMBEDDED_LANGUAGE)
565 },
566 })
567 const folder = dirname(module)
src/serveGuiFiles.ts
+4 -4
@@ -136,10 +136,10 @@ async function treatIndex(ctx: Koa.Context, filesUri: string, body: string) {
136 <style>
137 :root {
138 ${_.map(plugins, (configs, pluginName) => // make plugin configs accessible via css
139 - _.map(configs, (v, k) => {
140 - v = serializeCss(v)
141 - return typeof v === 'string' && `\n--${pluginName}-${k}: ${v};`
142 - }).filter(Boolean).join('')).join('')}
139 + _.map(configs, (v, k) => {
140 + v = serializeCss(v)
141 + return typeof v === 'string' && `\n--${pluginName}-${k}: ${v};`
142 + }).filter(Boolean).join('')).join('')}
143 }
144 ${isFrontend && getSection('style')}
145 </style>