Skip to content

Commit

Permalink
Merge pull request #502 from VitNode/lang/improve_admin_keys
Browse files Browse the repository at this point in the history
perf(frontend): Improve name keys for plugin in AdminCP
  • Loading branch information
aXenDeveloper authored Sep 9, 2024
2 parents 0a12058 + aa1d084 commit 32a2763
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 62 deletions.
15 changes: 7 additions & 8 deletions apps/docs/content/docs/dev/pages-admin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down
60 changes: 29 additions & 31 deletions apps/frontend/src/plugins/core/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
}
7 changes: 3 additions & 4 deletions apps/frontend/src/plugins/welcome/langs/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"welcome": {
"admin": {}
}
}
"welcome": {},
"admin_welcome": {}
}
2 changes: 0 additions & 2 deletions packages/backend/scripts/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ export class CreateAdminPluginsService {
join(langPath, `${lang.code}.json`),
JSON.stringify(
{
[code]: {
admin: {},
},
[code]: {},
[`admin_${code}`]: {},
},
null,
2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function generateMetadataDevPluginAdminLayout({
}: DevPluginAdminLayoutProps): Promise<Metadata> {
const [t, tCore, config] = await Promise.all([
getTranslations('admin'),
getTranslations('core.admin'),
getTranslations('admin_core'),
getGlobalData(),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -30,7 +30,7 @@ export const ItemContentNavDevPluginAdmin = (
<p className="text-muted-foreground text-sm">
{tAdmin.rich('lang_key', {
key: () => (
<span className="text-foreground">{`${pluginCode}.admin.nav.${langKey}`}</span>
<span className="text-foreground">{`admin_${pluginCode}.nav.${langKey}`}</span>
),
})}
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getData = async () => {

export const generateMetadataAuthorizationSettingsAdmin =
async (): Promise<Metadata> => {
const t = await getTranslations('core.admin.nav');
const t = await getTranslations('admin_core.nav');

return {
title: t('settings_authorization'),
Expand All @@ -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(),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getData = async () => {

export const generateMetadataEmailSettingsAdmin =
async (): Promise<Metadata> => {
const t = await getTranslations('core.admin.nav');
const t = await getTranslations('admin_core.nav');

return {
title: t('settings_email'),
Expand All @@ -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(),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const getData = async () => {

export const generateMetadataMainSettingsCoreAdmin =
async (): Promise<Metadata> => {
const t = await getTranslations('core.admin.nav');
const t = await getTranslations('admin_core.nav');

return {
title: t('settings_general'),
Expand All @@ -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(),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const getData = async () => {
};

export const generateMetadataThemeEditor = async (): Promise<Metadata> => {
const t = await getTranslations('core.admin.nav');
const t = await getTranslations('admin_core.nav');

return {
title: t('styles_theme-editor'),
Expand Down

0 comments on commit 32a2763

Please sign in to comment.