Fixed some missing translations and fixed a small bug
This commit is contained in:
parent
651ccf4c92
commit
3257e90bc1
3 changed files with 26 additions and 18 deletions
|
@ -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 {guid} from "../crypto/uid";
|
||||||
import {Settings, StaticSettings} from "../settings";
|
import {Settings, StaticSettings} from "../settings";
|
||||||
import * as loader from "tc-loader";
|
import * as loader from "tc-loader";
|
||||||
|
@ -48,22 +48,29 @@ export interface TranslationRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
let translations: Translation[] = [];
|
let translations: Translation[] = [];
|
||||||
let fast_translate: { [key:string]:string; } = {};
|
let translateCache: { [key:string]: string; } = {};
|
||||||
export function tr(message: string, key?: string) {
|
export function tr(message: string, key?: string) {
|
||||||
const sloppy = fast_translate[message];
|
const sloppy = translateCache[message];
|
||||||
if(sloppy) return sloppy;
|
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) {
|
for(const translation of translations) {
|
||||||
if(translation.key.message == message) {
|
if(translation.key.message === message) {
|
||||||
translated = translation.translated;
|
translated = translation.translated;
|
||||||
break;
|
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;
|
return translated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,6 +323,7 @@ export async function initialize() {
|
||||||
if(cfg.current_translation_url) {
|
if(cfg.current_translation_url) {
|
||||||
try {
|
try {
|
||||||
await load_file(cfg.current_translation_url, cfg.current_translation_path);
|
await load_file(cfg.current_translation_url, cfg.current_translation_path);
|
||||||
|
translateCache = {};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logError(LogCategory.I18N, tr("Failed to initialize selected translation: %o"), error);
|
logError(LogCategory.I18N, tr("Failed to initialize selected translation: %o"), error);
|
||||||
const show_error = () => {
|
const show_error = () => {
|
||||||
|
|
|
@ -68,7 +68,7 @@ export let enabled_mapping = new Map<number, boolean>([
|
||||||
[LogCategory.VOICE, true],
|
[LogCategory.VOICE, true],
|
||||||
[LogCategory.AUDIO, true],
|
[LogCategory.AUDIO, true],
|
||||||
[LogCategory.CHAT, true],
|
[LogCategory.CHAT, true],
|
||||||
[LogCategory.I18N, false],
|
[LogCategory.I18N, true],
|
||||||
[LogCategory.IDENTITIES, true],
|
[LogCategory.IDENTITIES, true],
|
||||||
[LogCategory.IPC, true],
|
[LogCategory.IPC, true],
|
||||||
[LogCategory.STATISTICS, true],
|
[LogCategory.STATISTICS, true],
|
||||||
|
|
|
@ -159,7 +159,7 @@ const ChannelIcon = () => {
|
||||||
<div className="arrow down" />
|
<div className="arrow down" />
|
||||||
</div>
|
</div>
|
||||||
<div className={cssStyle.dropdown}>
|
<div className={cssStyle.dropdown}>
|
||||||
<div className={cssStyle.entry} onClick={() => enabled && events.fire("action_icon_select")}>Edit icon</div>
|
<div className={cssStyle.entry} onClick={() => enabled && events.fire("action_icon_select")}><Translatable>Edit icon</Translatable></div>
|
||||||
<div className={cssStyle.entry} onClick={() => {
|
<div className={cssStyle.entry} onClick={() => {
|
||||||
if(!enabled) {
|
if(!enabled) {
|
||||||
return;
|
return;
|
||||||
|
@ -173,7 +173,7 @@ const ChannelIcon = () => {
|
||||||
serverUniqueId: propertyValue.remoteIcon.serverUniqueId
|
serverUniqueId: propertyValue.remoteIcon.serverUniqueId
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}}>Remove icon</div>
|
}}><Translatable>Remove icon</Translatable></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -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[] = [
|
const kCodecTemplates: SimpleCodecQualityTemplate[] = [
|
||||||
{
|
{
|
||||||
id: "mobile",
|
id: "mobile",
|
||||||
codec: 4,
|
codec: 4,
|
||||||
quality: 4,
|
quality: 4,
|
||||||
name: useTr("Mobile")
|
name: () => useTr("Mobile")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "voice",
|
id: "voice",
|
||||||
codec: 4,
|
codec: 4,
|
||||||
quality: 6,
|
quality: 6,
|
||||||
name: useTr("Voice")
|
name: () => useTr("Voice")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "music",
|
id: "music",
|
||||||
codec: 5,
|
codec: 5,
|
||||||
quality: 6,
|
quality: 6,
|
||||||
name: useTr("Music")
|
name: () => useTr("Music")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "loading",
|
id: "loading",
|
||||||
codec: undefined,
|
codec: undefined,
|
||||||
quality: undefined,
|
quality: undefined,
|
||||||
name: useTr("loading")
|
name: () => useTr("loading")
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -404,7 +404,7 @@ const SimpleCodecQuality = React.memo(() => {
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
kCodecTemplates.map(template => (
|
kCodecTemplates.map(template => (
|
||||||
<option style={{ display: template.id === "loading" ? "none" : undefined }} key={template.id} value={template.id} disabled={!hasPermission(template)}>{template.name}</option>
|
<option style={{ display: template.id === "loading" ? "none" : undefined }} key={template.id} value={template.id} disabled={!hasPermission(template)}>{template.name()}</option>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
<option style={{ display: "none" }} key={"advanced"} value={"advanced"}>{useTr("Custom (Advanced settings)")}</option>
|
<option style={{ display: "none" }} key={"advanced"} value={"advanced"}>{useTr("Custom (Advanced settings)")}</option>
|
||||||
|
@ -431,7 +431,7 @@ const AdvancedCodecPresets = React.memo(() => {
|
||||||
disabled={!hasPermission(template) || propertyState !== "normal"}
|
disabled={!hasPermission(template) || propertyState !== "normal"}
|
||||||
onChange={() => setPropertyValue({ quality: template.quality, type: template.codec})}
|
onChange={() => setPropertyValue({ quality: template.quality, type: template.codec})}
|
||||||
>
|
>
|
||||||
<div>{template.name}</div>
|
<div>{template.name()}</div>
|
||||||
</RadioButton>
|
</RadioButton>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue