希腊语和文本转换:大写

cha*_*log 12 javascript css internationalization

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

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

从我上面链接的那个补丁开始,我已经将它转换为Javascript,针对它运行了一些用例,并且它有效.现在我所要做的就是:

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

Oto*_*obo 12

在这个问题的解决方案实施例3上面描述了这里

这是一个应该适用于任何浏览器的示例(仅在Firefox 25上测试)

HTML:

<body>
  <p id="withlang" lang="el">???????? ?? ????????? ??????? ?? ??? ??????</p>
  <p id="withoutlang">???????? ?? ????????? ??????? ?? ?????????????? unicode</p>
  <p id="withlangsmall" lang="el">????? ???????? ?? ????????? ??????? ?? ??? ??????</p>
  <p id="withoutlangsmall">????? ???????? ?? ????????? ??????? ?? ?????????????? unicode</p>
</body>
Run Code Online (Sandbox Code Playgroud)

CSS:

#withlang, #withoutlang{
  text-transform: uppercase;
}

#withlangsmall, #withoutlangsmall{
  font-variant: small-caps;
}
Run Code Online (Sandbox Code Playgroud)

您还可以在更高级别使用lang属性,例如在body标签处.

HTML:

<body lang="el">
  <p id="withlang">???????? ?? ????????? ??????? ?? ??? ??????</p>
  <p id="withlangsmall">????? ???????? ?? ????????? ??????? ?? ??? ??????</p>
</body>
Run Code Online (Sandbox Code Playgroud)

CSS:

#withlang{
  text-transform: uppercase;
}

#withlangsmall{
  font-variant: small-caps;
}
Run Code Online (Sandbox Code Playgroud)

  • 不适用于IE和Chrome,对于Chrome,如果您将lang ="el"添加到html标记,它将起作用 (3认同)

Nie*_*sol 11

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

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.
    }
}
Run Code Online (Sandbox Code Playgroud)

测试了10,000个元素,其中2,500个具有"大写"文本转换.

jQuery在595ms
处理,处理时间为60ms

所以JavaScript比jQuery快大约10倍.

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

jQuery failed.TypeError:Object不支持
在577ms中处理的属性或方法' each'JS