Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser Clipping Extension supports multiple languages #13559

Closed
ruin1990 opened this issue Dec 20, 2024 · 7 comments
Closed

Browser Clipping Extension supports multiple languages #13559

ruin1990 opened this issue Dec 20, 2024 · 7 comments
Assignees
Milestone

Comments

@ruin1990
Copy link

ruin1990 commented Dec 20, 2024

chrome插件添加多国语言支持框架

In what scenarios do you need this feature?

想着是不是可以对提示信息、设置及剪报界面做国际化处理,现在应该是全英文的

Describe the optimal solution

我目前是想着一个国家语言一个json,对于静态网页,默认还是英语,然后在load完成后加载对应的json用js给替换掉文字
对于动态弹出的一些提示信息,动态获取对应字符串代替静态的字符串。
所有json文件丢在locales底下以[langCode].json命名
设置里追加一个当前语言的设置,遇到不支持的语言就直接换英语

Describe the candidate solution

一样的做法,但是优先先把主界面静态内容给翻译了,一些popup的代码内字符串就延后处理

Other information

No response

@88250
Copy link
Member

88250 commented Dec 20, 2024

嗯,可以考虑使用浏览器语言来选择默认语言(比如从 User Agent 读取,或者从某个前端 API 获取默认语言)。

欢迎 PR。

@TCOTC
Copy link
Contributor

TCOTC commented Dec 20, 2024

https://developer.chrome.com/docs/extensions/reference/api/i18n?hl=zh-cn

@ruin1990
Copy link
Author

嗯,可以考虑使用浏览器语言来选择默认语言(比如从 User Agent 读取,或者从某个前端 API 获取默认语言)。

欢迎 PR。

嗯,那我这周改一个看看,确实是需要判断下浏览器的默认语言

@ruin1990
Copy link
Author

ruin1990 commented Dec 23, 2024

https://developer.chrome.com/docs/extensions/reference/api/i18n?hl=zh-cn

这个方法我研究了一下有个缺点,用户无法配置和浏览器语言不同的语言配置,准备整体结构参考这个,但是加载字符串的函数要重新封装一下

研究了一下,发现会遇到跨域问题,还是乖乖的就不让用户选择语言,直接跟着浏览器语言走吧?@88250 @TotoC
剪藏到background.js的时候如果调用动态加载json去解析就会报下面的错(看代码是消息发给tab传会content.js注册的函数)
怎么不用本地的json直接跳转到了developer.chrome.com

 GET https://developer.chrome.com/docs/extensions/reference/api/_locales/zh_CN/strings.json 404 (Not Found)
siyuanLoadLanguageFile @ content.js:551
(匿名) @ content.js:497
(匿名) @ content.js:489
显示另外 3 个框架
收起
content.js:567 There was a problem with the fetch operation: Error: Network response was not ok
    at siyuanLoadLanguageFile (content.js:553:19)

另外对于右键菜单copy to siyuan,发现chrome.i18n.getMessage("messagename")有点问题,有时候有报错,不过我重启浏览器以后没出现了

@88250
Copy link
Member

88250 commented Dec 25, 2024

我这里暂时没有时间看细节……感觉应该可以不用 HTTP 请求吧,直接加载插件中的文件?

@ruin1990
Copy link
Author

ruin1990 commented Dec 25, 2024

我这里暂时没有时间看细节……感觉应该可以不用 HTTP 请求吧,直接加载插件中的文件?

嗯,我再研究一下。直接加载的时候有时候popup.js会找不到对应的函数,感觉可能和加载顺序有关。所以尝试换fetch方法,但是本地域跳转到了别人网站去了。因为我测试剪藏的页面其实就是TOTOC发的这个:

https://developer.chrome.com/docs/extensions/reference/api/i18n?hl=zh-cn

准备先做成这样:选择语言目前只能先把option.html给翻译了,tip弹出框里的内容暂时先跟着浏览器走的。

另外我准备把语言选择设置也加入到实验性功能里(如果能选的话)
image

ruin1990 added a commit to ruin1990/siyuan-chrome that referenced this issue Dec 26, 2024
@88250 88250 changed the title chrome插件添加多国语言支持框架 Browser Clipping Extension supports multiple languages Dec 26, 2024
@88250 88250 added this to the 3.1.18 milestone Dec 26, 2024
88250 pushed a commit to siyuan-note/siyuan-chrome that referenced this issue Dec 26, 2024
@88250
Copy link
Member

88250 commented Dec 26, 2024

感谢贡献 siyuan-note/siyuan-chrome#14

@88250 88250 closed this as completed Dec 26, 2024
88250 added a commit to siyuan-note/siyuan-chrome that referenced this issue Dec 26, 2024
88250 added a commit to siyuan-note/siyuan-chrome that referenced this issue Dec 26, 2024
88250 added a commit to siyuan-note/siyuan-chrome that referenced this issue Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants