code refactoring

This commit is contained in:
2023-01-13 11:43:56 +01:00
parent dcd80b7366
commit 7d2503fe77
3 changed files with 15 additions and 14 deletions

View File

@@ -1,28 +1,28 @@
// @ts-nocheck
import i18n from "../../assets/i18n.yaml";
import i18n from "../../assets/i18n.yaml"
export default class I18nBuilder {
private language: string;
private textMap = i18n.languages;
private language: string
private textMap = i18n.languages
constructor(language: string) {
this.language = language;
this.language = language
}
getLanguage(): string {
return this.language;
return this.language
}
setLanguage(language: string): void {
this.language = language;
this.language = language
}
t(key: string): string {
const map = this.textMap[this.language]
if (map) {
const translation = map[key];
return translation ?? 'caption not defined';
const translation = map[key]
return translation ?? 'caption not defined'
}
return 'caption not defined';
return 'caption not defined'
}
}

View File

@@ -20,10 +20,13 @@ export class RPCClient {
}
private sendHTTP<T>(req: RPCRequest) {
return new Promise<RPCResponse<T>>((resolve, reject) => {
return new Promise<RPCResponse<T>>((resolve) => {
fetch(getHttpRPCEndpoint(), {
method: 'POST',
body: JSON.stringify(req)
body: JSON.stringify({
id: this.incrementSeq(),
...req
})
})
.then(res => res.json())
.then(data => resolve(data))
@@ -59,6 +62,7 @@ export class RPCClient {
public running() {
this.send({
id: this.incrementSeq(),
method: 'Service.Running',
params: [],
})