希腊语和文本变换:大写 [英] Greek and text-transform:uppercase

查看:223
本文介绍了希腊语和文本变换:大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个包含多种语言(其中一个是希腊语)翻译的网络应用程序。

I've written a web application that contains translations in several languages (one of them being Greek.)

当在标题上显示某个翻译时,规则是文本应该是大写的,在世界上任何其他语言都是好的,但是当涉及到希腊语,浏览器不知道如何处理口音(见),因此它们显示错误的大写字符串。

When displaying a certain translation on the title, the design rule was that the text is supposed to be uppercased, which in any other language in the world is fine, but when it comes to Greek, browsers don't know what to do with the accents (see this) so they display the wrong uppercased String.

从该补丁我已经链接上面,我已经把它转换为Javascript,运行一些用例对它,它的工作原理。现在我要做的就是这样:

From that patch I've linked above, I've transformed it to Javascript, ran some use cases against it, and it works. Now all I have to do is this:

不需要为每个需要大写的元素添加大写 (有很多),我可以使用计算的样式属性查询 DOM 吗?也就是说。给我所有具有计算 text-transform的元素:大写

Without adding a uppercase class to every element that needs to be uppercased (there are quite a few), can I query the DOM using a computed style property? Ie. give me all the elements that have a computed text-transform: uppercase

推荐答案

p>我强烈建议不要使用jQuery。而是这样做:

I strongly suggest not using jQuery for this. Instead do this:

var e = document.getElementsByTagName('*'), l = e.length, i;
if( typeof getComputedStyle == "undefined")
    getComputedStyle = function(e) {return e.currentStyle;};
for( i=0; i<l; i++) {
    if( getComputedStyle(e[i]).textTransform == "uppercase") {
        // do stuff with e[i] here.
    }
}

测试10,000个元素,其中2,500个 text-transform。

Tested with 10,000 elements, of which 2,500 had "uppercase" text-transform.


jQuery处理时间为595ms

JS处理时间为60ms

jQuery processed in 595ms
JS processed in 60ms

所以JavaScript比jQuery快约10倍。

So JavaScript is approximately 10 times faster at this than jQuery.

编辑:另一个测试, 100,000个元素:

Another test, this time with 100,000 elements:


jQuery failed.TypeError:Object不支持属性或方法'each'

JS处理在577毫秒

jQuery failed.TypeError: Object doesn't support property or method 'each'
JS processed in 577ms

这篇关于希腊语和文本变换:大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆