希腊语和文本转换:大写

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

问题描述

我编写了一个 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

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)