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

feat: 自动切换语言。 #43

Merged
merged 1 commit into from
Jun 13, 2019
Merged

feat: 自动切换语言。 #43

merged 1 commit into from
Jun 13, 2019

Conversation

Jeff-Tian
Copy link
Contributor

问题
目前 egg 文档总是默认显示英文,作为一个中文用户,每次打开都需要多做一次额外的切换语言动作。

解决方案
可以给在线文档添加一个自动判断用户语言的功能。

分析

  • 看了一下代码,似乎需要由 hexo 来完成这件事情(在 page.lang 初始化时读取客户端语言设置)。但是 hexo 似乎在 egg 框架之外,不好控制。
  • 而且 eggjs 的文档 host 在 github 的 gh-pages 上,为静态页面,可能服务端做的会不生效。

退而求其次
仅在 / 路径下用客户端 js 来判断,如果当前页面渲染所使用的语言与用户的设置不一致,就做一个跳转。一旦用户点击过语言切换,就记录在 localStorage 里,下次还会使用他上次切换到的语言。

测试
在本地 eggjs 项目下 通过 npm run doc-server 尝试,效果达到预期。跳转得很快,用户几乎无感知。

@fengmk2
Copy link
Member

fengmk2 commented Mar 11, 2019 via email

@Jeff-Tian Jeff-Tian mentioned this pull request Mar 11, 2019
5 tasks
@atian25 atian25 requested a review from whxaxes March 11, 2019 07:11
@whxaxes
Copy link
Member

whxaxes commented Mar 21, 2019

ci 挂了,修一下?

@codecov
Copy link

codecov bot commented Mar 22, 2019

Codecov Report

Merging #43 into master will decrease coverage by 2.55%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #43      +/-   ##
==========================================
- Coverage   88.21%   85.65%   -2.56%     
==========================================
  Files          10       10              
  Lines         509      509              
==========================================
- Hits          449      436      -13     
- Misses         60       73      +13
Impacted Files Coverage Δ
lib/cmd/deploy.js 39.13% <0%> (-56.53%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6436643...00a896c. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 22, 2019

Codecov Report

Merging #43 into master will decrease coverage by 2.1%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #43      +/-   ##
==========================================
- Coverage   87.79%   85.68%   -2.11%     
==========================================
  Files          10       10              
  Lines         516      510       -6     
==========================================
- Hits          453      437      -16     
- Misses         63       73      +10
Impacted Files Coverage Δ
lib/cmd/deploy.js 39.13% <0%> (-52.18%) ⬇️
lib/base.js 97.39% <0%> (+1.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef494d9...c8fd2d9. Read the comment docs.

@Jeff-Tian
Copy link
Contributor Author

@whxaxes 一共有三个 test 失败,都不是这个改动引起。
其中两个 build.test 的,通过添加了两个占位文件已经修复了。
另外一个 deploy.test,是超时错误,我尝试延长了等待时间,仍然报超时。感觉需要在本地调研一下,但是在我本地,会报没有权限读取远程仓库的错误,还需要请大佬协助一下解决 。

@Jeff-Tian
Copy link
Contributor Author

Jeff-Tian commented Mar 22, 2019

本地想重现这个 timeout,但是在跑到这一步时,报

    deploy
Cloning into 'doctools'...
Load key "/Users/jefftian/doctools/deploy_key": invalid format
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

机器是 macOS

@whxaxes
Copy link
Member

whxaxes commented Apr 2, 2019

@Jeff-Tian 好,我这边看看

@ghost
Copy link

ghost commented Apr 23, 2019

Got the same problem

@Jeff-Tian
Copy link
Contributor Author

@whxaxes 我今天又看了一下这个错误,原来 deploy_key 是个空文件,所以本地跑的时候会报 invalid format。

在 .travis 上失败,不知道是不是相应的 secure 过期了(一般生成的 secure 默认一年),需要更新?

本地想重现这个 timeout,但是在跑到这一步时,报

    deploy
Cloning into 'doctools'...
Load key "/Users/jefftian/doctools/deploy_key": invalid format
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

机器是 macOS

@atian25 atian25 requested a review from thonatos June 6, 2019 00:46
@thonatos
Copy link
Member

Rebase 一下再看.

Copy link
Member

@thonatos thonatos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最后一步过不了是因为没权限,commit & rebase master ,改完我直接合并。

test/fixtures/error/docs/theme/.gitignore Outdated Show resolved Hide resolved
lib/themes/egg/layout/partial/aside.nunjucks Show resolved Hide resolved
test/fixtures/framework-external/docs/theme/.gitignore Outdated Show resolved Hide resolved
@thonatos thonatos merged commit 82072a8 into eggjs:master Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants