fishros / install

一键安装程序,欢迎大家提交代码和小鱼一起一键安装停止浪费生命
https://fishros.github.io/install/
1.37k stars 187 forks source link

feat: Add translation support 添加基本翻译支持 #68

Closed ganyuanzhen closed 3 days ago

ganyuanzhen commented 1 month ago

翻译框架初步

本PR为一键安装提供了基本的翻译支持,基本效果如下: image

基本原理

受到 Qt 的启发,编写了一个工具类,将需要添加国际化支持的字符串传递给翻译类,其会自动查找是否有对应的翻译文本,并返回对应的翻译。如果没有,则会原样返回原始文本。

翻译文件按照LANG变量(类似en_US,zh_CN,etc.)进行存储。

基本使用

import importlib
tr = importlib.import_module("tools.translation.translator").Linguist()

print(tr.tr("我需要被翻译"))
ganyuanzhen commented 1 month ago

剩余文本可以在之后由大家合力pr补齐:)

ganyuanzhen commented 1 month ago

@fishros CC. 这个思路感觉还行叭(

fishros commented 1 month ago

@fishros CC. 这个思路感觉还行叭(

刚看到,很不错,我试试看有没有bug

ganyuanzhen commented 4 weeks ago

@fishros CC. 这个思路感觉还行叭(

刚看到,很不错,我试试看有没有bug

有什么问题没有(●ˇ∀ˇ●)

fishros commented 2 weeks ago

@fishros CC. 这个思路感觉还行叭(

刚看到,很不错,我试试看有没有bug

有什么问题没有(●ˇ∀ˇ●)

技术上没问题,主要考虑是什么时候用英文,什么时候用中文,是根据用户环境选还是让用户选语言

ganyuanzhen commented 2 weeks ago

ok,这个脚本里面是读取的终端的locale信息来判断的。

fishros commented 2 weeks ago

ok,这个脚本里面是读取的终端的locale信息来判断的。

担心的是很多国内用户它其实装虚拟机的时候语言没选对,其实是需要中文的,一起想想有没有更好的策略了

fishros commented 2 weeks ago

可以可以搞成自动ip归属国内还是国外来判断:https://api.vore.top/api/IPdata 有很多这种api https://ip.useragentinfo.com/json

ganyuanzhen commented 2 weeks ago

ok,回去看看相关的接口。

ganyuanzhen commented 1 week ago

添加了ip检测: 现在会从ip接口检测国家地区代码,如果检测失败或者不在翻译列表中,会使用英语作为回退选项 @fishros

fishros commented 3 days ago

我来测试一下

ganyuanzhen commented 3 days ago

ok在这里回复一下,requests已经添加到install的脚本里面: image 至于Warning是我关闭了https校验,因为不知道客户机上有无最新的https证书库。

ganyuanzhen commented 3 days ago

我改成http吧

fishros commented 3 days ago

考虑到安装requests库可能会引入新的bug,尝试用wget替换是否可以

wget --header="Accept: application/json" --no-check-certificate -O - "https://ip.renfei.net/"
fishros commented 3 days ago

wget --header="Accept: application/json" --no-check-certificate "https://ip.renfei.ne t/" -O /tmp/country 先输出到文件,然后再读取解析

ganyuanzhen commented 3 days ago

wget --header="Accept: application/json" --no-check-certificate "https://ip.renfei.ne t/" -O /tmp/country 先输出到文件,然后再读取解析

OK 修改了

ganyuanzhen commented 3 days ago

wget --header="Accept: application/json" --no-check-certificate "https://ip.renfei.ne t/" -O /tmp/country 先输出到文件,然后再读取解析

OK 修改了

还差一下()

fishros commented 3 days ago

好滴,我收拾下就给合并了

ganyuanzhen commented 3 days ago

好滴,我收拾下就给合并了

ok