[英]Which JavaScript library should I use for client-side hyphenation?
I would like to implement client-side hyphenation via JavaScript on some large texts on my site. 我想在我的网站上的一些大文本上通过JavaScript实现客户端连字。 (I know about CSS3 hyphenation and will use it instead when available, but it's usually not available.)
(我知道CSS3连字符,并且会在可用时使用它,但它通常不可用。)
I have been using Hyphenator.js , and it works well but is very large (my optimized, compiled build with just English comes out to 106 KB) and pretty slow. 我一直在使用Hyphenator.js ,它运行良好,但是非常大(我的优化,编译版本只有英文版本达到106 KB)而且非常慢。 It's large and slow enough that I'm considering dropping hyphenation altogether.
它足够大而且速度慢,我正在考虑完全删除连字符。 It's just a luxury anyway.
无论如何,这只是一种奢侈品。
But recently I came across what seems to be an alternative: Hypher . 但最近我遇到了似乎是另一种选择: Hypher 。 What baffles me is how Hypher can me so much smaller and do the same thing.
令我感到困惑的是,Hypher如何让我这么小,做同样的事情。 I'm wondering if anybody can explain this.
我想知道是否有人可以解释这一点。
Does Hypher work just as well? Hypher也能正常工作吗? Is there any reason to use Hyphenator.js instead?
是否有任何理由使用Hyphenator.js? Hypher's readme has a link to Hyphenator.js at the bottom of the page , but none of the text explains the connection between these projects.
Hypher的自述文件在页面底部有一个指向Hyphenator.js的链接,但没有一个文本解释了这些项目之间的联系。
Does anybody have an opinion about the most efficient client-side hyphenation? 有没有人对最有效的客户端连字法有什么看法?
The primary reason Hypher's so small, comparatively, is that it relies on an externally-loaded jQuery for page integration. 相比之下,Hypher如此小的主要原因是它依赖于外部加载的jQuery来进行页面集成。 Hyphenator.js is completely standalone and thus has to include way more boilerplate for manipulating HTML across browsers.
Hyphenator.js是完全独立的,因此必须包含更多样板来跨浏览器操作HTML。 (They even re-implement some jQuery functionality.)
(他们甚至重新实现了一些jQuery功能。)
To be fair, Hyphenator.js is a relatively old project that hasn't been completely rewritten along the way to take advantage of substantial browser improvements. 公平地说,Hyphenator.js是一个相对较旧的项目,在利用浏览器大量改进的过程中还没有完全重写。 (Note that they proudly support Firefox 3.0.) And, more charitably, Hyphenator.js has many more finely-grained settings .
(请注意,他们自豪地支持Firefox 3.0。)更重要的是,Hyphenator.js有更多细粒度的设置 。
If you're already using jQuery, and don't use Hyphenator.js's advanced API, switching to Hypher may be a worthwhile improvement. 如果您已经在使用jQuery,并且不使用Hyphenator.js的高级API,那么切换到Hypher可能是值得改进的。
I had a look at hyphenation in JavaScript and found the following four libraries: 我在JavaScript中看了一下连字符,发现了以下四个库:
All four libraries are using the hyphenation algorithm developed by Franklin M. Liang that uses matching patterns to find hyphenation points in words. 所有四个库都使用由Franklin M. Liang开发的连字算法,该算法使用匹配模式来查找单词中的连字点。 This algorithm does not provide 100% correct hyphenations as stated by Liang in his thesis :
该算法没有提供梁在他的论文中所述的100%正确的连字符:
These patterns find 89% of the hyphens in a pocket dictionary word list, with essentially no error.
这些模式在口袋字典单词列表中找到89%的连字符,基本上没有错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.