Added telemetry servers notification localization

Also now localization files can contain references to the constant properties
This commit is contained in:
Observer KRypt0n_ 2021-11-03 16:34:46 +02:00
parent ba8b1fea59
commit 320f679f6d
No known key found for this signature in database
GPG key ID: DC5D4EC1303465DA
18 changed files with 75 additions and 46 deletions

View file

@ -31,5 +31,6 @@
"Skip": "Überspringen", "Skip": "Überspringen",
"SkipAndDontAsk": "Überspingen und nicht noch mal fragen", "SkipAndDontAsk": "Überspingen und nicht noch mal fragen",
"LauncherUpdateTitle": "Launcher update verfügbar: ", "LauncherUpdateTitle": "Launcher update verfügbar: ",
"LauncherUpdateBody": "Sie können eine neue Version des Launchers aus dem Repository des Projekts unter https://notabug.org/nobody/an-anime-game-launcher herunterladen." "LauncherUpdateBody": "Sie können eine neue Version des Launchers aus dem Repository des Projekts unter {uri.launcher} herunterladen.",
"TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "Skip", "Skip": "Skip",
"SkipAndDontAsk": "Skip and don't ask again", "SkipAndDontAsk": "Skip and don't ask again",
"LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateTitle": "Launcher update available: ",
"LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at https://notabug.org/nobody/an-anime-game-launcher" "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}",
"TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "Skip", "Skip": "Skip",
"SkipAndDontAsk": "Skip and don't ask again", "SkipAndDontAsk": "Skip and don't ask again",
"LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateTitle": "Launcher update available: ",
"LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at https://notabug.org/nobody/an-anime-game-launcher" "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}",
"TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "Skip", "Skip": "Skip",
"SkipAndDontAsk": "Skip and don't ask again", "SkipAndDontAsk": "Skip and don't ask again",
"LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateTitle": "Launcher update available: ",
"LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at https://notabug.org/nobody/an-anime-game-launcher" "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}",
"TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "Skip", "Skip": "Skip",
"SkipAndDontAsk": "Skip and don't ask again", "SkipAndDontAsk": "Skip and don't ask again",
"LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateTitle": "Launcher update available: ",
"LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at https://notabug.org/nobody/an-anime-game-launcher" "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}",
"TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "Skip", "Skip": "Skip",
"SkipAndDontAsk": "Skip and don't ask again", "SkipAndDontAsk": "Skip and don't ask again",
"LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateTitle": "Launcher update available: ",
"LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at https://notabug.org/nobody/an-anime-game-launcher" "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}",
"TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "スキップ", "Skip": "スキップ",
"SkipAndDontAsk": "スキップして二度と聞かない", "SkipAndDontAsk": "スキップして二度と聞かない",
"LauncherUpdateTitle": "ランチャーのアップデートが可能 ", "LauncherUpdateTitle": "ランチャーのアップデートが可能 ",
"LauncherUpdateBody": "ランチャーの新バージョンは、プロジェクトのリポジトリhttps://notabug.org/nobody/an-anime-game-launcherからダウンロードできます。" "LauncherUpdateBody": "ランチャーの新バージョンは、プロジェクトのリポジトリ({uri.launcher})からダウンロードできます。",
"TelemetryNotDisabled": "{placeholders.uppercase.company}のテレメトリサーバは無効になっていません!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "Skip", "Skip": "Skip",
"SkipAndDontAsk": "Skip and don't ask again", "SkipAndDontAsk": "Skip and don't ask again",
"LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateTitle": "Launcher update available: ",
"LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at https://notabug.org/nobody/an-anime-game-launcher" "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}",
"TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "Skip", "Skip": "Skip",
"SkipAndDontAsk": "Skip and don't ask again", "SkipAndDontAsk": "Skip and don't ask again",
"LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateTitle": "Launcher update available: ",
"LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at https://notabug.org/nobody/an-anime-game-launcher" "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}",
"TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "Пропустить", "Skip": "Пропустить",
"SkipAndDontAsk": "Пропустить и не спрашивать", "SkipAndDontAsk": "Пропустить и не спрашивать",
"LauncherUpdateTitle": "Доступно обновление лаунчера: ", "LauncherUpdateTitle": "Доступно обновление лаунчера: ",
"LauncherUpdateBody": "Вы можете скачать новую версию лаунчера с репозитория проекта: https://notabug.org/nobody/an-anime-game-launcher" "LauncherUpdateBody": "Вы можете скачать новую версию лаунчера с репозитория проекта: {uri.launcher}",
"TelemetryNotDisabled": "Серверы сбора телеметрии {placeholders.uppercase.company} не отключены!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "Skip", "Skip": "Skip",
"SkipAndDontAsk": "Skip and don't ask again", "SkipAndDontAsk": "Skip and don't ask again",
"LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateTitle": "Launcher update available: ",
"LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at https://notabug.org/nobody/an-anime-game-launcher" "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}",
"TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "Skip", "Skip": "Skip",
"SkipAndDontAsk": "Skip and don't ask again", "SkipAndDontAsk": "Skip and don't ask again",
"LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateTitle": "Launcher update available: ",
"LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at https://notabug.org/nobody/an-anime-game-launcher" "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}",
"TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "省略", "Skip": "省略",
"SkipAndDontAsk": "跳过,不要再问", "SkipAndDontAsk": "跳过,不要再问",
"LauncherUpdateTitle": "启动器更新可用:", "LauncherUpdateTitle": "启动器更新可用:",
"LauncherUpdateBody": "你可以从项目的资源库中下载新版本的启动器网址是https://notabug.org/nobody/an-anime-game-launcher" "LauncherUpdateBody": "你可以从项目的资源库中下载新版本的启动器,网址是:{uri.launcher}",
"TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!"
} }

View file

@ -31,5 +31,6 @@
"Skip": "跳過", "Skip": "跳過",
"SkipAndDontAsk": "跳過,不要再詢問我", "SkipAndDontAsk": "跳過,不要再詢問我",
"LauncherUpdateTitle": "啟動器有新的更新可用:", "LauncherUpdateTitle": "啟動器有新的更新可用:",
"LauncherUpdateBody": "您可以從此專案的資源庫中下載新版本的啟動器網址是https://notabug.org/nobody/an-anime-game-launcher" "LauncherUpdateBody": "您可以從此專案的資源庫中下載新版本的啟動器,網址是:{uri.launcher}",
"TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!"
} }

View file

@ -197,8 +197,8 @@ $(() => {
console.log(`${constants.placeholders.uppercase.company}'s telemetry servers doesn't disabled!`); console.log(`${constants.placeholders.uppercase.company}'s telemetry servers doesn't disabled!`);
ipcRenderer.send('notification', { ipcRenderer.send('notification', {
title: document.title, // FIXME add translation title: document.title,
body: `${constants.placeholders.uppercase.company}'s telemetry servers doesn't disabled!` body: LauncherUI.i18n.translate('TelemetryNotDisabled')
}); });
} }

View file

@ -28,6 +28,7 @@ export class LauncherUI
{ {
if (!this._i18n) if (!this._i18n)
this._i18n = i18n; this._i18n = i18n;
return this._i18n; return this._i18n;
} }

View file

@ -138,7 +138,6 @@ export class Tools
let matches = /^[dwxr\-]+ [\w/]+[ ]+(\d+) [0-9\-]+ [0-9\:]+ (.+)/.exec(line); let matches = /^[dwxr\-]+ [\w/]+[ ]+(\d+) [0-9\-]+ [0-9\:]+ (.+)/.exec(line);
// TODO: compressedSize?
if (matches) if (matches)
{ {
total += parseInt(matches[1]); total += parseInt(matches[1]);

View file

@ -1,46 +1,61 @@
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
import { constants } from './constants';
export class i18n export class i18n
{ {
public static readonly localesDir = path.join(path.dirname(__dirname), '..', 'locales'); public static readonly localesDir = path.join(path.dirname(__dirname), '..', 'locales');
public static loadedLanguage: any; public static loadedLanguage: any;
public static translate (phrase: string) public static translate (phrase: string): string
{ {
if (i18n.loadedLanguage === undefined) if (i18n.loadedLanguage === undefined)
this.setLang(navigator.language); this.setLang(navigator.language);
return i18n.loadedLanguage[phrase] ?? phrase; let translation = i18n.loadedLanguage[phrase] ?? phrase;
} let item;
public static setLang (lang: string) while ((item = /\{([a-zA-Z\.]+)\}/g.exec(translation)) !== null)
{ {
lang = lang.toLowerCase(); let value = constants;
// Test if the locale is the same string so if it's de-de or id-id remove -de or -id like navigator.language does. // @ts-expect-error
let samecode = new RegExp(`(${lang.replace(/-.*$/, '')}.*){2}`, 'g'); item[1].split('.').forEach(ref => value = value[ref]);
if (samecode.test(lang)) translation = translation.replace(item[0], value);
lang = lang.replace(/-.*$/, ''); }
switch (lang) return translation;
{ }
case 'ja-jp':
lang = 'ja';
break; public static setLang (lang: string)
{
lang = lang.toLowerCase();
case 'vi-vn': // Test if the locale is the same string so if it's de-de or id-id remove -de or -id like navigator.language does.
lang = 'vi'; let samecode = new RegExp(`(${lang.replace(/-.*$/, '')}.*){2}`, 'g');
break; if (samecode.test(lang))
} lang = lang.replace(/-.*$/, '');
i18n.loadedLanguage = JSON.parse(fs.readFileSync(path.join(this.localesDir, switch (lang)
fs.existsSync(path.join(this.localesDir, lang + '.json')) ? {
lang + '.json' : 'en.json' case 'ja-jp':
))); lang = 'ja';
}
break;
case 'vi-vn':
lang = 'vi';
break;
}
i18n.loadedLanguage = JSON.parse(fs.readFileSync(path.join(this.localesDir,
fs.existsSync(path.join(this.localesDir, lang + '.json')) ?
lang + '.json' : 'en.json'
)));
}
} }