Skip to content

Commit

Permalink
新增 部分的英文界面支持
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Aug 4, 2023
1 parent 33dcf6d commit 88d38c3
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ Domain Admin是一个轻量级监控方案,占用系统资源较少。同时
- 辅助功能:Let’s Encrypt SSL证书申请

- 项目地址:
- github: [https://github.com/mouday/domain-admin](https://github.com/mouday/domain-admin)
- 国内镜像:[https://gitee.com/mouday/domain-admin](https://gitee.com/mouday/domain-admin)
- 后端代码(github): [https://github.com/mouday/domain-admin](https://github.com/mouday/domain-admin)
- 后端代码(国内镜像):[https://gitee.com/mouday/domain-admin](https://gitee.com/mouday/domain-admin)
- 前端代码:[https://github.com/mouday/domain-admin-web](https://github.com/mouday/domain-admin-web)
- H5端代码:[https://github.com/mouday/domain-admin-mini](https://github.com/mouday/domain-admin-mini)

- 发布渠道:
- pypi:[https://pypi.org/project/domain-admin](https://pypi.org/project/domain-admin)
Expand Down
3 changes: 3 additions & 0 deletions domain_admin/config/default_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# header请求头中携带 token 参数名称
TOKEN_KEY = 'X-Token'

# header请求头中携带 language 参数名称
LANGUAGE_KEY = 'X-Language'

# 默认的token有效时长 单位:天
DEFAULT_TOKEN_EXPIRE_DAYS = 7

Expand Down
6 changes: 6 additions & 0 deletions domain_admin/i18n/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
"""
@File : __init__.py
@Date : 2023-08-04
"""
from .main import translate
28 changes: 28 additions & 0 deletions domain_admin/i18n/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
"""
@File : config.py
@Date : 2023-08-04
"""
translate_config = [
{
'zh-CN': '简体中文',
'en-US': 'English',
},
{
'zh-CN': '刚刚',
'en-US': 'now',
},
{
'zh-CN': '分钟前',
'en-US': ' minutes ago',
},
{
'zh-CN': '小时前',
'en-US': ' hours ago',
},
{
'zh-CN': '天前',
'en-US': ' days ago',
},

]
28 changes: 28 additions & 0 deletions domain_admin/i18n/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
"""
@File : main.py
@Date : 2023-08-04
"""
from flask import request

from domain_admin.config import LANGUAGE_KEY
from domain_admin.i18n.config import translate_config

translate_map = {}

for item in translate_config:
translate_map[item['zh-CN']] = item


def translate(text):
language = 'zh-CN'

try:
language = request.headers.get(LANGUAGE_KEY)
except Exception as e:
pass

if text in translate_map:
return translate_map[text].get(language) or text
else:
return text
9 changes: 5 additions & 4 deletions domain_admin/utils/datetime_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from datetime import datetime
import math
import six
from domain_admin import i18n

DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"

Expand Down Expand Up @@ -135,13 +136,13 @@ def time_for_human(time_value):
duration = now_time - time_value

if duration < minute:
return '刚刚'
return i18n.translate('刚刚')
elif duration < hour:
return six.text_type(int(duration / minute)) + '分钟前'
return six.text_type(int(duration / minute)) + i18n.translate('分钟前')
elif duration < day:
return six.text_type(int(duration / hour)) + '小时前'
return six.text_type(int(duration / hour)) + i18n.translate('小时前')
elif duration < day_8:
return six.text_type(int(duration / day)) + '天前'
return six.text_type(int(duration / day)) + i18n.translate('天前')
else:
return time.strftime(DATE_FORMAT, time.localtime(time_value))

Expand Down

0 comments on commit 88d38c3

Please sign in to comment.