Skip to content

Commit

Permalink
feat: 添加自动根据国家切换源
Browse files Browse the repository at this point in the history
  • Loading branch information
fishros committed Sep 4, 2024
1 parent f7488e3 commit 47cf909
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 7 additions & 1 deletion install.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ def main():
importlib.import_module("tools.translation.translator").Linguist()
from tools.base import tr


# 使用量统计
CmdTask("wget https://fishros.org.cn/forum/topic/1733 -O /tmp/t1733 -q && rm -rf /tmp/t1733").run()

PrintUtils.print_success(tr.tr("已为您切换语言至当前所在国家语言:")+tr._currentLocale)
PrintUtils.print_success(tr.tr("已为您切换语言至当前所在国家语言:")+tr.lang)
if tr.country != 'CN':
PrintUtils.print_success(tr.tr("检测到当前不在CN,切换服务地址为:https://raw.githubusercontent.com/fishros/install/master/"))
url_prefix = 'https://raw.githubusercontent.com/fishros/install/master/'


# check base config
if not encoding_utf8:
print("Your system encoding not support ,will install some packgaes..")
Expand Down
2 changes: 0 additions & 2 deletions tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,4 @@ def download_tools(id,tools,url_prefix):
url = os.path.join(url_prefix,url)
CmdTask("wget {} -O /tmp/fishinstall/tools/{} --no-check-certificate".format(url,url[url.rfind('/')+1:])).run()



osarch = AptUtils.getArch()
8 changes: 5 additions & 3 deletions tools/translation/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
from tools.base import CmdTask

_suported_languages = ['zh_CN', 'en_US']
url_prefix = os.environ.get('FISHROS_URL','http://mirror.fishros.com/install')+'/'
lang_url = url_prefix+'tools/translation/assets/{}.py'

url_prefix = os.environ.get('FISHROS_URL','http://mirror.fishros.com/install')
lang_url = os.path.join(url_prefix,'tools/translation/assets/{}.py')

COUNTRY_CODE_MAPPING = {
"CN": "zh_CN",
Expand All @@ -29,6 +28,8 @@ def __init__(self):
if self._currentLocale is None:
self._currentLocale = locale.getdefaultlocale()[0]
# Load the translation file.
self.country = 'CN'
self.lang = self._currentLocale
for lang in _suported_languages:
CmdTask("wget {} -O /tmp/fishinstall/{} --no-check-certificate".format(lang_url.format(lang),lang_url.format(lang).replace(url_prefix,''))).run()

Expand Down Expand Up @@ -61,6 +62,7 @@ def getLocalFromIP(self) -> str:
with open('/tmp/fishros_check_country.json', 'r') as json_file:
data = json.loads(json_file.read())
self.ip_info = data
self.country = data['location']['countryCode']
if data['location']['countryCode'] in COUNTRY_CODE_MAPPING:
local_str = COUNTRY_CODE_MAPPING[data['location']['countryCode']]
else:
Expand Down

0 comments on commit 47cf909

Please sign in to comment.