mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-21 01:11:46 +03:00
Added generic types for Locales.translate()
This commit is contained in:
parent
2eb2c98637
commit
d1ebf567b7
8 changed files with 23 additions and 19 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue