nk2028 / opencc-js Goto Github PK
View Code? Open in Web Editor NEWThe JavaScript version of Open Chinese Convert (OpenCC)
Home Page: https://www.npmjs.com/package/opencc-js
License: MIT License
The JavaScript version of Open Chinese Convert (OpenCC)
Home Page: https://www.npmjs.com/package/opencc-js
License: MIT License
Hello, I created a jsffidle to test few usecases from your readme.md. I was partially successful.
The convert page content script didn't work :
((async () => {
const convert = await OpenCC.Converter('hk', 'cn');
const startNode = document.documentElement; // Convert the whole page
const HTMLConvertHandler = OpenCC.HTMLConverter(convert, startNode, 'zh-HK', 'zh-CN'); // Convert all zh-HK to zh-CN
HTMLConvertHandler.convert(); // Start conversion
HTMLConvertHandler.restore(); // Restore
})());
I tried to assign to variable but also failed. (but this one is likely on me since I don't understand asyn well).
It could be interesting for users to have some usecases working on fiddle as demos.
Hello.If I have been translated from SIMPLIFIED to TRADITIONAL, then my new input content will not be traditional. Is there any way to solve this problem?
预置的 HTMLConverter
无法处理下面这种“简繁转换菜单”的情况:
<html lang="zh-hans">
...
<a href="javascript:void(0)" lang="zh-hans" onclick="setConvert(false)">简体</a>
<a href="javascript:void(0)" lang="zh-hant" onclick="setConvert(true)">繁體</a>
...
</html>
常见的 UX 设计方案当中,这种“简繁转换菜单”中菜单项使用的文字应该和对应的变体一致,但是转换器(在这个示例中是简体转繁体)会将“简体”一项也转换成繁体。
我个人的解决方法是在 _inner
函数中原有的跳过内嵌 JS / CSS 处加入一个类名检测:
/* Do not convert these elements */
if (currentNode.nodeType == Node.ELEMENT_NODE && currentNode.classList.contains('ignore-opencc')) return;
...
此时转换器检测到带有 ignore-opencc
类的元素就会跳过后续的转换,在网页中只需要加入同样的类名即可指定无需转换的部分。
不过,因为本人的能力实在有限,不知道这样的解决方法效率如何(毕竟把所有元素都 DFS 一遍还要检测类名觉得时间复杂度有点大),并且也不太会用 PR,就先发 Issue 了。
The .HTMLConverter
API works perfectly for text nodes, but it would be even nicer if it could also convert attributes like placeholder
, aria-label
etc.
Thanks.
Sample files - testpages.zip
During my test, v0.3.6 and v0.3.7 took less than 100ms to finish the translation, while v1.0.0 and v1.0.1 took about 5 seconds.
For longer contents (for example, repeating the same content for 3 times), v0.3.6 and v0.3.7 still took less than 100ms to finish the translation, while v1.0.0 and v1.0.1 took about 16 to 18 seconds. Additionally for v1.0.0 and v1.0.1, the browser gave a pop-up that the tab is not responding.
你好,请问能否将 OpenCCJSData
变量改为用 window
或 globalThis
来声明?
目前使用的声明方式 const OpenCCJSData
在动态加载时不能使用 window.OpenCCJSData
进行访问。
Sorry if this is obvious (JS is still somewhat opaque to me...), but how would one use this with es6 imports? I tried various versions of what is described here but none worked. Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.