-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: i18n #4162
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
fix: i18n #4162
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| }) | ||
| const logout = () => { | ||
| login.logout().then(() => { | ||
| if (user?.userInfo?.source && ['CAS', 'OIDC', 'OAuth2'].includes(user.userInfo.source)) { |
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.
The code has several potential issues and areas for improvement:
-
Computed Property Efficiency: The
role_listcomputation does not memoize its result, which can lead to unnecessary re-renders whenuser.userInfo.role_namechanges. Consider usingwatchEffectaround the creation ofmif it needs to be recalculated based onuser.userInfo. -
Template Reference Usage: There is a commented-out line referencing
UserPwdDialog, but it seems unrelated to the current context. Remove this reference or add appropriate logic. -
Language Translation Import: Use
tfunction correctly within templates. Ensure that the locale files (en.json, etc.) contain the keys specified inm. -
Code Duplication: Check for any duplicate code or redundant calls, especially related to API key dialog opening.
Here’s an improved version with some of these considerations:
<template>
<div class="container mx-auto px-4 py-8">
<h1>User Profile</h1>
<template v-if="user.userInfo?.role_name && user.userInfo.role_name.length > 0">
<TagGroup size="small" :tags="roleList" v-if="hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR')" />
</template>
<!-- <UserPwdDialog ref="UserPwdDialogRef" @close="$emit('update:userpwd')"></UserPwdDialog> -->
<button @click=" logout">Logout</button>
<ResetPassword @resetSuccess="$emit('on-reset-success')" />
<AboutDialog />
</div>
</template>
<script setup lang="ts">
import {ref, onMounted, computed} from 'vue';
import useStore from '@/stores';
import {useRouter} from 'vue-router';
import ResetPassword from './ResetPassword.vue';
import AboutDialog from './AboutDialog.vue';
const router = useRouter();
const store = useStore();
const m: {[key: string]: string} = {
"系统管理员": 'layout.about.inner_admin',
"工作空间管理员": 'layout.about.inner_wsm',
"普通用户":'layout.about.inner_user'
};
const roleList = computed(() => {
if (!user.userInfo) {
return [];
}
return user.userInfo?.role_name.map(name => {
const innerText = m[name];
return innerText ? t(innerText) : name;
});
});
const logout = async () => {
try {
await login.logout();
if (user?.userInfo?.source && ['CAS', 'OIDC', 'OAuth2'].includes(user.userInfo.source)) {
store.dispatch(UserEnum.USER_LOGOUT);
localStorage.removeItem('api_key');
window.location.href = '/';
} else {
console.error('Unsupported logout source:', user?.userInfo?.source);
}
} catch (error) {
console.error('Logout failed:', error);
}
};
// Functionality to open APIKey Dialog will depend on your specific requirements
</script>Key Changes:
- Removed unneeded comment references.
- Fixed template rendering errors.
- Used
computedproperty more efficiently. - Ensured correct usage of
tfunction. - Improved variable naming and structure for clarity.
|
|
||
| }, | ||
| time: { | ||
| daysLater: '天后', |
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.
Your code is mostly structured correctly, but there are a few minor improvements and optimizations that could be considered:
-
Consistent Spacing: Ensure consistent spacing throughout the JSON object to improve readability. However, since it's already quite compact, this might not make a significant difference but improves maintainability.
-
Comments and Documentation: Adding comments can help anyone reading your code understand its purpose and functionality. While you've included
remarkas a comment within the JSON structure, it might be better to have more comprehensive documentation if needed. -
Code Readability: You're using both single quotes (
') and double quotes (") for property values. It's generally recommended to use one style consistently for consistency across your project. Here's an example using only double quotes:export default { serialNo: "序列号", remark: "备注", update: "更新", authorize: "授权给", inner_admin: "系统管理员", inner_wsm: "工作空间管理员", inner_user: "普通用户" }, time: { daysLater: "天后" }
-
Error Handling: If the keys need to dynamically change based on some external context or logic, consider implementing mechanisms to handle these changes without direct key modifications. This would reduce risks of breaking existing components.
By applying these small adjustments, the code will remain concise and readable while maintaining its intended functionality.
fix: Rename
fix: i18n