Improved snackbar translations support

This commit is contained in:
Isaac Abadi
2022-06-20 16:25:55 -04:00
parent 4c6c15d3a3
commit cbdd1a6253
11 changed files with 60 additions and 57 deletions

View File

@@ -53,9 +53,9 @@ export class CustomPlaylistsComponent implements OnInit {
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
if (result) { if (result) {
this.getAllPlaylists(); this.getAllPlaylists();
this.postsService.openSnackBar('Successfully created playlist!', ''); this.postsService.openSnackBar($localize`Successfully created playlist!', '`);
} else if (result === false) { } else if (result === false) {
this.postsService.openSnackBar('ERROR: failed to create playlist!', ''); this.postsService.openSnackBar($localize`ERROR: failed to create playlist!', '`);
} }
}); });
} }
@@ -96,7 +96,7 @@ export class CustomPlaylistsComponent implements OnInit {
this.postsService.removePlaylist(playlistID).subscribe(res => { this.postsService.removePlaylist(playlistID).subscribe(res => {
if (res['success']) { if (res['success']) {
this.playlists.splice(index, 1); this.playlists.splice(index, 1);
this.postsService.openSnackBar('Playlist successfully removed.', ''); this.postsService.openSnackBar($localize`Playlist successfully removed.', '`);
} }
this.getAllPlaylists(); this.getAllPlaylists();
}); });

View File

@@ -8,6 +8,7 @@ import { MatDialog } from '@angular/material/dialog';
import { ConfirmDialogComponent } from 'app/dialogs/confirm-dialog/confirm-dialog.component'; import { ConfirmDialogComponent } from 'app/dialogs/confirm-dialog/confirm-dialog.component';
import { MatSort } from '@angular/material/sort'; import { MatSort } from '@angular/material/sort';
import { Clipboard } from '@angular/cdk/clipboard'; import { Clipboard } from '@angular/cdk/clipboard';
import { Download } from 'api-types';
@Component({ @Component({
selector: 'app-downloads', selector: 'app-downloads',
@@ -68,7 +69,7 @@ export class DownloadsComponent implements OnInit, OnDestroy {
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
sort_downloads = (a, b) => { sort_downloads = (a: Download, b: Download): number => {
const result = b.timestamp_start - a.timestamp_start; const result = b.timestamp_start - a.timestamp_start;
return result; return result;
} }
@@ -166,7 +167,7 @@ export class DownloadsComponent implements OnInit, OnDestroy {
pauseDownload(download_uid: string): void { pauseDownload(download_uid: string): void {
this.postsService.pauseDownload(download_uid).subscribe(res => { this.postsService.pauseDownload(download_uid).subscribe(res => {
if (!res['success']) { if (!res['success']) {
this.postsService.openSnackBar('Failed to pause download! See server logs for more info.'); this.postsService.openSnackBar($localize`Failed to pause download! See server logs for more info.`);
} }
}); });
} }
@@ -174,7 +175,7 @@ export class DownloadsComponent implements OnInit, OnDestroy {
pauseAllDownloads(): void { pauseAllDownloads(): void {
this.postsService.pauseAllDownloads().subscribe(res => { this.postsService.pauseAllDownloads().subscribe(res => {
if (!res['success']) { if (!res['success']) {
this.postsService.openSnackBar('Failed to pause all downloads! See server logs for more info.'); this.postsService.openSnackBar($localize`Failed to pause all downloads! See server logs for more info.`);
} }
}); });
} }
@@ -182,7 +183,7 @@ export class DownloadsComponent implements OnInit, OnDestroy {
resumeDownload(download_uid: string): void { resumeDownload(download_uid: string): void {
this.postsService.resumeDownload(download_uid).subscribe(res => { this.postsService.resumeDownload(download_uid).subscribe(res => {
if (!res['success']) { if (!res['success']) {
this.postsService.openSnackBar('Failed to resume download! See server logs for more info.'); this.postsService.openSnackBar($localize`Failed to resume download! See server logs for more info.`);
} }
}); });
} }
@@ -190,7 +191,7 @@ export class DownloadsComponent implements OnInit, OnDestroy {
resumeAllDownloads(): void { resumeAllDownloads(): void {
this.postsService.resumeAllDownloads().subscribe(res => { this.postsService.resumeAllDownloads().subscribe(res => {
if (!res['success']) { if (!res['success']) {
this.postsService.openSnackBar('Failed to resume all downloads! See server logs for more info.'); this.postsService.openSnackBar($localize`Failed to resume all downloads! See server logs for more info.`);
} }
}); });
} }
@@ -198,7 +199,7 @@ export class DownloadsComponent implements OnInit, OnDestroy {
restartDownload(download_uid: string): void { restartDownload(download_uid: string): void {
this.postsService.restartDownload(download_uid).subscribe(res => { this.postsService.restartDownload(download_uid).subscribe(res => {
if (!res['success']) { if (!res['success']) {
this.postsService.openSnackBar('Failed to restart download! See server logs for more info.'); this.postsService.openSnackBar($localize`Failed to restart download! See server logs for more info.`);
} }
}); });
} }
@@ -206,7 +207,7 @@ export class DownloadsComponent implements OnInit, OnDestroy {
cancelDownload(download_uid: string): void { cancelDownload(download_uid: string): void {
this.postsService.cancelDownload(download_uid).subscribe(res => { this.postsService.cancelDownload(download_uid).subscribe(res => {
if (!res['success']) { if (!res['success']) {
this.postsService.openSnackBar('Failed to cancel download! See server logs for more info.'); this.postsService.openSnackBar($localize`Failed to cancel download! See server logs for more info.`);
} }
}); });
} }
@@ -214,12 +215,12 @@ export class DownloadsComponent implements OnInit, OnDestroy {
clearDownload(download_uid: string): void { clearDownload(download_uid: string): void {
this.postsService.clearDownload(download_uid).subscribe(res => { this.postsService.clearDownload(download_uid).subscribe(res => {
if (!res['success']) { if (!res['success']) {
this.postsService.openSnackBar('Failed to pause download! See server logs for more info.'); this.postsService.openSnackBar($localize`Failed to pause download! See server logs for more info.`);
} }
}); });
} }
watchContent(download): void { watchContent(download: Download): void {
const container = download['container']; const container = download['container'];
localStorage.setItem('player_navigator', this.router.url.split(';')[0]); localStorage.setItem('player_navigator', this.router.url.split(';')[0]);
const is_playlist = container['uids']; // hacky, TODO: fix const is_playlist = container['uids']; // hacky, TODO: fix
@@ -230,7 +231,7 @@ export class DownloadsComponent implements OnInit, OnDestroy {
} }
} }
combineDownloads(downloads_old, downloads_new) { combineDownloads(downloads_old: Download[], downloads_new: Download[]): Download[] {
// only keeps downloads that exist in the new set // only keeps downloads that exist in the new set
downloads_old = downloads_old.filter(download_old => downloads_new.some(download_new => download_new.uid === download_old.uid)); downloads_old = downloads_old.filter(download_old => downloads_new.some(download_new => download_new.uid === download_old.uid));
@@ -251,7 +252,7 @@ export class DownloadsComponent implements OnInit, OnDestroy {
return downloads_old; return downloads_old;
} }
showError(download) { showError(download: Download): void {
const copyToClipboardEmitter = new EventEmitter<boolean>(); const copyToClipboardEmitter = new EventEmitter<boolean>();
this.dialog.open(ConfirmDialogComponent, { this.dialog.open(ConfirmDialogComponent, {
data: { data: {
@@ -272,10 +273,3 @@ export class DownloadsComponent implements OnInit, OnDestroy {
}); });
} }
} }
export interface Download {
timestamp_start: number;
title: string;
step_index: number;
progress: string;
}

View File

@@ -43,17 +43,17 @@ export class LogsViewerComponent implements OnInit {
}) })
}); });
} else { } else {
this.postsService.openSnackBar('Failed to retrieve logs!'); this.postsService.openSnackBar($localize`Failed to retrieve logs!`);
} }
}, err => { }, err => {
this.logs_loading = false; this.logs_loading = false;
console.error(err); console.error(err);
this.postsService.openSnackBar('Failed to retrieve logs!'); this.postsService.openSnackBar($localize`Failed to retrieve logs!`);
}); });
} }
copiedLogsToClipboard() { copiedLogsToClipboard() {
this.postsService.openSnackBar('Logs copied to clipboard!'); this.postsService.openSnackBar($localize`Logs copied to clipboard!`);
} }
clearLogs() { clearLogs() {
@@ -72,12 +72,12 @@ export class LogsViewerComponent implements OnInit {
this.logs = []; this.logs = [];
this.logs_text = ''; this.logs_text = '';
this.getLogs(); this.getLogs();
this.postsService.openSnackBar('Logs successfully cleared!'); this.postsService.openSnackBar($localize`Logs successfully cleared!`);
} else { } else {
this.postsService.openSnackBar('Failed to clear logs!'); this.postsService.openSnackBar($localize`Failed to clear logs!`);
} }
}, err => { }, err => {
this.postsService.openSnackBar('Failed to clear logs!'); this.postsService.openSnackBar($localize`Failed to clear logs!`);
}); });
} }
}); });

View File

@@ -297,13 +297,13 @@ export class RecentVideosComponent implements OnInit {
deleteNormalFile(file, blacklistMode = false) { deleteNormalFile(file, blacklistMode = false) {
this.postsService.deleteFile(file.uid, blacklistMode).subscribe(result => { this.postsService.deleteFile(file.uid, blacklistMode).subscribe(result => {
if (result) { if (result) {
this.postsService.openSnackBar('Delete success!', 'OK.'); this.postsService.openSnackBar($localize`Delete success!', 'OK.`);
this.removeFileCard(file); this.removeFileCard(file);
} else { } else {
this.postsService.openSnackBar('Delete failed!', 'OK.'); this.postsService.openSnackBar($localize`Delete failed!', 'OK.`);
} }
}, err => { }, err => {
this.postsService.openSnackBar('Delete failed!', 'OK.'); this.postsService.openSnackBar($localize`Delete failed!', 'OK.`);
}); });
} }

View File

@@ -96,18 +96,18 @@ export class TwitchChatComponent implements OnInit, OnDestroy {
let vodId = this.db_file.url.split('videos/').length > 1 && this.db_file.url.split('videos/')[1]; let vodId = this.db_file.url.split('videos/').length > 1 && this.db_file.url.split('videos/')[1];
vodId = vodId.split('?')[0]; vodId = vodId.split('?')[0];
if (!vodId) { if (!vodId) {
this.postsService.openSnackBar('VOD url for this video is not supported. VOD ID must be after "twitch.tv/videos/"'); this.postsService.openSnackBar($localize`VOD url for this video is not supported. VOD ID must be after "twitch.tv/videos/"`);
} }
this.postsService.downloadTwitchChat(this.db_file.id, this.db_file.isAudio ? 'audio' : 'video', vodId, null, this.sub).subscribe(res => { this.postsService.downloadTwitchChat(this.db_file.id, this.db_file.isAudio ? 'audio' : 'video', vodId, null, this.sub).subscribe(res => {
if (res['chat']) { if (res['chat']) {
this.initializeChatCheck(res['chat']); this.initializeChatCheck(res['chat']);
} else { } else {
this.downloading_chat = false; this.downloading_chat = false;
this.postsService.openSnackBar('Download failed.') this.postsService.openSnackBar($localize`Download failed.`)
} }
}, err => { }, err => {
this.downloading_chat = false; this.downloading_chat = false;
this.postsService.openSnackBar('Chat could not be downloaded.') this.postsService.openSnackBar($localize`Chat could not be downloaded.`)
}); });
} }

View File

@@ -53,17 +53,26 @@ export class CreatePlaylistComponent implements OnInit {
} else { } else {
this.dialogRef.close(false); this.dialogRef.close(false);
} }
}, err => {
this.create_in_progress = false;
console.error(err);
}); });
} }
updatePlaylist(): void { updatePlaylist(): void {
this.create_in_progress = true;
this.playlist['name'] = this.name; this.playlist['name'] = this.name;
this.playlist['uids'] = this.filesSelect.value; this.playlist['uids'] = this.filesSelect.value;
this.playlist_updated = true; this.playlist_updated = true;
this.postsService.updatePlaylist(this.playlist).subscribe(() => { this.postsService.updatePlaylist(this.playlist).subscribe(() => {
this.postsService.openSnackBar('Playlist updated successfully.'); this.create_in_progress = false;
this.postsService.openSnackBar($localize`Playlist updated successfully.`);
this.getPlaylist(); this.getPlaylist();
this.postsService.playlists_changed.next(true); this.postsService.playlists_changed.next(true);
}, err => {
this.create_in_progress = false;
console.error(err)
this.postsService.openSnackBar($localize`Playlist updated successfully.`);
}); });
} }

View File

@@ -39,7 +39,7 @@ export class CookiesUploaderDialogComponent implements OnInit {
this.uploading = false; this.uploading = false;
if (res['success']) { if (res['success']) {
this.uploaded = true; this.uploaded = true;
this.postsService.openSnackBar('Cookies successfully uploaded!'); this.postsService.openSnackBar($localize`Cookies successfully uploaded!`);
} }
}, err => { }, err => {
this.uploading = false; this.uploading = false;

View File

@@ -36,14 +36,14 @@ export class RestoreDbDialogComponent implements OnInit {
this.postsService.restoreDBBackup(this.selected_backup[0]).subscribe(res => { this.postsService.restoreDBBackup(this.selected_backup[0]).subscribe(res => {
this.restoring = false; this.restoring = false;
if (res['success']) { if (res['success']) {
this.postsService.openSnackBar('Database successfully restored!'); this.postsService.openSnackBar($localize`Database successfully restored!`);
this.dialogRef.close(); this.dialogRef.close();
} else { } else {
this.postsService.openSnackBar('Failed to restore database! See logs for more info.'); this.postsService.openSnackBar($localize`Failed to restore database! See logs for more info.`);
} }
}, err => { }, err => {
this.restoring = false; this.restoring = false;
this.postsService.openSnackBar('Failed to restore database! See browser console for more info.'); this.postsService.openSnackBar($localize`Failed to restore database! See browser console for more info.`);
console.error(err); console.error(err);
}); });
} }

View File

@@ -390,7 +390,7 @@ export class MainComponent implements OnInit {
}, () => { // can't access server }, () => { // can't access server
this.downloadingfile = false; this.downloadingfile = false;
this.current_download = null; this.current_download = null;
this.postsService.openSnackBar('Download failed!', 'OK.'); this.postsService.openSnackBar($localize`Download failed!', 'OK.`);
}); });
if (!this.autoplay && urls.length === 1) { if (!this.autoplay && urls.length === 1) {
@@ -776,7 +776,7 @@ export class MainComponent implements OnInit {
} else if (this.current_download['finished'] && this.current_download['error']) { } else if (this.current_download['finished'] && this.current_download['error']) {
this.downloadingfile = false; this.downloadingfile = false;
this.current_download = null; this.current_download = null;
this.postsService.openSnackBar('Download failed!', 'OK.'); this.postsService.openSnackBar($localize`Download failed!', 'OK.`);
} }
} else { } else {
// console.log('failed to get new download'); // console.log('failed to get new download');

View File

@@ -147,7 +147,7 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy {
this.postsService.getFile(this.uid, this.uuid).subscribe(res => { this.postsService.getFile(this.uid, this.uuid).subscribe(res => {
this.db_file = res['file']; this.db_file = res['file'];
if (!this.db_file) { if (!this.db_file) {
this.postsService.openSnackBar('Failed to get file information from the server.', 'Dismiss'); this.postsService.openSnackBar($localize`Failed to get file information from the server.', 'Dismiss`);
return; return;
} }
this.postsService.incrementViewCount(this.db_file['uid'], null, this.uuid).subscribe(() => undefined, err => { this.postsService.incrementViewCount(this.db_file['uid'], null, this.uuid).subscribe(() => undefined, err => {
@@ -183,10 +183,10 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy {
this.show_player = true; this.show_player = true;
this.parseFileNames(); this.parseFileNames();
} else { } else {
this.postsService.openSnackBar('Failed to load playlist!', ''); this.postsService.openSnackBar($localize`Failed to load playlist!', '`);
} }
}, () => { }, () => {
this.postsService.openSnackBar('Failed to load playlist!', ''); this.postsService.openSnackBar($localize`Failed to load playlist!', '`);
}); });
} }

View File

@@ -131,7 +131,7 @@ export class SettingsComponent implements OnInit {
this.postsService.updateCategories(this.postsService.categories).subscribe(res => { this.postsService.updateCategories(this.postsService.categories).subscribe(res => {
}, () => { }, () => {
this.postsService.openSnackBar('Failed to update categories!'); this.postsService.openSnackBar($localize`Failed to update categories!`);
}); });
} }
@@ -205,7 +205,7 @@ export class SettingsComponent implements OnInit {
localeSelectChanged(new_val: string): void { localeSelectChanged(new_val: string): void {
localStorage.setItem('locale', new_val); localStorage.setItem('locale', new_val);
this.postsService.openSnackBar('Language successfully changed! Reload to update the page.') this.postsService.openSnackBar($localize`Language successfully changed! Reload to update the page.`)
} }
generateBookmarklet(): void { generateBookmarklet(): void {
@@ -233,7 +233,7 @@ export class SettingsComponent implements OnInit {
window['external']['AddFavorite'](url, title); window['external']['AddFavorite'](url, title);
} else if (window['chrome']) { } else if (window['chrome']) {
// Google Chrome // Google Chrome
this.postsService.openSnackBar('Chrome users must drag the \'Alternate URL\' link to your bookmarks.'); this.postsService.openSnackBar($localize`Chrome users must drag the \'Alternate URL\' link to your bookmarks.`);
} else if (window['sidebar']) { } else if (window['sidebar']) {
// Firefox // Firefox
window['sidebar'].addPanel(title, url, ''); window['sidebar'].addPanel(title, url, '');
@@ -288,14 +288,14 @@ export class SettingsComponent implements OnInit {
this.postsService.killAllDownloads().subscribe(res => { this.postsService.killAllDownloads().subscribe(res => {
if (res['success']) { if (res['success']) {
dialogRef.close(); dialogRef.close();
this.postsService.openSnackBar('Successfully killed all downloads!'); this.postsService.openSnackBar($localize`Successfully killed all downloads!`);
} else { } else {
dialogRef.close(); dialogRef.close();
this.postsService.openSnackBar('Failed to kill all downloads! Check logs for details.'); this.postsService.openSnackBar($localize`Failed to kill all downloads! Check logs for details.`);
} }
}, () => { }, () => {
dialogRef.close(); dialogRef.close();
this.postsService.openSnackBar('Failed to kill all downloads! Check logs for details.'); this.postsService.openSnackBar($localize`Failed to kill all downloads! Check logs for details.`);
}); });
} }
}); });
@@ -303,9 +303,9 @@ export class SettingsComponent implements OnInit {
restartServer(): void { restartServer(): void {
this.postsService.restartServer().subscribe(() => { this.postsService.restartServer().subscribe(() => {
this.postsService.openSnackBar('Restarting!'); this.postsService.openSnackBar($localize`Restarting!`);
}, () => { }, () => {
this.postsService.openSnackBar('Failed to restart the server.'); this.postsService.openSnackBar($localize`Failed to restart the server.`);
}); });
} }
@@ -336,14 +336,14 @@ export class SettingsComponent implements OnInit {
this.db_transferring = false; this.db_transferring = false;
const success = res['success']; const success = res['success'];
if (success) { if (success) {
this.postsService.openSnackBar('Successfully transfered DB! Reloading info...'); this.postsService.openSnackBar($localize`Successfully transfered DB! Reloading info...`);
this.getDBInfo(); this.getDBInfo();
} else { } else {
this.postsService.openSnackBar('Failed to transfer DB -- transfer was aborted. Error: ' + res['error']); this.postsService.openSnackBar($localize`Failed to transfer DB -- transfer was aborted. Error: ` + res['error']);
} }
}, err => { }, err => {
this.db_transferring = false; this.db_transferring = false;
this.postsService.openSnackBar('Failed to transfer DB -- API call failed. See browser logs for details.'); this.postsService.openSnackBar($localize`Failed to transfer DB -- API call failed. See browser logs for details.`);
console.error(err); console.error(err);
}); });
} }
@@ -353,13 +353,13 @@ export class SettingsComponent implements OnInit {
this.postsService.testConnectionString(connection_string).subscribe(res => { this.postsService.testConnectionString(connection_string).subscribe(res => {
this.testing_connection_string = false; this.testing_connection_string = false;
if (res['success']) { if (res['success']) {
this.postsService.openSnackBar('Connection successful!'); this.postsService.openSnackBar($localize`Connection successful!`);
} else { } else {
this.postsService.openSnackBar('Connection failed! Error: ' + res['error']); this.postsService.openSnackBar($localize`Connection failed! Error: ` + res['error']);
} }
}, () => { }, () => {
this.testing_connection_string = false; this.testing_connection_string = false;
this.postsService.openSnackBar('Connection failed! Error: Server error. See logs for more info.'); this.postsService.openSnackBar($localize`Connection failed! Error: Server error. See logs for more info.`);
}); });
} }
} }