mirror of https://github.com/jumpserver/jumpserver
Merge pull request #10267 from jumpserver/pr@dev@perf_yaml_support_i18n
perf: yaml 文件支持 i18npull/10273/head
commit
8e61dc8e02
|
@ -1,7 +1,15 @@
|
||||||
id: gather_accounts_mysql
|
id: gather_accounts_mysql
|
||||||
name: Gather account from MySQL
|
name: "{{ 'Gather account from MySQL' | trans }}"
|
||||||
category: database
|
category: database
|
||||||
type:
|
type:
|
||||||
- mysql
|
- mysql
|
||||||
- mariadb
|
- mariadb
|
||||||
method: gather_accounts
|
method: gather_accounts
|
||||||
|
|
||||||
|
i18n:
|
||||||
|
en:
|
||||||
|
Gather account from MySQL: Gather account from MySQL
|
||||||
|
zh:
|
||||||
|
Gather account from MySQL: 从MySQL获取账号
|
||||||
|
ja:
|
||||||
|
Gather account from MySQL: MySQLからアカウントを取得する
|
||||||
|
|
|
@ -2,7 +2,7 @@ import json
|
||||||
import os
|
import os
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import yaml
|
from common.utils.yml import yaml_load_with_i18n
|
||||||
|
|
||||||
|
|
||||||
def check_platform_method(manifest, manifest_path):
|
def check_platform_method(manifest, manifest_path):
|
||||||
|
@ -40,7 +40,8 @@ def get_platform_automation_methods(path):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
manifest = yaml.safe_load(f)
|
print("path: ", path)
|
||||||
|
manifest = yaml_load_with_i18n(f)
|
||||||
check_platform_method(manifest, path)
|
check_platform_method(manifest, path)
|
||||||
manifest['dir'] = os.path.dirname(path)
|
manifest['dir'] = os.path.dirname(path)
|
||||||
manifest['params_serializer'] = generate_serializer(manifest)
|
manifest['params_serializer'] = generate_serializer(manifest)
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
id: posix_ping
|
id: posix_ping
|
||||||
name: Posix ping
|
name: "{{ 'Posix ping' | trans }}"
|
||||||
category: host
|
category: host
|
||||||
type:
|
type:
|
||||||
- linux
|
- linux
|
||||||
- unix
|
- unix
|
||||||
method: ping
|
method: ping
|
||||||
|
|
||||||
|
i18n:
|
||||||
|
Posix ping:
|
||||||
|
zh: Posix ping
|
||||||
|
en: Posix ping
|
||||||
|
ja: Posix ピング
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
import io
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
from django.utils.translation import get_language
|
||||||
|
from jinja2 import Environment
|
||||||
|
|
||||||
|
|
||||||
|
def translate(i18n, key):
|
||||||
|
lang = get_language()[:2]
|
||||||
|
lang_data = i18n.get(key, {})
|
||||||
|
return lang_data.get(lang, key)
|
||||||
|
|
||||||
|
|
||||||
|
def yaml_load_with_i18n(stream):
|
||||||
|
ori_text = stream.read()
|
||||||
|
stream = io.StringIO(ori_text)
|
||||||
|
yaml_data = yaml.safe_load(stream)
|
||||||
|
i18n = yaml_data.get('i18n', {})
|
||||||
|
|
||||||
|
env = Environment()
|
||||||
|
env.filters['trans'] = lambda key: translate(i18n, key)
|
||||||
|
template = env.from_string(ori_text)
|
||||||
|
yaml_data = template.render()
|
||||||
|
yaml_f = io.StringIO(yaml_data)
|
||||||
|
d = yaml.safe_load(yaml_f)
|
||||||
|
if isinstance(d, dict):
|
||||||
|
d.pop('i18n', None)
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
with open('manifest.yml') as f:
|
||||||
|
data = yaml_load_with_i18n(f)
|
||||||
|
print(data)
|
|
@ -1,4 +0,0 @@
|
||||||
- zh:
|
|
||||||
display_name: Chrome 浏览器
|
|
||||||
comment: 浏览器打开 URL 页面地址
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
name: chrome
|
name: chrome
|
||||||
display_name: Chrome Browser
|
display_name: "{{ 'Chrome Browser' | trans }}"
|
||||||
version: 0.2
|
version: 0.2
|
||||||
comment: Chrome Browser Open URL Page Address
|
comment: "{{ 'Chrome Browser Open URL Page Address' | trans }}"
|
||||||
author: JumpServer Team
|
author: JumpServer Team
|
||||||
exec_type: python
|
exec_type: python
|
||||||
update_policy: always
|
update_policy: always
|
||||||
|
@ -10,3 +10,13 @@ tags:
|
||||||
- web
|
- web
|
||||||
protocols:
|
protocols:
|
||||||
- http
|
- http
|
||||||
|
|
||||||
|
i18n:
|
||||||
|
Chrome Browser:
|
||||||
|
en: Chrome Browser
|
||||||
|
zh: Chrome 浏览器
|
||||||
|
ja: Chrome ブラウザ
|
||||||
|
Chrome Browser Open URL Page Address:
|
||||||
|
en: Chrome Browser Open URL Page Address
|
||||||
|
zh: Chrome 浏览器打开网页地址
|
||||||
|
ja: Chrome ブラウザでウェブページを開く
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
- zh:
|
|
||||||
display_name: DBeaver Community
|
|
||||||
comment: 免费的多平台数据库工具,供开发人员、数据库管理员、分析师和所有需要使用数据库的人使用。
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: dbeaver
|
name: dbeaver
|
||||||
display_name: DBeaver Community
|
display_name: "{{ 'DBeaver Community' | trans }}"
|
||||||
comment: Free multi-platform database tool for developers, database administrators, analysts and all people who need to work with databases.
|
comment: "{{ 'Free multi-platform database tool for developers, database administrators, analysts and all people who need to work with databases.' | trans }}"
|
||||||
version: 0.1
|
version: 0.1
|
||||||
exec_type: python
|
exec_type: python
|
||||||
author: JumpServer Team
|
author: JumpServer Team
|
||||||
|
@ -14,3 +14,14 @@ protocols:
|
||||||
- postgresql
|
- postgresql
|
||||||
- sqlserver
|
- sqlserver
|
||||||
- oracle
|
- oracle
|
||||||
|
|
||||||
|
i18n:
|
||||||
|
DBeaver Community:
|
||||||
|
en: DBeaver Community
|
||||||
|
zh: DBeaver 社区版
|
||||||
|
ja: DBeaver コミュニティ
|
||||||
|
|
||||||
|
Free multi-platform database tool for developers, database administrators, analysts and all people who need to work with databases.:
|
||||||
|
en: Free multi-platform database tool for developers, database administrators, analysts and all people who need to work with databases.
|
||||||
|
zh: 免费的多平台数据库工具,供开发人员、数据库管理员、分析师和所有需要使用数据库的人使用。
|
||||||
|
ja: 開発者、データベース管理者、分析家、およびデータベースを使用する必要があるすべての人のための無料のマルチプラットフォームデータベースツール。
|
||||||
|
|
|
@ -12,6 +12,7 @@ from rest_framework.serializers import ValidationError
|
||||||
|
|
||||||
from common.db.models import JMSBaseModel
|
from common.db.models import JMSBaseModel
|
||||||
from common.utils import lazyproperty, get_logger
|
from common.utils import lazyproperty, get_logger
|
||||||
|
from common.utils.yml import yaml_load_with_i18n
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
@ -76,14 +77,14 @@ class Applet(JMSBaseModel):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_pkg(d):
|
def validate_pkg(d):
|
||||||
files = ['manifest.yml', 'icon.png', 'i18n.yml', 'setup.yml']
|
files = ['manifest.yml', 'icon.png', 'setup.yml']
|
||||||
for name in files:
|
for name in files:
|
||||||
path = os.path.join(d, name)
|
path = os.path.join(d, name)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
raise ValidationError({'error': _('Applet pkg not valid, Missing file {}').format(name)})
|
raise ValidationError({'error': _('Applet pkg not valid, Missing file {}').format(name)})
|
||||||
|
|
||||||
with open(os.path.join(d, 'manifest.yml')) as f:
|
with open(os.path.join(d, 'manifest.yml')) as f:
|
||||||
manifest = yaml.safe_load(f)
|
manifest = yaml_load_with_i18n(f)
|
||||||
|
|
||||||
if not manifest.get('name', ''):
|
if not manifest.get('name', ''):
|
||||||
raise ValidationError({'error': 'Missing name in manifest.yml'})
|
raise ValidationError({'error': 'Missing name in manifest.yml'})
|
||||||
|
|
Loading…
Reference in New Issue