mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-06 01:40:52 +00:00
perf: 优化英文下树的显示 (#7883)
* perf: 优化英文下树的显示 * perf: 修改翻译 * perf: 修改翻译 Co-authored-by: ibuler <ibuler@qq.com>
This commit is contained in:
@@ -2,11 +2,10 @@
|
||||
from collections import defaultdict
|
||||
from typing import Callable
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from django.utils.translation import gettext_lazy as _, gettext, get_language
|
||||
from django.conf import settings
|
||||
from django.apps import apps
|
||||
from django.db.models import F, Count
|
||||
from django.utils.translation import ugettext
|
||||
|
||||
from common.tree import TreeNode
|
||||
from .models import Permission, ContentType
|
||||
@@ -155,10 +154,10 @@ def sort_nodes(node):
|
||||
class PermissionTreeUtil:
|
||||
get_permissions: Callable
|
||||
action_mapper = {
|
||||
'add': ugettext('Create'),
|
||||
'view': ugettext('View'),
|
||||
'change': ugettext('Update'),
|
||||
'delete': ugettext('Delete')
|
||||
'add': _('Create'),
|
||||
'view': _('View'),
|
||||
'change': _('Update'),
|
||||
'delete': _('Delete')
|
||||
}
|
||||
action_icon = {
|
||||
'add': 'add',
|
||||
@@ -178,6 +177,7 @@ class PermissionTreeUtil:
|
||||
self.check_disabled = check_disabled
|
||||
self.total_counts = defaultdict(int)
|
||||
self.checked_counts = defaultdict(int)
|
||||
self.lang = get_language()
|
||||
|
||||
@staticmethod
|
||||
def prefetch_permissions(perms):
|
||||
@@ -288,12 +288,18 @@ class PermissionTreeUtil:
|
||||
return name, icon
|
||||
|
||||
app_model = '%s.%s' % (p.content_type.app_label, resource)
|
||||
if action in self.action_mapper and app_model in content_types_name_mapper:
|
||||
if self.lang == 'en':
|
||||
name = p.name
|
||||
# 因为默认的权限位是没有翻译的,所以我们要用 action + resource name 去拼
|
||||
elif action in self.action_mapper and app_model in content_types_name_mapper:
|
||||
action_name = self.action_mapper[action]
|
||||
name = action_name + content_types_name_mapper[app_model]
|
||||
resource_name = content_types_name_mapper[app_model]
|
||||
sep = ''
|
||||
name = '{}{}{}'.format(action_name, sep, resource_name)
|
||||
# 手动创建的 permission
|
||||
else:
|
||||
name = gettext(p.name)
|
||||
name = name.replace('Can ', '').replace('可以', '')
|
||||
name = name.replace('Can ', '').replace('可以', '').capitalize()
|
||||
return name, icon
|
||||
|
||||
def _create_perms_nodes(self):
|
||||
|
Reference in New Issue
Block a user