feat(pfapi): add various translations

This commit is contained in:
Johannes Millan 2025-04-14 18:55:27 +02:00
parent 2a0566a625
commit 647e022848
6 changed files with 58 additions and 58 deletions

View file

@ -63,6 +63,7 @@ import moment from 'moment/moment';
import { LocalBackupService } from './imex/local-backup/local-backup.service';
import { DEFAULT_META_MODEL } from './pfapi/api/model-ctrl/meta-model-ctrl';
import { AppDataCompleteNew } from './pfapi/pfapi-config';
import { TranslateService } from '@ngx-translate/core';
const w = window as any;
const productivityTip: string[] = w.productivityTips && w.productivityTips[w.randomIndex];
@ -97,6 +98,7 @@ const productivityTip: string[] = w.productivityTips && w.productivityTips[w.ran
],
})
export class AppComponent implements OnDestroy {
private _translateService = inject(TranslateService);
private _globalConfigService = inject(GlobalConfigService);
private _shortcutService = inject(ShortcutService);
private _bannerService = inject(BannerService);
@ -165,12 +167,11 @@ export class AppComponent implements OnDestroy {
const legacyData = await this._persistenceLegacyService.loadComplete();
console.log({ legacyData: legacyData });
alert('Detected legacy data. We will migrate it for you! ');
alert(this._translateService.instant(T.MIGRATE.DETECTED_LEGACY));
if (
!IS_ANDROID_WEB_VIEW &&
confirm(
'Do you want to download a backup of your legacy data (can be used with older versions of Super Productivity)?',
)
confirm(this._translateService.instant(T.MIGRATE.C_DOWNLOAD_BACKUP))
) {
download('sp-legacy-backup.json', JSON.stringify(legacyData));
}
@ -182,7 +183,9 @@ export class AppComponent implements OnDestroy {
);
this.imexMetaService.setDataImportInProgress(true);
await this._persistenceLocalService.updateLastSyncModelChange(MIGRATED_VAL);
alert('Migration all done! Restarting app now...');
alert(this._translateService.instant(T.MIGRATE.SUCCESS));
if (IS_ELECTRON) {
window.ea.relaunch();
// if relaunch fails we hard close the app
@ -192,7 +195,7 @@ export class AppComponent implements OnDestroy {
window.setTimeout(() => window.location.reload());
// fallback
window.setTimeout(
() => alert('Automatic restart failed. Please restart the app manually!'),
() => alert(this._translateService.instant(T.MIGRATE.E_RESTART_FAILED)),
2000,
);
} catch (error) {
@ -202,11 +205,16 @@ export class AppComponent implements OnDestroy {
try {
alert(
'Migration failed! with Error:\n\n' +
this._translateService.instant(T.MIGRATE.E_MIGRATION_FAILED) +
'\n\n' +
JSON.stringify((error as any).additionalLog[0].errors),
);
} catch (e) {
alert('Migration failed! with Error: ' + error?.toString());
alert(
this._translateService.instant(T.MIGRATE.E_MIGRATION_FAILED) +
'\n\n' +
error?.toString(),
);
}
return;
}

View file

@ -50,8 +50,6 @@ export const SYNC_FORM: ConfigFormSection<SyncConfig> = {
type: 'btn',
key: 'syncFolderPath',
templateOptions: {
// TODO translate
// text: `Select Sync Folder`,
text: T.F.SYNC.FORM.LOCAL_FILE.L_SYNC_FOLDER_PATH,
required: true,
onClick: () => {

View file

@ -1,9 +1,6 @@
<mat-dialog-content>
<div class="content">
<!--TODO translate -->
<p>
Your data is encrypted and decryption failed. Please enter the correct password!
</p>
<p>{{ T.F.SYNC.D_DECRYPT_ERROR.P1 | translate }}</p>
</div>
<form
@ -26,15 +23,15 @@
class="content"
style="margin-top: 24px"
>
<!--TODO translate -->
<p>You can also change your password, which will overwrite all remote data.</p>
<p>{{ T.F.SYNC.D_DECRYPT_ERROR.P2 | translate }}</p>
<button
mat-stroked-button
color="warn"
type="button"
(click)="updatePWAndForceUpload()"
>
Change and overwrite remote
{{ T.F.SYNC.D_DECRYPT_ERROR.BTN_OVER_WRITE_REMOTE | translate }}
</button>
</div>
</mat-dialog-content>

View file

@ -26,7 +26,6 @@ import { ReminderService } from '../../features/reminder/reminder.service';
import { DataInitService } from '../../core/data-init/data-init.service';
import { DialogSyncInitialCfgComponent } from './dialog-sync-initial-cfg/dialog-sync-initial-cfg.component';
import { DialogIncompleteSyncComponent } from './dialog-incomplete-sync/dialog-incomplete-sync.component';
import { SyncConfigService } from './sync-config.service';
import { DialogHandleDecryptErrorComponent } from './dialog-handle-decrypt-error/dialog-handle-decrypt-error.component';
@Injectable({
@ -40,7 +39,6 @@ export class SyncWrapperService {
private _matDialog = inject(MatDialog);
private _dataInitService = inject(DataInitService);
private _reminderService = inject(ReminderService);
private _syncConfigService = inject(SyncConfigService);
syncState$ = this._pfapiService.syncState$;
@ -48,7 +46,6 @@ export class SyncWrapperService {
map((cfg) => cfg?.sync),
);
syncProviderId$: Observable<SyncProviderId | null> = this.syncCfg$.pipe(
// TODO local file sync for electron and android provider interface
// NOTE: types are compatible
map((cfg) => cfg.syncProvider as SyncProviderId | null),
);
@ -72,10 +69,9 @@ export class SyncWrapperService {
// TODO move someplace else
async sync(): Promise<SyncStatus | 'USER_ABORT' | 'HANDLED_ERROR'> {
async sync(): Promise<SyncStatus | 'HANDLED_ERROR'> {
const providerId = await this.syncProviderId$.pipe(take(1)).toPromise();
if (!providerId) {
// // TODO handle different
throw new Error('No Sync Provider for sync()');
}
@ -92,7 +88,6 @@ export class SyncWrapperService {
case SyncStatus.UpdateLocal:
case SyncStatus.UpdateLocalAll:
// TODO dare to do more complicated stuff for UpdateLocal
await this._reInitAppAfterDataModelChange();
this._snackService.open({
msg: T.F.SYNC.S.SUCCESS_DOWNLOAD,
@ -121,17 +116,8 @@ export class SyncWrapperService {
await this._pfapiService.pf.downloadAll();
await this._reInitAppAfterDataModelChange();
}
console.log({ res });
// TODO implement and test force cases
// if (!this._c(T.F.SYNC.C.EMPTY_SYNC)) {
// TODO implement and test force cases
// this._pfapiWrapperService.pf
// switch (r.conflictData?.reason) {
// case ConflictReason.NoLastSync:
// }
// }
// return 'USER_ABORT';
return r.status;
}
} catch (error: any) {
@ -142,7 +128,7 @@ export class SyncWrapperService {
msg: T.F.SYNC.S.INCOMPLETE_CFG,
type: 'ERROR',
actionFn: async () => this._matDialog.open(DialogSyncInitialCfgComponent),
actionStr: 'Configure',
actionStr: T.F.SYNC.S.BTN_CONFIGURE,
});
return 'HANDLED_ERROR';
} else if (
@ -165,10 +151,10 @@ export class SyncWrapperService {
} else if (error instanceof LockPresentError) {
this._snackService.open({
// TODO translate
msg: 'Remote Data is currently being written',
msg: T.F.SYNC.S.ERROR_DATA_IS_CURRENTLY_WRITTEN,
type: 'ERROR',
actionFn: async () => this._forceUpload(),
actionStr: 'Force Overwrite',
actionStr: T.F.SYNC.S.BTN_FORCE_OVERWRITE,
});
return 'HANDLED_ERROR';
} else if (
@ -190,18 +176,11 @@ export class SyncWrapperService {
});
return 'HANDLED_ERROR';
}
throw new Error('unhandled sync error');
}
}
private async _forceUpload(): Promise<void> {
if (
!this._c(
this._translateService.instant(
'Forcing an upload of your data could lead to data loss. Continue?',
),
)
) {
if (!this._c(this._translateService.instant(T.F.SYNC.C.FORCE_UPLOAD))) {
return;
}
try {
@ -223,7 +202,6 @@ export class SyncWrapperService {
providerId: SyncProviderId,
): Promise<{ wasConfigured: boolean }> {
const provider = await this._pfapiService.pf.getSyncProviderById(providerId);
console.log(provider);
if (!provider) {
return { wasConfigured: false };
@ -256,9 +234,6 @@ export class SyncWrapperService {
}, 1000);
return { wasConfigured: true };
} else {
// this._globalConfigService.updateSection('sync', {
// isEnabled: false,
// });
return { wasConfigured: false };
}
}
@ -289,18 +264,11 @@ export class SyncWrapperService {
}
private async _reInitAppAfterDataModelChange(): Promise<void> {
// TODO maybe do it more elegantly with pfapi.events
// this._imexViewService.setDataImportInProgress(true);
await Promise.all([
// reload view model from ls
this._dataInitService.reInit(true),
this._reminderService.reloadFromDatabase(),
]);
// this._imexViewService.setDataImportInProgress(false);
// TODO better solution, unclear why needed
// setTimeout(() => {
// this._imexViewService.setDataImportInProgress(false);
// });
}
private _c(str: string): boolean {

View file

@ -870,7 +870,6 @@ const T = {
},
C: {
EMPTY_SYNC: 'F.SYNC.C.EMPTY_SYNC',
FORCE_IMPORT: 'F.SYNC.C.FORCE_IMPORT',
FORCE_UPLOAD: 'F.SYNC.C.FORCE_UPLOAD',
FORCE_UPLOAD_AFTER_ERROR: 'F.SYNC.C.FORCE_UPLOAD_AFTER_ERROR',
MIGRATE_LEGACY: 'F.SYNC.C.MIGRATE_LEGACY',
@ -895,6 +894,11 @@ const T = {
USE_LOCAL: 'F.SYNC.D_CONFLICT.USE_LOCAL',
USE_REMOTE: 'F.SYNC.D_CONFLICT.USE_REMOTE',
},
D_DECRYPT_ERROR: {
BTN_OVER_WRITE_REMOTE: 'F.SYNC.D_DECRYPT_ERROR.BTN_OVER_WRITE_REMOTE',
P1: 'F.SYNC.D_DECRYPT_ERROR.P1',
P2: 'F.SYNC.D_DECRYPT_ERROR.P2',
},
D_INCOMPLETE_SYNC: {
BTN_CLOSE_APP: 'F.SYNC.D_INCOMPLETE_SYNC.BTN_CLOSE_APP',
BTN_DOWNLOAD_BACKUP: 'F.SYNC.D_INCOMPLETE_SYNC.BTN_DOWNLOAD_BACKUP',
@ -953,6 +957,9 @@ const T = {
S: {
ALREADY_IN_SYNC: 'F.SYNC.S.ALREADY_IN_SYNC',
ALREADY_IN_SYNC_NO_LOCAL_CHANGES: 'F.SYNC.S.ALREADY_IN_SYNC_NO_LOCAL_CHANGES',
BTN_CONFIGURE: 'F.SYNC.S.BTN_CONFIGURE',
BTN_FORCE_OVERWRITE: 'F.SYNC.S.BTN_FORCE_OVERWRITE',
ERROR_DATA_IS_CURRENTLY_WRITTEN: 'F.SYNC.S.ERROR_DATA_IS_CURRENTLY_WRITTEN',
ERROR_FALLBACK_TO_BACKUP: 'F.SYNC.S.ERROR_FALLBACK_TO_BACKUP',
ERROR_INVALID_DATA: 'F.SYNC.S.ERROR_INVALID_DATA',
ERROR_NO_REV: 'F.SYNC.S.ERROR_NO_REV',
@ -1658,6 +1665,13 @@ const T = {
TRIGGER_SYNC: 'MH.TRIGGER_SYNC',
WORKLOG: 'MH.WORKLOG',
},
MIGRATE: {
DETECTED_LEGACY: 'MIGRATE.DETECTED_LEGACY',
SUCCESS: 'MIGRATE.SUCCESS',
C_DOWNLOAD_BACKUP: 'MIGRATE.C_DOWNLOAD_BACKUP',
E_MIGRATION_FAILED: 'MIGRATE.E_MIGRATION_FAILED',
E_RESTART_FAILED: 'MIGRATE.E_RESTART_FAILED',
},
PDS: {
BACK: 'PDS.BACK',
BREAK_LABEL: 'PDS.BREAK_LABEL',

View file

@ -858,8 +858,7 @@
},
"C": {
"EMPTY_SYNC": "You're trying to sync an empty data object. If you are trying to setup syncing from a new app instance, just press OK to load the data from the server. Otherwise, please check your data.",
"FORCE_IMPORT": "Import remote data anyway?",
"FORCE_UPLOAD": "Upload local data anyway?",
"FORCE_UPLOAD": "Forcing an upload of your data could lead to data loss. Continue?",
"FORCE_UPLOAD_AFTER_ERROR": "An Error occurred while uploading your local data. Try to force the update?",
"MIGRATE_LEGACY": "Legacy data detected while importing, do you want to try to migrate it?",
"NO_REMOTE_DATA": "No remote data found. Upload local to Remote?",
@ -883,6 +882,11 @@
"USE_LOCAL": "Keep local",
"USE_REMOTE": "Keep remote"
},
"D_DECRYPT_ERROR": {
"BTN_OVER_WRITE_REMOTE": "Change and overwrite remote",
"P1": "Your data is encrypted and decryption failed. Please enter the correct password!",
"P2": "You can also change your password, which will overwrite all remote data."
},
"D_INCOMPLETE_SYNC": {
"BTN_CLOSE_APP": "Close App",
"BTN_DOWNLOAD_BACKUP": "Download Local Backup",
@ -940,6 +944,9 @@
"S": {
"ALREADY_IN_SYNC": "Already in sync",
"ALREADY_IN_SYNC_NO_LOCAL_CHANGES": "No local changes Already in sync",
"BTN_CONFIGURE": "Configure",
"BTN_FORCE_OVERWRITE": "Force Overwrite",
"ERROR_DATA_IS_CURRENTLY_WRITTEN": "Remote Data is currently being written",
"ERROR_FALLBACK_TO_BACKUP": "Something went wrong while importing the data. Falling back to local backup.",
"ERROR_INVALID_DATA": "Error while syncing. Invalid data",
"ERROR_NO_REV": "No valid rev for remote file",
@ -1632,6 +1639,14 @@
"TRIGGER_SYNC": "Sync!",
"WORKLOG": "Worklog"
},
"MIGRATE": {
"DETECTED_LEGACY": "Detected legacy data. We will migrate it for you!",
"SUCCESS": "Migration all done! Restarting app now...",
"C_DOWNLOAD_BACKUP": "Do you want to download a backup of your legacy data (can be used with older versions of Super Productivity)?",
"E_MIGRATION_FAILED": "Migration failed! with Error:",
"E_RESTART_FAILED": "Automatic restart failed. Please restart the app manually!"
},
"PDS": {
"BACK": "Wait I forgot something!",
"BREAK_LABEL": "Breaks (nr / time)",