Skip to content

Commit 5690603

Browse files
committed
fix fe message
1 parent 84569bf commit 5690603

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

adminforth/documentation/docs/tutorial/03-Customization/06-customPages.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -499,19 +499,6 @@ admin.discoverDatabases();
499499
mongoose, or just use raw SQL queries against your tables.
500500
501501
502-
> ☝️ To call API from frontend component we use Adminforth's callApi method.
503-
> However this is not mandatory. Alternatively you can just use plain fetch:
504-
>
505-
> ```ts
506-
> //diff-remove
507-
> data.value = await callApi({path: '/api/dashboard/', method: 'GET'});
508-
> //diff-add
509-
> const response = await fetch('/api/dashboard/');
510-
> //diff-add
511-
> data.value = await response.json();
512-
> ```
513-
> however, the callApi function will handle path prefixing(you can change baseUrl and it will take this into account) and 401 redirect to login when user is logged out
514-
515502
Demo:
516503
517504
![alt text](dashDemo.gif)

adminforth/plugins/i18n/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export default class I18N extends AdminForthPlugin {
326326
this.updateUntranslatedMenuBadge();
327327
return {
328328
ok: true, error: undefined,
329-
successMessage: await tr(`Translated {count} items`, 'frontend', {count: selectedIds.length}),
329+
successMessage: await tr(`Translated {count} items`, 'backend', {count: selectedIds.length}),
330330
};
331331
}
332332
}
@@ -619,11 +619,18 @@ ${
619619
if (!msg) {
620620
return msg;
621621
}
622+
623+
if (category === 'frontend') {
624+
throw new Error(`Category 'frontend' is reserved for frontend messages, use any other category for backend messages`);
625+
}
622626
// console.log('🪲tr', msg, category, lang);
623627

624628
// if lang is not supported , throw
625629
if (!this.options.supportedLanguages.includes(lang as LanguageCode)) {
626-
throw new Error(`Language ${lang} is not entered to be supported by requested by browser in request headers accept-language`);
630+
lang = 'en'; // for now simply fallback to english
631+
632+
// throwing like line below might be too strict, e.g. for custom apis made with fetch which don't pass accept-language
633+
// throw new Error(`Language ${lang} is not entered to be supported by requested by browser in request headers accept-language`);
627634
}
628635

629636
let result;

0 commit comments

Comments
 (0)