Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ui/src/components/folder-tree/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<div class="flex align-center">
<AppIcon iconName="app-folder" style="font-size: 20px"></AppIcon>
<span class="ml-8 ellipsis tree-label" style="max-width: 110px" :title="node.label">{{
node.label
i18n_name(node.label)
}}</span>
</div>

Expand Down Expand Up @@ -103,6 +103,7 @@ import { onBeforeRouteLeave } from 'vue-router'
import type { TreeInstance } from 'element-plus'
import CreateFolderDialog from '@/components/folder-tree/CreateFolderDialog.vue'
import { t } from '@/locales'
import { i18n_name } from '@/utils/common'
import folderApi from '@/api/folder'
import { EditionConst } from '@/utils/permission/data'
import { hasPermission } from '@/utils/permission/index'
Expand Down
3 changes: 2 additions & 1 deletion ui/src/components/workspace-dropdown/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<el-button text style="font-size: 14px" class="workspace-dropdown__button">
<AppIcon iconName="app-workspace" style="font-size: 18px"></AppIcon>
<span class="ellipsis" style="max-width: 155px" :title="currentWorkspace?.name">
{{ currentWorkspace?.name }}
{{ i18n_name(currentWorkspace?.name) }}
</span>
<el-icon class="el-icon--right">
<CaretBottom />
Expand Down Expand Up @@ -55,6 +55,7 @@

<script setup lang="ts">
import { watch, ref } from 'vue'
import { i18n_name } from '@/utils/common'
import type { WorkspaceItem } from '@/api/type/workspace'
import useStore from '@/stores'
const props = defineProps({
Expand Down
5 changes: 4 additions & 1 deletion ui/src/locales/lang/en-US/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export default {
authorize: 'Authorized',
inner_admin: 'System Admin',
inner_wsm: 'Workspace Manager',
inner_user: 'Common User',
inner_user: 'Regular User',
root: 'Root Directory',
default_workspace: 'Default Workspace',
default_user_group: 'Default User Group',
},
time: {
daysLater: 'days later',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, please supply the piece of code you'd like me to review.

Expand Down
4 changes: 3 additions & 1 deletion ui/src/locales/lang/zh-CN/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export default {
inner_admin: '系统管理员',
inner_wsm: '工作空间管理员',
inner_user: '普通用户',

root: '根目录',
default_workspace: '默认工作空间',
default_user_group: '默认用户组',
},
time: {
daysLater: '天后',
Expand Down
3 changes: 3 additions & 0 deletions ui/src/locales/lang/zh-Hant/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export default {
inner_admin: '系統管理員',
inner_wsm: '工作空間管理員',
inner_user: '普通用戶',
root: '根目錄',
default_workspace: '預設工作空間',
default_user_group: '預設使用者群組',
},
time: {
daysLater: '天後',
Expand Down
17 changes: 17 additions & 0 deletions ui/src/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {nanoid} from 'nanoid'
import {t} from '@/locales'

/**
* 数字处理
Expand Down Expand Up @@ -85,6 +86,22 @@ export function downloadByURL(url: string, name: string) {
document.body.removeChild(a)
}

// 替换固定数据国际化
const i18n_default_name_map:any = {
"系统管理员": 'layout.about.inner_admin',
"工作空间管理员": 'layout.about.inner_wsm',
"普通用户": 'layout.about.inner_user',
"根目录": 'layout.about.root',
"默认工作空间": 'layout.about.default_workspace',
"默认用户组": 'layout.about.default_user_group',
}

export function i18n_name(name: string) {
const key = i18n_default_name_map[name]
return key ? t(key) : name
}


// 截取文件名
export function cutFilename(filename: string, num: number) {
const lastIndex = filename.lastIndexOf('.')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks mostly correct, but here are some minor suggestions and points to consider:

  1. Whitespace Issues: The code has unnecessary whitespace around imports, after type annotations, comments, and before closing curly braces (}).

  2. Function Naming Convention: Functions should be named using camelCase, such as downloadByUrl, rather than PascalCase.

  3. Error Handling for document.body.removeChild: Adding error handling can prevent crashes if the element is not found unexpectedly (a). You could handle this with a try-catch block or by ensuring that the anchor element exists when calling .removeChild().

  4. Unused Variable: There's a variable name declared in the loop of cutFilename that isn't used anywhere else in the method. Consider removing it.

  5. Optimization: If there's a possibility that filenames might contain many items, ensure that the loop doesn't unnecessarily compute the same index multiple times or modify elements directly within the loop without considering whether they've already been processed.

Here’s the cleaned-up code version incorporating these suggestions:

import nanoid from 'nanoid';
import { t } from '@/locales';

/**
 * Number processing functions
 */
export function downloadByURL(url: string, name?: string) {
  if (!url || !name) return;

  const link = document.createElement('a');
  link.href = url;
  link.download = name!;
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);

  // Cleanup
  setTimeout(() => {
    window.URL.revokeObjectURL(link.download);
  }, 0);
}

// Replace fixed data localization
const i18n_default_name_map = {
  "System Administrator": 'layout.about.inner_admin',
  "Workspace Administrator": 'layout.about.inner_wsm',
  "Normal User": 'layout.about.inner_user',
  "Root Directory": 'layout.about.root',
  "Default Workspace": 'layout.about.default_workspace',
  "Default User Group": 'layout.about.default_user_group',
};

export function i18nName(name: string): string | undefined {
  const key = i18n_default_name_map[name];
  return key ? t(key) : name;
}

function cutFilename(filename: string, num: number): string {
  let lastIndex = filename.lastIndexOf('.');
  while (lastIndex > -1 && --num >= 0) {
    lastIndex = filename.lastIndexOf('.', lastIndex - 1);
  }
  return filename.substr(lastIndex).replace(/[^a-zA-Z0-9_.]/g, '_');
}

These changes enhance readability and potentially make the code more robust and efficient.

Expand Down
5 changes: 3 additions & 2 deletions ui/src/views/application/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
</template>
<template #subTitle>
<el-text class="color-secondary lighter" size="small">
{{ $t('common.creator') }}: {{ item.nick_name }}
{{ $t('common.creator') }}: {{ i18n_name(item.nick_name) }}
</el-text>
</template>
</CardBox>
Expand All @@ -197,7 +197,7 @@
<template #subTitle>
<el-text class="color-secondary lighter" size="small">
<auto-tooltip :content="item.username">
{{ $t('common.creator') }}: {{ item.nick_name }}
{{ $t('common.creator') }}: {{ i18n_name(item.nick_name) }}
</auto-tooltip>
</el-text>
</template>
Expand Down Expand Up @@ -330,6 +330,7 @@ import ApplicationApi from '@/api/application/application'
import { MsgSuccess, MsgConfirm, MsgError } from '@/utils/message'
import useStore from '@/stores'
import { t } from '@/locales'
import { i18n_name } from '@/utils/common'
import { useRouter, useRoute } from 'vue-router'
import { isWorkFlow } from '@/utils/application'
import { resetUrl } from '@/utils/common'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code provided appears to be part of a Vue.js application that uses internationalization (i18n). The changes made include using an i18n_name function instead of directly calling $t('common.creator').toLowerCase().

Analysis:

  1. Template Usage:

    • In both templates, the same string ($t('common.creator')) is being used with the nick name. This means that if "common.creator" changes its translation in the locale files, these strings will need to be updated manually.
  2. Use of auto-tooltip Component:

    • If the intention was to provide tooltips for usernames, then replacing {{ item.nick_name }} with `{{ i18n_name(item.nick_name) }}" would make more sense since tooltips should typically display the translated value.
  3. Functionality Check:

    • Ensure that i18n_name function correctly translates the input text into the desired language, especially considering potential variations across different locales like Chinese and English.
  4. Optimization Suggestions:

    • Consider caching results or lazy-loading translations where appropriate to improve performance, particularly if item.nick_name or other frequently accessed data is expensive to translate.

Overall, the main issue here is the consistency of how localization functions are called, which can lead to mismatches between expected translations and rendered output.

Expand Down
5 changes: 3 additions & 2 deletions ui/src/views/knowledge/component/KnowledgeListContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
</template>
<template #subTitle>
<el-text class="color-secondary lighter" size="small">
{{ $t('common.creator') }}: {{ item.nick_name }}
{{ $t('common.creator') }}: {{ i18n_name(item.nick_name) }}
</el-text>
</template>
</CardBox>
Expand All @@ -190,7 +190,7 @@
</template>
<template #subTitle>
<el-text class="color-secondary lighter" size="small">
{{ $t('common.creator') }}: {{ item.nick_name }}
{{ $t('common.creator') }}: {{ i18n_name(item.nick_name) }}
</el-text>
</template>
<template #tag>
Expand Down Expand Up @@ -361,6 +361,7 @@ import { MsgSuccess, MsgConfirm } from '@/utils/message'
import useStore from '@/stores'
import { numberFormat } from '@/utils/common'
import { t } from '@/locales'
import { i18n_name } from '@/utils/common'
import { SourceTypeEnum } from '@/enums/common'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import permissionMap from '@/permission'
Expand Down
3 changes: 2 additions & 1 deletion ui/src/views/model/component/ModelCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</template>
<template #subTitle>
<el-text class="color-secondary lighter" size="small">
{{ $t('common.creator') }}: {{ model.nick_name }}
{{ $t('common.creator') }}: {{ i18n_name(model.nick_name) }}
</el-text>
</template>
<template #tag>
Expand Down Expand Up @@ -145,6 +145,7 @@ import AuthorizedWorkspace from '@/views/system-shared/AuthorizedWorkspaceDialog
import ResourceAuthorizationDrawer from '@/components/resource-authorization-drawer/index.vue'
import { SourceTypeEnum } from '@/enums/common'
import { t } from '@/locales'
import { i18n_name } from '@/utils/common'
import permissionMap from '@/permission'
import { useRoute } from 'vue-router'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
Expand Down
5 changes: 3 additions & 2 deletions ui/src/views/system-chat-user/group/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
>
<template #default="{ row }">
<div class="flex-between">
<span class="ellipsis" :title="row.name">{{ row.name }}</span>
<span class="ellipsis" :title="row.name">{{ i18n_name(row.name) }}</span>
<div @click.stop v-show="mouseId === row.id">
<el-dropdown
:teleported="false"
Expand Down Expand Up @@ -105,7 +105,7 @@
<!-- 右边 -->
<div class="user-right" v-loading="rightLoading">
<div class="flex align-center">
<h4 class="medium ellipsis" :title="current?.name">{{ current?.name }}</h4>
<h4 class="medium ellipsis" :title="current?.name">{{ i18n_name(current?.name as string) }}</h4>
<el-divider direction="vertical" class="mr-8 ml-8" />
<AppIcon
iconName="app-workspace"
Expand Down Expand Up @@ -269,6 +269,7 @@
import { onMounted, ref, watch, reactive } from 'vue'
import SystemGroupApi from '@/api/system/user-group'
import { t } from '@/locales'
import { i18n_name } from '@/utils/common'
import type { ChatUserGroupUserItem } from '@/api/type/systemChatUser'
import CreateOrUpdateGroupDialog from './component/CreateOrUpdateGroupDialog.vue'
import CreateGroupUserDialog from './component/CreateGroupUserDialog.vue'
Expand Down
5 changes: 3 additions & 2 deletions ui/src/views/system/role/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@mouseleave="mouseId = ''"
>
<template #default="{ row }">
<span class="ellipsis-1" :title="row.role_name">{{ row.role_name }}</span>
<span class="ellipsis-1" :title="row.role_name">{{ i18n_name(row.role_name) }}</span>
</template>
<template #empty>
<span></span>
Expand Down Expand Up @@ -119,7 +119,7 @@
<div class="flex-between mb-16">
<div class="flex align-center">
<h4>
{{ currentRole?.role_name }}
{{ i18n_name(currentRole?.role_name as string) }}
</h4>
<span
v-if="currentRole?.type && !currentRole.internal"
Expand Down Expand Up @@ -155,6 +155,7 @@
<script lang="ts" setup>
import { onMounted, ref, watch } from 'vue'
import { t } from '@/locales'
import { i18n_name } from '@/utils/common'
import PermissionConfiguration from './component/PermissionConfiguration.vue'
import Member from './component/Member.vue'
import CreateOrUpdateRoleDialog from './component/CreateOrUpdateRoleDialog.vue'
Expand Down
5 changes: 3 additions & 2 deletions ui/src/views/system/workspace/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
>
<template #default="{ row }">
<div class="flex-between">
<span class="ellipsis" :title="row.name">{{ row.name }}</span>
<span class="ellipsis" :title="row.name">{{ i18n_name(row.name) }}</span>
<div @click.stop v-show="mouseId === row.id">
<el-dropdown
:teleported="false"
Expand Down Expand Up @@ -87,7 +87,7 @@
<!-- 右边 -->
<div class="workspace-right p-24" v-loading="loading">
<div class="flex align-center mb-16">
<h4 class="medium">{{ currentWorkspace?.name }}</h4>
<h4 class="medium">{{ i18n_name(currentWorkspace?.name as string) }}</h4>
<el-divider direction="vertical" class="mr-8 ml-8" />
<el-icon class="color-input-placeholder"><UserFilled /></el-icon>
<span class="color-input-placeholder ml-4">
Expand All @@ -106,6 +106,7 @@
<script lang="ts" setup>
import { onMounted, ref, watch } from 'vue'
import { t } from '@/locales'
import { i18n_name } from '@/utils/common'
import Member from './component/Member.vue'
import CreateOrUpdateWorkspaceDialog from './component/CreateOrUpdateWorkspaceDialog.vue'
import type { WorkspaceItem } from '@/api/type/workspace'
Expand Down
5 changes: 3 additions & 2 deletions ui/src/views/tool/component/ToolListContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
</template>
<template #subTitle>
<el-text class="color-secondary lighter" size="small">
{{ $t('common.creator') }}: {{ item.nick_name }}
{{ $t('common.creator') }}: {{ i18n_name(item.nick_name) }}
</el-text>
</template>
</CardBox>
Expand Down Expand Up @@ -186,7 +186,7 @@
</template>
<template #subTitle>
<el-text class="color-secondary lighter" size="small">
{{ $t('common.creator') }}: {{ item.nick_name }}
{{ $t('common.creator') }}: {{ i18n_name(item.nick_name) }}
</el-text>
</template>
<template #tag="{ hoverShow }">
Expand Down Expand Up @@ -383,6 +383,7 @@ import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import permissionMap from '@/permission'
import useStore from '@/stores'
import { t } from '@/locales'
import { i18n_name } from '@/utils/common'
import ToolStoreApi from '@/api/tool/store.ts'
import ToolStoreDescDrawer from "@/views/tool/component/ToolStoreDescDrawer.vue";
const route = useRoute()
Expand Down
Loading