angular / angular-cn

Chinese localization of angular.io
MIT License
756 stars 426 forks source link

查看原文 #331

Closed sangeren closed 5 years ago

sangeren commented 6 years ago

我看了“关于中文版”,发现点击可以查看原文, 想问下这个是怎么实现的谢谢了!

asnowwolf commented 6 years ago

所有文字内容都可以这样,不仅是关于中文版这里。

原理很简单:在编译 markdown 时把中英文对调并标上 translation-result 和 translation-origin 属性,用 css 隐藏 translation-origin。当用户点击 result 时就找到相应的 origin ,并显示它。

其实现代码都在 aio 分支下。代码可能也就一两百行吧。

asnowwolf commented 5 years ago

另外,如果你的是 gitbook 书籍,可以使用 gitbook-plugin-translator,那是抽出的对照翻译核心。