@adminforth/i18n 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom/langCommon.ts +1 -0
- package/dist/custom/langCommon.ts +1 -0
- package/dist/index.js +14 -5
- package/index.ts +10 -0
- package/package.json +1 -1
package/custom/langCommon.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -205,29 +205,38 @@ export default class I18N extends AdminForthPlugin {
|
|
|
205
205
|
// clear frontend cache for all lan
|
|
206
206
|
return { ok: true };
|
|
207
207
|
}));
|
|
208
|
+
// add hook on delete of any translation to reset cache
|
|
209
|
+
resourceConfig.hooks.delete.afterSave.push((_d) => __awaiter(this, [_d], void 0, function* ({ record }) {
|
|
210
|
+
for (const lang of this.options.supportedLanguages) {
|
|
211
|
+
this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
|
|
212
|
+
this.cache.clear(`${this.resourceConfig.resourceId}:${record[this.options.categoryFieldName]}:${lang}:${record[this.enFieldName]}`);
|
|
213
|
+
}
|
|
214
|
+
this.updateUntranslatedMenuBadge();
|
|
215
|
+
return { ok: true };
|
|
216
|
+
}));
|
|
208
217
|
if (this.options.completedFieldName) {
|
|
209
218
|
// on show and list add a list hook which will add incomplete field to record if translation is missing for at least one language
|
|
210
219
|
const addIncompleteField = (record) => {
|
|
211
220
|
// form list of all langs, sorted by alphabet, without en, to get 'al|ro|uk'
|
|
212
221
|
record.fully_translated = this.fullCompleatedFieldValue === record[this.options.completedFieldName];
|
|
213
222
|
};
|
|
214
|
-
resourceConfig.hooks.list.afterDatasourceResponse.push((
|
|
223
|
+
resourceConfig.hooks.list.afterDatasourceResponse.push((_e) => __awaiter(this, [_e], void 0, function* ({ response }) {
|
|
215
224
|
response.forEach(addIncompleteField);
|
|
216
225
|
return { ok: true };
|
|
217
226
|
}));
|
|
218
|
-
resourceConfig.hooks.show.afterDatasourceResponse.push((
|
|
227
|
+
resourceConfig.hooks.show.afterDatasourceResponse.push((_f) => __awaiter(this, [_f], void 0, function* ({ response }) {
|
|
219
228
|
addIncompleteField(response.length && response[0]);
|
|
220
229
|
return { ok: true };
|
|
221
230
|
}));
|
|
222
231
|
// also add edit hook beforeSave to update completedFieldName
|
|
223
|
-
resourceConfig.hooks.edit.beforeSave.push((
|
|
232
|
+
resourceConfig.hooks.edit.beforeSave.push((_g) => __awaiter(this, [_g], void 0, function* ({ record, oldRecord }) {
|
|
224
233
|
const futureRecord = Object.assign(Object.assign({}, oldRecord), record);
|
|
225
234
|
const futureCompletedFieldValue = yield this.computeCompletedFieldValue(futureRecord);
|
|
226
235
|
record[this.options.completedFieldName] = futureCompletedFieldValue;
|
|
227
236
|
return { ok: true };
|
|
228
237
|
}));
|
|
229
238
|
// add list hook to support filtering by fully_translated virtual field
|
|
230
|
-
resourceConfig.hooks.list.beforeDatasourceRequest.push((
|
|
239
|
+
resourceConfig.hooks.list.beforeDatasourceRequest.push((_h) => __awaiter(this, [_h], void 0, function* ({ query }) {
|
|
231
240
|
if (!query.filters || query.filters.length === 0) {
|
|
232
241
|
query.filters = [];
|
|
233
242
|
}
|
|
@@ -265,7 +274,7 @@ export default class I18N extends AdminForthPlugin {
|
|
|
265
274
|
// if optional `confirm` is provided, user will be asked to confirm action
|
|
266
275
|
confirm: 'Are you sure you want to translate selected items?',
|
|
267
276
|
state: 'selected',
|
|
268
|
-
action: (
|
|
277
|
+
action: (_j) => __awaiter(this, [_j], void 0, function* ({ selectedIds, tr }) {
|
|
269
278
|
try {
|
|
270
279
|
yield this.bulkTranslate({ selectedIds });
|
|
271
280
|
}
|
package/index.ts
CHANGED
|
@@ -234,6 +234,16 @@ export default class I18N extends AdminForthPlugin {
|
|
|
234
234
|
return { ok: true };
|
|
235
235
|
});
|
|
236
236
|
|
|
237
|
+
// add hook on delete of any translation to reset cache
|
|
238
|
+
resourceConfig.hooks.delete.afterSave.push(async ({ record }: { record: any }): Promise<{ ok: boolean, error?: string }> => {
|
|
239
|
+
for (const lang of this.options.supportedLanguages) {
|
|
240
|
+
this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
|
|
241
|
+
this.cache.clear(`${this.resourceConfig.resourceId}:${record[this.options.categoryFieldName]}:${lang}:${record[this.enFieldName]}`);
|
|
242
|
+
}
|
|
243
|
+
this.updateUntranslatedMenuBadge();
|
|
244
|
+
return { ok: true };
|
|
245
|
+
});
|
|
246
|
+
|
|
237
247
|
if (this.options.completedFieldName) {
|
|
238
248
|
// on show and list add a list hook which will add incomplete field to record if translation is missing for at least one language
|
|
239
249
|
const addIncompleteField = (record: any) => {
|