@samitouri / QOSami-HFS / commits / edd09e7f

removed legacy code

Massimo Melina committed Jun 28, 2023 at 22:22 UTC edd09e7fb1981835a1d03ea77dca4608038deeab
1 file changed +11 -12
frontend/src/i18n.ts
+11 -12
@@ -2,9 +2,12 @@ import { findFirst, getHFS } from './misc'
2 import { createElement as h, Fragment } from 'react'
3 import { proxy, useSnapshot } from 'valtio'
4
5 -const state = proxy<{ langs: string[], embedded: string }>({ embedded: '', langs: [] })
5 +const translations = getHFS().lang || {} // all dictionaries
6 +const state = proxy<{ langs: string[], embedded: string }>({
7 + embedded: '',
8 + langs: Object.keys(translations)
9 +})
10 const warns = new Set() // avoid duplicates
7 -let loaded: any // all dictionaries
11
12 // the hook ensures translation is refreshed when language changes
13 export function useI18N() {
@@ -13,9 +16,7 @@ export function useI18N() {
16 }
17
18 export function I18Nprovider({ embedded='en', ...props }) {
16 - loaded = getHFS().lang
19 state.embedded = embedded
18 - state.langs = Object.keys(loaded||{})
20 return h(Fragment, props)
21 }
22
@@ -30,14 +31,12 @@ export function t(keyOrTpl: string | string[] | TemplateStringsArray, params?: a
31 let found
32 let selectedLang = '' // keep track of where we find the translation
33 const { langs, embedded } = state
33 - if (loaded) {
34 - for (const key of keys) {
35 - found = findFirst(langs, lang => loaded[selectedLang=lang]?.translate?.[key])
36 - if (found) break
37 - if (selectedLang && langs[0] !== embedded && !warns.has(key)) {
38 - warns.add(key)
39 - console.debug("miss i18n:", key)
40 - }
34 + for (const key of keys) {
35 + found = findFirst(langs, lang => translations[selectedLang=lang]?.translate?.[key])
36 + if (found) break
37 + if (selectedLang && langs[0] !== embedded && !warns.has(key)) {
38 + warns.add(key)
39 + console.debug("miss i18n:", key)
40 }
41 }
42 if (!found) {