Added generic types for Locales.translate()

This commit is contained in:
Observer KRypt0n_ 2022-02-20 14:46:58 +02:00
parent 2eb2c98637
commit d1ebf567b7
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
8 changed files with 23 additions and 19 deletions

View file

@ -26,7 +26,7 @@
Windows.current.show(); Windows.current.show();
Windows.current.center(); Windows.current.center();
const title = Locales.translate('tos_violation.title') as string|null; const title = Locales.translate<string|null>('tos_violation.title');
if (title) if (title)
Windows.current.setTitle(title); Windows.current.setTitle(title);

View file

@ -156,7 +156,7 @@ export default class Locales
/** /**
* Get translation from the currently selected locale * Get translation from the currently selected locale
*/ */
public static translate(message: string): string|object|null public static translate<T>(message: string): T
{ {
const currentDictionary = svelteget(dictionary) as object; const currentDictionary = svelteget(dictionary) as object;
@ -170,7 +170,7 @@ export default class Locales
break; break;
} }
return translation; return translation as T;
} }
/** /**

View file

@ -143,7 +143,7 @@ export default class State
else if (await fs.exists(path.join(await constants.paths.launcherDir, '.analytics'))) else if (await fs.exists(path.join(await constants.paths.launcherDir, '.analytics')))
{ {
Windows.open('analytics', { Windows.open('analytics', {
title: Locales.translate('analytics.title') as string, title: Locales.translate<string>('analytics.title'),
width: 700, width: 700,
height: 460, height: 460,
exitProcessOnClose: false exitProcessOnClose: false
@ -188,7 +188,7 @@ export default class State
for (const tag of tags.reverse()) for (const tag of tags.reverse())
if (semver.gt(tag.tag, Launcher.version)) if (semver.gt(tag.tag, Launcher.version))
{ {
const locales = Locales.translate('notifications.launcher_update_available') as object; const locales = Locales.translate<object>('notifications.launcher_update_available');
Notification.show({ Notification.show({
title: locales['title'].replace('{from}', Launcher.version).replace('{to}', tag.tag), title: locales['title'].replace('{from}', Launcher.version).replace('{to}', tag.tag),
@ -505,7 +505,7 @@ export default class State
state = 'game-launch-available'; state = 'game-launch-available';
Notification.show({ Notification.show({
...(Locales.translate('notifications.patch_repos_unavailable') as { title: string, body: string }), ...Locales.translate('notifications.patch_repos_unavailable'),
icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`, icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`,
importance: 'critical' importance: 'critical'
}); });

View file

@ -21,7 +21,7 @@ export default (launcher: Launcher): Promise<void> => {
if (files.length > 0) if (files.length > 0)
{ {
launcher.progressBar?.init({ launcher.progressBar?.init({
label: Locales.translate('launcher.progress.game.applying_changes') as string, label: Locales.translate<string>('launcher.progress.game.applying_changes'),
showSpeed: false, showSpeed: false,
showEta: true, showEta: true,
showPercents: true, showPercents: true,
@ -64,7 +64,7 @@ export default (launcher: Launcher): Promise<void> => {
if (patchErrors > 0) if (patchErrors > 0)
{ {
const locale = Locales.translate('notifications.game_changes_applying_error') as { title: string, body: string }; const locale = Locales.translate<{ title: string, body: string }>('notifications.game_changes_applying_error');
Notification.show({ Notification.show({
title: locale.title, title: locale.title,

View file

@ -12,7 +12,7 @@ export default (launcher: Launcher): Promise<void> => {
if (!await Package.exists('xdelta3')) if (!await Package.exists('xdelta3'))
{ {
Notification.show({ Notification.show({
...(Locales.translate('notifications.xdelta3_package_required') as { title: string, body: string }), ...Locales.translate('notifications.xdelta3_package_required'),
icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`, icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`,
importance: 'critical' importance: 'critical'
}); });
@ -61,7 +61,7 @@ export default (launcher: Launcher): Promise<void> => {
if (!result) if (!result)
{ {
Notification.show({ Notification.show({
...(Locales.translate('notifications.patch_applying_error') as { title: string, body: string }), ...Locales.translate('notifications.patch_applying_error'),
icon: `${constants.paths.appDir}/public/images/baal64-transparent.png` icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`
}); });
} }
@ -73,7 +73,7 @@ export default (launcher: Launcher): Promise<void> => {
} }
}).catch(() => { }).catch(() => {
Notification.show({ Notification.show({
...(Locales.translate('notifications.patch_repos_unavailable') as { title: string, body: string }), ...Locales.translate('notifications.patch_repos_unavailable'),
icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`, icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`,
importance: 'critical' importance: 'critical'
}); });

View file

@ -29,7 +29,7 @@ export default (launcher: Launcher): Promise<void> => {
Game.update(prevGameVersion).then((stream) => { Game.update(prevGameVersion).then((stream) => {
launcher.progressBar?.init({ launcher.progressBar?.init({
label: Locales.translate('launcher.progress.game.downloading') as string, label: Locales.translate('launcher.progress.game.downloading'),
showSpeed: true, showSpeed: true,
showEta: true, showEta: true,
showPercents: true, showPercents: true,
@ -46,14 +46,14 @@ export default (launcher: Launcher): Promise<void> => {
{ {
stream?.pauseDownload(); stream?.pauseDownload();
launcher.state!.pauseButton.textContent = Locales.translate('launcher.progress.resume') as string; launcher.state!.pauseButton.textContent = Locales.translate('launcher.progress.resume');
} }
else else
{ {
stream?.resumeDownload(); stream?.resumeDownload();
launcher.state!.pauseButton.textContent = Locales.translate('launcher.progress.pause') as string; launcher.state!.pauseButton.textContent = Locales.translate('launcher.progress.pause');
} }
paused = !paused; paused = !paused;
@ -67,7 +67,7 @@ export default (launcher: Launcher): Promise<void> => {
stream?.unpackStart(() => { stream?.unpackStart(() => {
launcher.progressBar?.init({ launcher.progressBar?.init({
label: Locales.translate('launcher.progress.game.unpacking') as string, label: Locales.translate('launcher.progress.game.unpacking'),
showSpeed: true, showSpeed: true,
showEta: true, showEta: true,
showPercents: true, showPercents: true,

View file

@ -17,15 +17,17 @@ export default (launcher: Launcher): Promise<void> => {
Game.isTelemetryDisabled() Game.isTelemetryDisabled()
.then(async (telemetryDisabled) => { .then(async (telemetryDisabled) => {
// If telemetry servers are not disabled // If telemetry servers are not disabled
if (!telemetryDisabled) if (telemetryDisabled)
{ {
Notification.show({ Notification.show({
...(Locales.translate('notifications.telemetry_not_disabled') as { title: string, body: string }), ...Locales.translate('notifications.telemetry_not_disabled'),
icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`, icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`,
importance: 'critical' importance: 'critical'
}); });
debugThread.log('Telemetry is not disabled!'); debugThread.log('Telemetry is not disabled!');
resolve();
} }
// Otherwise run the game // Otherwise run the game
@ -280,10 +282,12 @@ export default (launcher: Launcher): Promise<void> => {
}) })
.catch(() => { .catch(() => {
Notification.show({ Notification.show({
...(Locales.translate('notifications.iputils_package_required') as { title: string, body: string }), ...Locales.translate('notifications.iputils_package_required'),
icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`, icon: `${constants.paths.appDir}/public/images/baal64-transparent.png`,
importance: 'critical' importance: 'critical'
}); });
resolve();
}); });
}); });
}; };

View file

@ -18,7 +18,7 @@ export default (launcher: Launcher): Promise<void> => {
if (files.length > 0) if (files.length > 0)
{ {
launcher.progressBar?.init({ launcher.progressBar?.init({
label: Locales.translate('launcher.progress.game.deleting_outdated') as string, label: Locales.translate<string>('launcher.progress.game.deleting_outdated'),
showSpeed: false, showSpeed: false,
showEta: true, showEta: true,
showPercents: true, showPercents: true,