From 3257e90bc1d223e08d1d80333d12869e3ce6ab94 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 17 Jan 2021 13:07:39 +0100 Subject: [PATCH] Fixed some missing translations and fixed a small bug --- shared/js/i18n/localize.ts | 24 +++++++++++++------- shared/js/log.ts | 2 +- shared/js/ui/modal/channel-edit/Renderer.tsx | 18 +++++++-------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/shared/js/i18n/localize.ts b/shared/js/i18n/localize.ts index 74a1ac47..b47f2a4e 100644 --- a/shared/js/i18n/localize.ts +++ b/shared/js/i18n/localize.ts @@ -1,4 +1,4 @@ -import {LogCategory, logError, logInfo, logWarn} from "../log"; +import {LogCategory, logDebug, logError, logInfo, logTrace, logWarn} from "../log"; import {guid} from "../crypto/uid"; import {Settings, StaticSettings} from "../settings"; import * as loader from "tc-loader"; @@ -48,22 +48,29 @@ export interface TranslationRepository { } let translations: Translation[] = []; -let fast_translate: { [key:string]:string; } = {}; +let translateCache: { [key:string]: string; } = {}; export function tr(message: string, key?: string) { - const sloppy = fast_translate[message]; - if(sloppy) return sloppy; + const sloppy = translateCache[message]; + if(sloppy) { + return sloppy; + } - logInfo(LogCategory.I18N, "Translating \"%s\". Default: \"%s\"", key, message); + logTrace(LogCategory.I18N, "Translating \"%s\". Default: \"%s\"", key, message); - let translated = message; + let translated; for(const translation of translations) { - if(translation.key.message == message) { + if(translation.key.message === message) { translated = translation.translated; break; } } - fast_translate[message] = translated; + if(typeof translated === "string") { + translateCache[message] = translated; + } else { + logDebug(LogCategory.I18N, "Missing translation for \"%s\".", message); + translateCache[message] = translated = message; + } return translated; } @@ -316,6 +323,7 @@ export async function initialize() { if(cfg.current_translation_url) { try { await load_file(cfg.current_translation_url, cfg.current_translation_path); + translateCache = {}; } catch (error) { logError(LogCategory.I18N, tr("Failed to initialize selected translation: %o"), error); const show_error = () => { diff --git a/shared/js/log.ts b/shared/js/log.ts index dfc75909..72c1a4ed 100644 --- a/shared/js/log.ts +++ b/shared/js/log.ts @@ -68,7 +68,7 @@ export let enabled_mapping = new Map([ [LogCategory.VOICE, true], [LogCategory.AUDIO, true], [LogCategory.CHAT, true], - [LogCategory.I18N, false], + [LogCategory.I18N, true], [LogCategory.IDENTITIES, true], [LogCategory.IPC, true], [LogCategory.STATISTICS, true], diff --git a/shared/js/ui/modal/channel-edit/Renderer.tsx b/shared/js/ui/modal/channel-edit/Renderer.tsx index 32c7bcb9..457d5e73 100644 --- a/shared/js/ui/modal/channel-edit/Renderer.tsx +++ b/shared/js/ui/modal/channel-edit/Renderer.tsx @@ -159,7 +159,7 @@ const ChannelIcon = () => {
-
enabled && events.fire("action_icon_select")}>Edit icon
+
enabled && events.fire("action_icon_select")}>Edit icon
{ if(!enabled) { return; @@ -173,7 +173,7 @@ const ChannelIcon = () => { serverUniqueId: propertyValue.remoteIcon.serverUniqueId } }); - }}>Remove icon
+ }}>Remove icon
@@ -351,31 +351,31 @@ const SidebarType = React.memo(() => { ); }); -type SimpleCodecQualityTemplate = { id: string, codec: number, quality: number, name: string }; +type SimpleCodecQualityTemplate = { id: string, codec: number, quality: number, name: () => string }; const kCodecTemplates: SimpleCodecQualityTemplate[] = [ { id: "mobile", codec: 4, quality: 4, - name: useTr("Mobile") + name: () => useTr("Mobile") }, { id: "voice", codec: 4, quality: 6, - name: useTr("Voice") + name: () => useTr("Voice") }, { id: "music", codec: 5, quality: 6, - name: useTr("Music") + name: () => useTr("Music") }, { id: "loading", codec: undefined, quality: undefined, - name: useTr("loading") + name: () => useTr("loading") } ]; @@ -404,7 +404,7 @@ const SimpleCodecQuality = React.memo(() => { > { kCodecTemplates.map(template => ( - + )) } @@ -431,7 +431,7 @@ const AdvancedCodecPresets = React.memo(() => { disabled={!hasPermission(template) || propertyState !== "normal"} onChange={() => setPropertyValue({ quality: template.quality, type: template.codec})} > -
{template.name}
+
{template.name()}
)) }