-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Translate fixed name #4169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import {nanoid} from 'nanoid' | ||
| import {t} from '@/locales' | ||
|
|
||
| /** | ||
| * 数字处理 | ||
|
|
@@ -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('.') | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
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. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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> | ||
|
|
@@ -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> | ||
|
|
@@ -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' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Analysis:
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. |
||
|
|
||
There was a problem hiding this comment.
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.