MOBILE-3654 sync: Add component translatable string

main
Pau Ferrer Ocaña 2021-03-18 11:19:06 +01:00
parent 3dbe1d12d7
commit 28bf4243bc
11 changed files with 85 additions and 121 deletions

View File

@ -28,7 +28,6 @@ import { AddonCalendarOffline } from './calendar-offline';
import { AddonCalendarHelper } from './calendar-helper'; import { AddonCalendarHelper } from './calendar-helper';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
import { CoreTextUtils } from '@services/utils/text';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
/** /**
@ -41,6 +40,8 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider<AddonCalenda
static readonly MANUAL_SYNCED = 'addon_calendar_manual_synced'; static readonly MANUAL_SYNCED = 'addon_calendar_manual_synced';
static readonly SYNC_ID = 'calendar'; static readonly SYNC_ID = 'calendar';
protected componentTranslatableString = 'addon.calendar.calendarevent';
constructor() { constructor() {
super('AddonCalendarSync'); super('AddonCalendarSync');
} }
@ -229,12 +230,9 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider<AddonCalenda
})); }));
await Promise.all(promises); await Promise.all(promises);
// Event deleted, add a warning. // Event deleted, add a warning.
result.warnings.push(Translate.instant('core.warningofflinedatadeleted', { this.addOfflineDataDeletedWarning(result.warnings, data.name, error);
component: Translate.instant('addon.calendar.calendarevent'),
name: data.name,
error: CoreTextUtils.getErrorMessageFromError(error),
}));
} }
return; return;
@ -286,12 +284,9 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider<AddonCalenda
result.updated = true; result.updated = true;
await AddonCalendarOffline.deleteEvent(event.id!, siteId); await AddonCalendarOffline.deleteEvent(event.id!, siteId);
// Event deleted, add a warning. // Event deleted, add a warning.
result.warnings.push(Translate.instant('core.warningofflinedatadeleted', { this.addOfflineDataDeletedWarning(result.warnings, event.name, error);
component: Translate.instant('addon.calendar.calendarevent'),
name: event.name,
error: CoreTextUtils.getErrorMessageFromError(error),
}));
} }
} }

View File

@ -36,7 +36,6 @@ import { CoreSync } from '@services/sync';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreTextUtils } from '@services/utils/text';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreGradesFormattedItem, CoreGradesFormattedRow, CoreGradesHelper } from '@features/grades/services/grades-helper'; import { CoreGradesFormattedItem, CoreGradesFormattedRow, CoreGradesHelper } from '@features/grades/services/grades-helper';
import { AddonModAssignSubmissionDelegate } from './submission-delegate'; import { AddonModAssignSubmissionDelegate } from './submission-delegate';
@ -51,11 +50,10 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid
static readonly AUTO_SYNCED = 'addon_mod_assign_autom_synced'; static readonly AUTO_SYNCED = 'addon_mod_assign_autom_synced';
static readonly MANUAL_SYNCED = 'addon_mod_assign_manual_synced'; static readonly MANUAL_SYNCED = 'addon_mod_assign_manual_synced';
protected componentTranslate: string; protected componentTranslatableString = 'assign';
constructor() { constructor() {
super('AddonModLessonSyncProvider'); super('AddonModLessonSyncProvider');
this.componentTranslate = CoreCourse.translateModuleName('assign');
} }
/** /**
@ -164,7 +162,6 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid
*/ */
async syncAssign(assignId: number, siteId?: string): Promise<AddonModAssignSyncResult> { async syncAssign(assignId: number, siteId?: string): Promise<AddonModAssignSyncResult> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
this.componentTranslate = this.componentTranslate || CoreCourse.translateModuleName('assign');
if (this.isSyncing(assignId, siteId)) { if (this.isSyncing(assignId, siteId)) {
// There's already a sync ongoing for this assign, return the promise. // There's already a sync ongoing for this assign, return the promise.
@ -328,7 +325,6 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid
// The submission was modified in Moodle, discard the submission. // The submission was modified in Moodle, discard the submission.
this.addOfflineDataDeletedWarning( this.addOfflineDataDeletedWarning(
warnings, warnings,
this.componentTranslate,
assign.name, assign.name,
Translate.instant('addon.mod_assign.warningsubmissionmodified'), Translate.instant('addon.mod_assign.warningsubmissionmodified'),
); );
@ -369,12 +365,7 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid
} }
// A WebService has thrown an error, this means it cannot be submitted. Discard the submission. // A WebService has thrown an error, this means it cannot be submitted. Discard the submission.
this.addOfflineDataDeletedWarning( this.addOfflineDataDeletedWarning(warnings, assign.name, error);
warnings,
this.componentTranslate,
assign.name,
CoreTextUtils.getErrorMessageFromError(error) || '',
);
} }
// Delete the offline data. // Delete the offline data.
@ -458,7 +449,6 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid
// The submission grade was modified in Moodle, discard it. // The submission grade was modified in Moodle, discard it.
this.addOfflineDataDeletedWarning( this.addOfflineDataDeletedWarning(
warnings, warnings,
this.componentTranslate,
assign.name, assign.name,
Translate.instant('addon.mod_assign.warningsubmissiongrademodified'), Translate.instant('addon.mod_assign.warningsubmissiongrademodified'),
); );
@ -527,12 +517,7 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid
} }
// A WebService has thrown an error, this means it cannot be submitted. Discard the submission. // A WebService has thrown an error, this means it cannot be submitted. Discard the submission.
this.addOfflineDataDeletedWarning( this.addOfflineDataDeletedWarning(warnings, assign.name, error);
warnings,
this.componentTranslate,
assign.name,
CoreTextUtils.getErrorMessageFromError(error) || '',
);
} }
// Delete the offline data. // Delete the offline data.

View File

@ -14,8 +14,7 @@
import { ContextLevel } from '@/core/constants'; import { ContextLevel } from '@/core/constants';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreSyncBaseProvider } from '@classes/base-sync'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync';
import { CoreCourse } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploader } from '@features/fileuploader/services/fileuploader';
import { CoreRatingSync } from '@features/rating/services/rating-sync'; import { CoreRatingSync } from '@features/rating/services/rating-sync';
@ -23,7 +22,6 @@ import { CoreApp } from '@services/app';
import { CoreGroups } from '@services/groups'; import { CoreGroups } from '@services/groups';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { CoreArray } from '@singletons/array'; import { CoreArray } from '@singletons/array';
@ -55,25 +53,17 @@ declare module '@singletons/events' {
* Service to sync forums. * Service to sync forums.
*/ */
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class AddonModForumSyncProvider extends CoreSyncBaseProvider<AddonModForumSyncResult> { export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvider<AddonModForumSyncResult> {
static readonly AUTO_SYNCED = 'addon_mod_forum_autom_synced'; static readonly AUTO_SYNCED = 'addon_mod_forum_autom_synced';
static readonly MANUAL_SYNCED = 'addon_mod_forum_manual_synced'; static readonly MANUAL_SYNCED = 'addon_mod_forum_manual_synced';
private _componentTranslate?: string; protected componentTranslatableString = 'forum';
constructor() { constructor() {
super('AddonModForumSyncProvider'); super('AddonModForumSyncProvider');
} }
protected get componentTranslate(): string {
if (!this._componentTranslate) {
this._componentTranslate = CoreCourse.translateModuleName('forum');
}
return this._componentTranslate;
}
/** /**
* Try to synchronize all the forums in a certain site or in all sites. * Try to synchronize all the forums in a certain site or in all sites.
* *
@ -291,11 +281,7 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider<AddonModForu
if (errors.length === groupIds.length) { if (errors.length === groupIds.length) {
// All requests failed with WS error. // All requests failed with WS error.
result.warnings.push(Translate.instant('core.warningofflinedatadeleted', { this.addOfflineDataDeletedWarning(result.warnings, discussion.name, errors[0]);
component: this.componentTranslate,
name: discussion.name,
error: CoreTextUtils.getErrorMessageFromError(errors[0]),
}));
} }
}); });
@ -352,11 +338,7 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider<AddonModForu
promises.push(AddonModForum.getForum(result.itemSet!.courseId!, result.itemSet!.instanceId, { siteId }) promises.push(AddonModForum.getForum(result.itemSet!.courseId!, result.itemSet!.instanceId, { siteId })
.then((forum) => { .then((forum) => {
result.warnings.forEach((warning) => { result.warnings.forEach((warning) => {
warnings.push(Translate.instant('core.warningofflinedatadeleted', { this.addOfflineDataDeletedWarning(warnings, forum.name, warning);
component: this.componentTranslate,
name: forum.name,
error: warning,
}));
}); });
return; return;
@ -512,11 +494,8 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider<AddonModForu
await this.deleteReply(forumId, reply.postid, siteId, userId); await this.deleteReply(forumId, reply.postid, siteId, userId);
// Responses deleted, add a warning. // Responses deleted, add a warning.
result.warnings.push(Translate.instant('core.warningofflinedatadeleted', { this.addOfflineDataDeletedWarning(result.warnings, reply.name, error);
component: this.componentTranslate,
name: reply.name,
error: CoreTextUtils.getErrorMessageFromError(error),
}));
} }
}); });

View File

@ -16,15 +16,13 @@ import { Injectable } from '@angular/core';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync';
import { CoreCourse } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreXAPIOffline } from '@features/xapi/services/offline'; import { CoreXAPIOffline } from '@features/xapi/services/offline';
import { CoreXAPI } from '@features/xapi/services/xapi'; import { CoreXAPI } from '@features/xapi/services/xapi';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { AddonModH5PActivity, AddonModH5PActivityProvider } from './h5pactivity'; import { AddonModH5PActivity, AddonModH5PActivityProvider } from './h5pactivity';
@ -36,25 +34,12 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP
static readonly AUTO_SYNCED = 'addon_mod_h5pactivity_autom_synced'; static readonly AUTO_SYNCED = 'addon_mod_h5pactivity_autom_synced';
protected componentTranslate?: string; protected componentTranslatableString = 'h5pactivity';
constructor() { constructor() {
super('AddonModH5PActivitySyncProvider'); super('AddonModH5PActivitySyncProvider');
} }
/**
* Get component name translated.
*
* @return Component name translated.
*/
protected getComponentTranslate(): string {
if (!this.componentTranslate) {
this.componentTranslate = CoreCourse.translateModuleName('h5pactivity');
}
return this.componentTranslate;
}
/** /**
* Try to synchronize all the H5P activities in a certain site or in all sites. * Try to synchronize all the H5P activities in a certain site or in all sites.
* *
@ -188,11 +173,8 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP
await CoreXAPIOffline.deleteStatements(entry.id, siteId); await CoreXAPIOffline.deleteStatements(entry.id, siteId);
// Responses deleted, add a warning. // Responses deleted, add a warning.
result.warnings.push(Translate.instant('core.warningofflinedatadeleted', { this.addOfflineDataDeletedWarning(result.warnings, entry.extra || '', error);
component: this.componentTranslate,
name: entry.extra,
error: CoreTextUtils.getErrorMessageFromError(error),
}));
} }
} }

View File

@ -22,7 +22,6 @@ import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
import { CoreTextUtils } from '@services/utils/text';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -41,7 +40,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid
static readonly AUTO_SYNCED = 'addon_mod_lesson_autom_synced'; static readonly AUTO_SYNCED = 'addon_mod_lesson_autom_synced';
protected componentTranslate?: string; protected componentTranslatableString = 'lesson';
constructor() { constructor() {
super('AddonModLessonSyncProvider'); super('AddonModLessonSyncProvider');
@ -189,7 +188,6 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid
siteId?: string, siteId?: string,
): Promise<AddonModLessonSyncResult> { ): Promise<AddonModLessonSyncResult> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
this.componentTranslate = this.componentTranslate || CoreCourse.translateModuleName('lesson');
let syncPromise = this.getOngoingSync(lessonId, siteId); let syncPromise = this.getOngoingSync(lessonId, siteId);
if (syncPromise) { if (syncPromise) {
@ -317,11 +315,12 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid
if (attempts.length != attemptsLength) { if (attempts.length != attemptsLength) {
// Some attempts won't be sent, add a warning. // Some attempts won't be sent, add a warning.
result.warnings.push(Translate.instant('core.warningofflinedatadeleted', { this.addOfflineDataDeletedWarning(
component: this.componentTranslate, result.warnings,
name: lesson.name, lesson.name,
error: Translate.instant('addon.mod_lesson.warningretakefinished'), Translate.instant('addon.mod_lesson.warningretakefinished'),
})); );
} }
await Promise.all(promises); await Promise.all(promises);
@ -386,11 +385,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid
await AddonModLessonOffline.deleteAttempt(lesson.id, retake, pageId, timemodified, siteId); await AddonModLessonOffline.deleteAttempt(lesson.id, retake, pageId, timemodified, siteId);
// Attempt deleted, add a warning. // Attempt deleted, add a warning.
result.warnings.push(Translate.instant('core.warningofflinedatadeleted', { this.addOfflineDataDeletedWarning(result.warnings, lesson.name, error);
component: this.componentTranslate,
name: lesson.name,
error: CoreTextUtils.getErrorMessageFromError(error),
}));
} }
} }
@ -447,11 +442,11 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid
if (retake.retake != passwordData.accessInfo.attemptscount) { if (retake.retake != passwordData.accessInfo.attemptscount) {
// The retake changed, add a warning if it isn't there already. // The retake changed, add a warning if it isn't there already.
if (!result.warnings.length) { if (!result.warnings.length) {
result.warnings.push(Translate.instant('core.warningofflinedatadeleted', { this.addOfflineDataDeletedWarning(
component: this.componentTranslate, result.warnings,
name: passwordData.lesson.name, passwordData.lesson.name,
error: Translate.instant('addon.mod_lesson.warningretakefinished'), Translate.instant('addon.mod_lesson.warningretakefinished'),
})); );
} }
await AddonModLessonOffline.deleteRetake(lessonId, siteId); await AddonModLessonOffline.deleteRetake(lessonId, siteId);
@ -488,11 +483,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid
await AddonModLessonOffline.deleteRetake(lessonId, siteId); await AddonModLessonOffline.deleteRetake(lessonId, siteId);
// Retake deleted, add a warning. // Retake deleted, add a warning.
result.warnings.push(Translate.instant('core.warningofflinedatadeleted', { this.addOfflineDataDeletedWarning(result.warnings, passwordData.lesson.name, error);
component: this.componentTranslate,
name: passwordData.lesson.name,
error: CoreTextUtils.getErrorMessageFromError(error),
}));
} }
} }

View File

@ -40,7 +40,7 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider
static readonly AUTO_SYNCED = 'addon_mod_quiz_autom_synced'; static readonly AUTO_SYNCED = 'addon_mod_quiz_autom_synced';
protected componentTranslate?: string; protected componentTranslatableString = 'quiz';
constructor() { constructor() {
super('AddonModQuizSyncProvider'); super('AddonModQuizSyncProvider');
@ -271,7 +271,6 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider
// Verify that quiz isn't blocked. // Verify that quiz isn't blocked.
if (CoreSync.isBlocked(AddonModQuizProvider.COMPONENT, quiz.id, siteId)) { if (CoreSync.isBlocked(AddonModQuizProvider.COMPONENT, quiz.id, siteId)) {
this.logger.debug('Cannot sync quiz ' + quiz.id + ' because it is blocked.'); this.logger.debug('Cannot sync quiz ' + quiz.id + ' because it is blocked.');
this.componentTranslate = this.componentTranslate || CoreCourse.translateModuleName('quiz');
throw new CoreError(Translate.instant('core.errorsyncblocked', { $a: this.componentTranslate })); throw new CoreError(Translate.instant('core.errorsyncblocked', { $a: this.componentTranslate }));
} }

View File

@ -19,9 +19,8 @@ import { CoreCourse } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { AddonModSurveyPrefetchHandler } from './handlers/prefetch'; import { AddonModSurveyPrefetchHandler } from './handlers/prefetch';
import { AddonModSurvey, AddonModSurveyProvider } from './survey'; import { AddonModSurvey, AddonModSurveyProvider } from './survey';
@ -35,11 +34,10 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid
static readonly AUTO_SYNCED = 'addon_mod_survey_autom_synced'; static readonly AUTO_SYNCED = 'addon_mod_survey_autom_synced';
protected componentTranslate: string; protected componentTranslatableString = 'survey';
constructor() { constructor() {
super('AddonModSurveySyncProvider'); super('AddonModSurveySyncProvider');
this.componentTranslate = CoreCourse.translateModuleName('survey');
} }
/** /**
@ -196,11 +194,7 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid
await AddonModSurveyOffline.deleteSurveyAnswers(surveyId, siteId, userId); await AddonModSurveyOffline.deleteSurveyAnswers(surveyId, siteId, userId);
// Answers deleted, add a warning. // Answers deleted, add a warning.
result.warnings.push(Translate.instant('core.warningofflinedatadeleted', { this.addOfflineDataDeletedWarning(result.warnings, data.name, error);
component: this.componentTranslate,
name: data.name,
error: CoreTextUtils.getErrorMessageFromError(error),
}));
} }
if (result.courseId) { if (result.courseId) {

View File

@ -19,7 +19,7 @@ import { CoreTextUtils } from '@services/utils/text';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { CoreError } from '@classes/errors/error'; import { CoreAnyError, CoreError } from '@classes/errors/error';
/** /**
* Blocked sync error. * Blocked sync error.
@ -41,6 +41,16 @@ export class CoreSyncBaseProvider<T = void> {
*/ */
component = 'core'; component = 'core';
/**
* Translatable component name string.
*/
protected componentTranslatableString = 'generic component';
/**
* Translated name of the component.
*/
protected componentTranslateInternal?: string;
/** /**
* Sync provider's interval. * Sync provider's interval.
*/ */
@ -58,15 +68,14 @@ export class CoreSyncBaseProvider<T = void> {
* Add an offline data deleted warning to a list of warnings. * Add an offline data deleted warning to a list of warnings.
* *
* @param warnings List of warnings. * @param warnings List of warnings.
* @param component Component.
* @param name Instance name. * @param name Instance name.
* @param error Specific error message. * @param error Specific error message.
*/ */
protected addOfflineDataDeletedWarning(warnings: string[], component: string, name: string, error: string): void { protected addOfflineDataDeletedWarning(warnings: string[], name: string, error: CoreAnyError): void {
const warning = Translate.instant('core.warningofflinedatadeleted', { const warning = Translate.instant('core.warningofflinedatadeleted', {
component: component, component: this.componentTranslate,
name: name, name: name,
error: error, error: CoreTextUtils.getErrorMessageFromError(error),
}); });
if (warnings.indexOf(warning) == -1) { if (warnings.indexOf(warning) == -1) {
@ -304,4 +313,17 @@ export class CoreSyncBaseProvider<T = void> {
} }
} }
/**
* Get component name translated.
*
* @return Component name translated.
*/
protected get componentTranslate(): string {
if (!this.componentTranslateInternal) {
this.componentTranslateInternal = Translate.instant(this.componentTranslatableString);
}
return this.componentTranslateInternal!;
}
} }

View File

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreTextErrorObject } from '@services/utils/text';
/** /**
* Base Error class. * Base Error class.
* *
@ -31,3 +33,5 @@ export class CoreError extends Error {
} }
} }
export type CoreAnyError = string | CoreError | CoreTextErrorObject | null | undefined;

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { CoreSyncBaseProvider } from '@classes/base-sync'; import { CoreSyncBaseProvider } from '@classes/base-sync';
import { CoreCourseAnyModuleData } from '../services/course'; import { CoreCourse, CoreCourseAnyModuleData } from '../services/course';
import { CoreCourseModulePrefetchDelegate } from '../services/module-prefetch-delegate'; import { CoreCourseModulePrefetchDelegate } from '../services/module-prefetch-delegate';
import { CoreCourseModulePrefetchHandlerBase } from './module-prefetch-handler'; import { CoreCourseModulePrefetchHandlerBase } from './module-prefetch-handler';
@ -22,6 +22,8 @@ import { CoreCourseModulePrefetchHandlerBase } from './module-prefetch-handler';
*/ */
export class CoreCourseActivitySyncBaseProvider<T = void> extends CoreSyncBaseProvider<T> { export class CoreCourseActivitySyncBaseProvider<T = void> extends CoreSyncBaseProvider<T> {
protected componentTranslatableString = 'activity';
/** /**
* Conveniece function to prefetch data after an update. * Conveniece function to prefetch data after an update.
* *
@ -54,4 +56,15 @@ export class CoreCourseActivitySyncBaseProvider<T = void> extends CoreSyncBasePr
} }
} }
/**
* @inheritdoc
*/
protected get componentTranslate(): string {
if (!this.componentTranslateInternal) {
this.componentTranslateInternal = CoreCourse.translateModuleName(this.componentTranslatableString);
}
return this.componentTranslateInternal;
}
} }

View File

@ -18,7 +18,7 @@ import { ModalOptions } from '@ionic/core';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreLang } from '@services/lang'; import { CoreLang } from '@services/lang';
import { CoreError } from '@classes/errors/error'; import { CoreAnyError, CoreError } from '@classes/errors/error';
import { makeSingleton, ModalController, Translate } from '@singletons'; import { makeSingleton, ModalController, Translate } from '@singletons';
import { CoreWSExternalFile } from '@services/ws'; import { CoreWSExternalFile } from '@services/ws';
import { Locutus } from '@singletons/locutus'; import { Locutus } from '@singletons/locutus';
@ -533,7 +533,7 @@ export class CoreTextUtilsProvider {
* @param error Error. * @param error Error.
* @return Error message, undefined if not found. * @return Error message, undefined if not found.
*/ */
getErrorMessageFromError(error?: string | CoreError | CoreTextErrorObject | null): string | undefined { getErrorMessageFromError(error?: CoreAnyError): string | undefined {
if (typeof error == 'string') { if (typeof error == 'string') {
return error; return error;
} }