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

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

问题描述

我编写了一个 Web 应用程序,其中包含多种语言的翻译(其中一种是希腊语.)

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

当在标题上显示某个翻译时,设计规则是文本应该是大写的,这在世界上任何其他语言中都可以,但是当涉及到希腊语时,浏览器不知道要写什么处理重音符号(参见 this)所以他们显示错误的大写字符串.

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:

如果不对每个需要大写的元素(有很多)添加 uppercase 类,我可以使用计算的样式属性查询 DOM 吗?IE.给我所有具有计算 text-transform: uppercase

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

推荐答案

我强烈建议不要为此使用 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 个具有大写"文本转换.

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

jQuery 处理时间为 595 毫秒
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: 对象不支持属性或方法'each'
JS 处理时间为 577ms

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

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

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