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 {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 = () => {
|
||||
|
|
|
@ -68,7 +68,7 @@ export let enabled_mapping = new Map<number, boolean>([
|
|||
[LogCategory.VOICE, true],
|
||||
[LogCategory.AUDIO, true],
|
||||
[LogCategory.CHAT, true],
|
||||
[LogCategory.I18N, false],
|
||||
[LogCategory.I18N, true],
|
||||
[LogCategory.IDENTITIES, true],
|
||||
[LogCategory.IPC, true],
|
||||
[LogCategory.STATISTICS, true],
|
||||
|
|
|
@ -159,7 +159,7 @@ const ChannelIcon = () => {
|
|||
<div className="arrow down" />
|
||||
</div>
|
||||
<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={() => {
|
||||
if(!enabled) {
|
||||
return;
|
||||
|
@ -173,7 +173,7 @@ const ChannelIcon = () => {
|
|||
serverUniqueId: propertyValue.remoteIcon.serverUniqueId
|
||||
}
|
||||
});
|
||||
}}>Remove icon</div>
|
||||
}}><Translatable>Remove icon</Translatable></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[] = [
|
||||
{
|
||||
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 => (
|
||||
<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>
|
||||
|
@ -431,7 +431,7 @@ const AdvancedCodecPresets = React.memo(() => {
|
|||
disabled={!hasPermission(template) || propertyState !== "normal"}
|
||||
onChange={() => setPropertyValue({ quality: template.quality, type: template.codec})}
|
||||
>
|
||||
<div>{template.name}</div>
|
||||
<div>{template.name()}</div>
|
||||
</RadioButton>
|
||||
))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue