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.center();
const title = Locales.translate('tos_violation.title') as string|null;
const title = Locales.translate<string|null>('tos_violation.title');
if (title)
Windows.current.setTitle(title);

View file

@ -156,7 +156,7 @@ export default class Locales
/**
* 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;
@ -170,7 +170,7 @@ export default class Locales
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')))
{
Windows.open('analytics', {
title: Locales.translate('analytics.title') as string,
title: Locales.translate<string>('analytics.title'),
width: 700,
height: 460,
exitProcessOnClose: false
@ -188,7 +188,7 @@ export default class State
for (const tag of tags.reverse())
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({
title: locales['title'].replace('{from}', Launcher.version).replace('{to}', tag.tag),
@ -505,7 +505,7 @@ export default class State
state = 'game-launch-available';
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`,
importance: 'critical'
});

View file

@ -21,7 +21,7 @@ export default (launcher: Launcher): Promise<void> => {
if (files.length > 0)
{
launcher.progressBar?.init({
label: Locales.translate('launcher.progress.game.applying_changes') as string,
label: Locales.translate<string>('launcher.progress.game.applying_changes'),
showSpeed: false,
showEta: true,
showPercents: true,
@ -64,7 +64,7 @@ export default (launcher: Launcher): Promise<void> => {
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({
title: locale.title,

View file

@ -12,7 +12,7 @@ export default (launcher: Launcher): Promise<void> => {
if (!await Package.exists('xdelta3'))
{
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`,
importance: 'critical'
});
@ -61,7 +61,7 @@ export default (launcher: Launcher): Promise<void> => {
if (!result)
{
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`
});
}
@ -73,7 +73,7 @@ export default (launcher: Launcher): Promise<void> => {
}
}).catch(() => {
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`,
importance: 'critical'
});

View file

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

View file

@ -17,15 +17,17 @@ export default (launcher: Launcher): Promise<void> => {
Game.isTelemetryDisabled()
.then(async (telemetryDisabled) => {
// If telemetry servers are not disabled
if (!telemetryDisabled)
if (telemetryDisabled)
{
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`,
importance: 'critical'
});
debugThread.log('Telemetry is not disabled!');
resolve();
}
// Otherwise run the game
@ -280,10 +282,12 @@ export default (launcher: Launcher): Promise<void> => {
})
.catch(() => {
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`,
importance: 'critical'
});
resolve();
});
});
};

View file

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