From 95bdb9d594f8567c6f657220d5fdead74884b468 Mon Sep 17 00:00:00 2001 From: aXenDeveloper Date: Mon, 9 Sep 2024 18:36:06 +0200 Subject: [PATCH 1/2] perf(frontend): Improve name keys for plugin in AdminCP --- apps/docs/content/docs/dev/pages-admin.mdx | 15 +++-- apps/frontend/src/plugins/core/langs/en.json | 60 +++++++++---------- .../src/plugins/welcome/langs/en.json | 7 +-- packages/backend/scripts/database.ts | 2 - .../admin/plugins/create/create.service.ts | 5 +- .../layout/auth/aside/search/items/page.tsx | 2 +- .../views/admin/layout/auth/nav/item/item.tsx | 2 +- .../views/admin/layout/auth/nav/item/link.tsx | 2 +- .../views/dev/nav/create-edit/create-edit.tsx | 2 +- .../core/plugins/views/dev/nav/item/item.tsx | 4 +- 10 files changed, 47 insertions(+), 54 deletions(-) diff --git a/apps/docs/content/docs/dev/pages-admin.mdx b/apps/docs/content/docs/dev/pages-admin.mdx index 9f9f2ebdb..59ad356fe 100644 --- a/apps/docs/content/docs/dev/pages-admin.mdx +++ b/apps/docs/content/docs/dev/pages-admin.mdx @@ -52,21 +52,20 @@ Default language is English `en`. If you have more then one language add keys to ### Language Keys -- **Title Plugin** - key is always `{your_plugin_code}.admin.nav.title`. +- **Title Plugin** - key is always `admin_{your_plugin_code}.nav.title`. For example: `blog.admin.nav.title`, -- **Navigation item** - key is always `{your_plugin_code}.admin.nav.{navigation_item_name}`. +- **Navigation item** - key is always `admin_{your_plugin_code}.nav.{navigation_item_name}`. For example: `blog.admin.nav.categories`. Here is an example of the language keys: ```json title="en.json" { - "blog": { - "admin": { - "nav": { - "title": "Blog", - "categories": "Categories" - } + "blog": {}, + "admin_blog": { + "nav": { + "title": "Blog", + "categories": "Categories" } } } diff --git a/apps/frontend/src/plugins/core/langs/en.json b/apps/frontend/src/plugins/core/langs/en.json index d0776ddfd..c11c57a32 100644 --- a/apps/frontend/src/plugins/core/langs/en.json +++ b/apps/frontend/src/plugins/core/langs/en.json @@ -338,27 +338,6 @@ "contact": "Contact with Us" } }, - "admin": { - "nav": { - "title": "Core", - "dashboard": "Dashboard", - "settings": "Settings", - "settings_general": "General", - "settings_security": "Security", - "settings_metadata": "Metadata", - "settings_email": "Email", - "settings_authorization": "Authorization", - "settings_legal": "Legal & Policies", - "plugins": "Plugins", - "styles": "Styles", - "styles_theme-editor": "Theme Editor", - "styles_nav": "Navigation", - "styles_editor": "Editor", - "langs": "Languages", - "advanced": "Advanced", - "advanced_files": "Files" - } - }, "legal": { "title": "Legal & Policies", "title_page": "Explore our Legal documents and Policies", @@ -367,16 +346,35 @@ "empty": "No documents found." } }, - "members": { - "admin": { - "nav": { - "title": "Members", - "users": "Users List", - "groups": "Groups", - "staff": "Staff", - "staff_moderators": "Moderators", - "staff_administrators": "Administrators" - } + "admin_core": { + "nav": { + "title": "Core", + "dashboard": "Dashboard", + "settings": "Settings", + "settings_general": "General", + "settings_security": "Security", + "settings_metadata": "Metadata", + "settings_email": "Email", + "settings_authorization": "Authorization", + "settings_legal": "Legal & Policies", + "plugins": "Plugins", + "styles": "Styles", + "styles_theme-editor": "Theme Editor", + "styles_nav": "Navigation", + "styles_editor": "Editor", + "langs": "Languages", + "advanced": "Advanced", + "advanced_files": "Files" + } + }, + "admin_members": { + "nav": { + "title": "Members", + "users": "Users List", + "groups": "Groups", + "staff": "Staff", + "staff_moderators": "Moderators", + "staff_administrators": "Administrators" } } } diff --git a/apps/frontend/src/plugins/welcome/langs/en.json b/apps/frontend/src/plugins/welcome/langs/en.json index bfbf3a86d..2e52066c4 100644 --- a/apps/frontend/src/plugins/welcome/langs/en.json +++ b/apps/frontend/src/plugins/welcome/langs/en.json @@ -1,5 +1,4 @@ { - "welcome": { - "admin": {} - } -} \ No newline at end of file + "welcome": {}, + "admin_welcome": {} +} diff --git a/packages/backend/scripts/database.ts b/packages/backend/scripts/database.ts index 82462fff6..57da1fbda 100644 --- a/packages/backend/scripts/database.ts +++ b/packages/backend/scripts/database.ts @@ -7,8 +7,6 @@ const execShellCommand = async (cmd: string) => { reject(error); } const result = stdout ? stdout : stderr; - // eslint-disable-next-line no-console - console.log(result); resolve(result); }); diff --git a/packages/backend/src/core/admin/plugins/create/create.service.ts b/packages/backend/src/core/admin/plugins/create/create.service.ts index 907facc4a..e47662a52 100644 --- a/packages/backend/src/core/admin/plugins/create/create.service.ts +++ b/packages/backend/src/core/admin/plugins/create/create.service.ts @@ -72,9 +72,8 @@ export class CreateAdminPluginsService { join(langPath, `${lang.code}.json`), JSON.stringify( { - [code]: { - admin: {}, - }, + [code]: {}, + [`admin_${code}`]: {}, }, null, 2, diff --git a/packages/frontend/src/views/admin/layout/auth/aside/search/items/page.tsx b/packages/frontend/src/views/admin/layout/auth/aside/search/items/page.tsx index 17cdeb04b..ef8ee8e61 100644 --- a/packages/frontend/src/views/admin/layout/auth/aside/search/items/page.tsx +++ b/packages/frontend/src/views/admin/layout/auth/aside/search/items/page.tsx @@ -20,7 +20,7 @@ export const PageItemContentSearchAsideAuthAdmin = ({ }: Props) => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error - const t = useTranslations(`${code_plugin}.admin`); + const t = useTranslations(`admin_${code_plugin}`); const { push } = useRouter(); const href = parent_nav_code ? `/admin/${code_plugin}/${parent_nav_code}/${hrefFromProps}` diff --git a/packages/frontend/src/views/admin/layout/auth/nav/item/item.tsx b/packages/frontend/src/views/admin/layout/auth/nav/item/item.tsx index 8015d06f1..32dd17025 100644 --- a/packages/frontend/src/views/admin/layout/auth/nav/item/item.tsx +++ b/packages/frontend/src/views/admin/layout/auth/nav/item/item.tsx @@ -12,7 +12,7 @@ export const ItemNavAdmin = ({ }) => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error - const t = useTranslations(`${id}.admin`); + const t = useTranslations(`admin_${id}`); return ( <> diff --git a/packages/frontend/src/views/admin/layout/auth/nav/item/link.tsx b/packages/frontend/src/views/admin/layout/auth/nav/item/link.tsx index 285b6adf4..180fdb148 100644 --- a/packages/frontend/src/views/admin/layout/auth/nav/item/link.tsx +++ b/packages/frontend/src/views/admin/layout/auth/nav/item/link.tsx @@ -31,7 +31,7 @@ export const LinkItemNavAdmin = ({ }: Props) => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error - const t = useTranslations(`${plugin_code}.admin.nav`); + const t = useTranslations(`admin_${plugin_code}.nav`); const pathname = usePathname(); const href = `/admin/${plugin_code}/${hrefFromProps}`; const active = pathname.startsWith(`/admin/${plugin_code}/${id}`); diff --git a/packages/frontend/src/views/admin/views/core/plugins/views/dev/nav/create-edit/create-edit.tsx b/packages/frontend/src/views/admin/views/core/plugins/views/dev/nav/create-edit/create-edit.tsx index b947d7c78..7e35b526d 100644 --- a/packages/frontend/src/views/admin/views/core/plugins/views/dev/nav/create-edit/create-edit.tsx +++ b/packages/frontend/src/views/admin/views/core/plugins/views/dev/nav/create-edit/create-edit.tsx @@ -38,7 +38,7 @@ export const CreateEditNavDevPluginAdmin = ({ const tPlugin = useTranslations( // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error - `${Array.isArray(code) ? code[0] : code}.admin.nav`, + `admin_${Array.isArray(code) ? code[0] : code}.nav`, ); return ( diff --git a/packages/frontend/src/views/admin/views/core/plugins/views/dev/nav/item/item.tsx b/packages/frontend/src/views/admin/views/core/plugins/views/dev/nav/item/item.tsx index 63e7b11a9..23f6257e1 100644 --- a/packages/frontend/src/views/admin/views/core/plugins/views/dev/nav/item/item.tsx +++ b/packages/frontend/src/views/admin/views/core/plugins/views/dev/nav/item/item.tsx @@ -12,7 +12,7 @@ export const ItemContentNavDevPluginAdmin = ( const { code: pluginCode } = useParams(); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error - const t = useTranslations(`${pluginCode}.admin.nav`); + const t = useTranslations(`admin_${pluginCode}.nav`); const tAdmin = useTranslations('admin.core.plugins.dev.nav'); const tCore = useTranslations('core'); const { parentId, icons } = useItemNavDevPluginAdmin(); @@ -30,7 +30,7 @@ export const ItemContentNavDevPluginAdmin = (

{tAdmin.rich('lang_key', { key: () => ( - {`${pluginCode}.admin.nav.${langKey}`} + {`admin_${pluginCode}.nav.${langKey}`} ), })}

From aa1d084985954b4de78938bc3acbd55cbd2673fa Mon Sep 17 00:00:00 2001 From: aXenDeveloper Date: Mon, 9 Sep 2024 18:50:03 +0200 Subject: [PATCH 2/2] chore: Clean up --- .../admin/views/core/plugins/views/dev/layout/layout.tsx | 2 +- .../authorization/authorization-settings-core-admin-view.tsx | 4 ++-- .../views/core/settings/email/email-settings-admin-view.tsx | 4 ++-- .../core/settings/main/main-settings-core-admin-view.tsx | 4 ++-- .../src/views/admin/views/theme_editor/theme-editor-view.tsx | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/frontend/src/views/admin/views/core/plugins/views/dev/layout/layout.tsx b/packages/frontend/src/views/admin/views/core/plugins/views/dev/layout/layout.tsx index 0e0c196cd..b108a92d5 100644 --- a/packages/frontend/src/views/admin/views/core/plugins/views/dev/layout/layout.tsx +++ b/packages/frontend/src/views/admin/views/core/plugins/views/dev/layout/layout.tsx @@ -26,7 +26,7 @@ export async function generateMetadataDevPluginAdminLayout({ }: DevPluginAdminLayoutProps): Promise { const [t, tCore, config] = await Promise.all([ getTranslations('admin'), - getTranslations('core.admin'), + getTranslations('admin_core'), getGlobalData(), ]); diff --git a/packages/frontend/src/views/admin/views/core/settings/authorization/authorization-settings-core-admin-view.tsx b/packages/frontend/src/views/admin/views/core/settings/authorization/authorization-settings-core-admin-view.tsx index 39137480d..00439b141 100644 --- a/packages/frontend/src/views/admin/views/core/settings/authorization/authorization-settings-core-admin-view.tsx +++ b/packages/frontend/src/views/admin/views/core/settings/authorization/authorization-settings-core-admin-view.tsx @@ -21,7 +21,7 @@ const getData = async () => { export const generateMetadataAuthorizationSettingsAdmin = async (): Promise => { - const t = await getTranslations('core.admin.nav'); + const t = await getTranslations('admin_core.nav'); return { title: t('settings_authorization'), @@ -30,7 +30,7 @@ export const generateMetadataAuthorizationSettingsAdmin = export const AuthorizationSettingsCoreAdminView = async () => { const [t, data] = await Promise.all([ - getTranslations('core.admin.nav'), + getTranslations('admin_core.nav'), getData(), ]); diff --git a/packages/frontend/src/views/admin/views/core/settings/email/email-settings-admin-view.tsx b/packages/frontend/src/views/admin/views/core/settings/email/email-settings-admin-view.tsx index 2f24e5422..1db325f28 100644 --- a/packages/frontend/src/views/admin/views/core/settings/email/email-settings-admin-view.tsx +++ b/packages/frontend/src/views/admin/views/core/settings/email/email-settings-admin-view.tsx @@ -26,7 +26,7 @@ const getData = async () => { export const generateMetadataEmailSettingsAdmin = async (): Promise => { - const t = await getTranslations('core.admin.nav'); + const t = await getTranslations('admin_core.nav'); return { title: t('settings_email'), @@ -35,7 +35,7 @@ export const generateMetadataEmailSettingsAdmin = export const EmailSettingsAdminView = async () => { const [t, data] = await Promise.all([ - getTranslations('core.admin.nav'), + getTranslations('admin_core.nav'), getData(), ]); diff --git a/packages/frontend/src/views/admin/views/core/settings/main/main-settings-core-admin-view.tsx b/packages/frontend/src/views/admin/views/core/settings/main/main-settings-core-admin-view.tsx index 2ed59e93c..2871fede6 100644 --- a/packages/frontend/src/views/admin/views/core/settings/main/main-settings-core-admin-view.tsx +++ b/packages/frontend/src/views/admin/views/core/settings/main/main-settings-core-admin-view.tsx @@ -24,7 +24,7 @@ const getData = async () => { export const generateMetadataMainSettingsCoreAdmin = async (): Promise => { - const t = await getTranslations('core.admin.nav'); + const t = await getTranslations('admin_core.nav'); return { title: t('settings_general'), @@ -33,7 +33,7 @@ export const generateMetadataMainSettingsCoreAdmin = export const MainSettingsCoreAdminView = async () => { const [t, data] = await Promise.all([ - getTranslations('core.admin.nav'), + getTranslations('admin_core.nav'), getData(), ]); diff --git a/packages/frontend/src/views/admin/views/theme_editor/theme-editor-view.tsx b/packages/frontend/src/views/admin/views/theme_editor/theme-editor-view.tsx index 1bd69a92d..b495d4519 100644 --- a/packages/frontend/src/views/admin/views/theme_editor/theme-editor-view.tsx +++ b/packages/frontend/src/views/admin/views/theme_editor/theme-editor-view.tsx @@ -23,7 +23,7 @@ const getData = async () => { }; export const generateMetadataThemeEditor = async (): Promise => { - const t = await getTranslations('core.admin.nav'); + const t = await getTranslations('admin_core.nav'); return { title: t('styles_theme-editor'),