-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters