小程序 国际化_在国际化您的应用程序时忘记的一件事

小程序 国际化

The hidden bugs waiting to be found by your international users

您的国际用户正在等待发现的隐藏错误

While internationalizing our applications, we focus on the things we can see: text, tool-tips, error messages, and the like. But, hidden in our code there are places requiring internationalization that tend to be missed until found by our international users and reported as a bug.

在对我们的应用程序进行国际化的同时,我们专注于可以看到的内容:文本,工具提示,错误消息等。 但是,在我们的代码中隐藏着一些需要国际化的地方,在我们的国际用户发现并报告为错误之前,这些地方往往会被遗漏。

Here’s a big one: regular expressions. You likely use these handy, flexible, programming features to parse text entered by users. If your regular expressions are not internationalized, more specifically, if they are not written to handle Unicode characters, they will fail in subtle ways.

这是一个很大的:正则表达式。 您可能会使用这些方便,灵活的编程功能来解析用户输入的文本。 如果您的正则表达式没有被国际化,更具体地说,如果它们不被编写为处理Unicode字符,它们将以微妙的方式失败。

Here’s an example: imagine a commenting system in your application that allows users to type at-mentions of other users or user groups. People at-mentioned are notified that the comment needs their attention. Your system may have the requirement that the at-mention format is something like:

^ h ERE是一个例子:想象你的应用程序中的评论系统,允许用户输入其他用户或用户组的AT-提及。 通知所提及的人该评论需要引起他们的注意。 您的系统可能要求注意格式为:

Image for post

Writing a regular expression to find and parse the usernames out of these strings is the most direct way for handling this. In Java, JavaScript, and other languages, the regular expression might look like this:

编写正则表达式以从这些字符串中查找和解析用户名是处理此问题的最直接方法。 在Java,JavaScript和其他语言中,正则表达式可能如下所示:

Image for post

This expression specifies that we’re looking for an ‘@’ followed by a letter or number, followed by one or more letters, numbers, dashes, underscores, or dots, and ending with a letter or number. The parentheses tell the expression to capture this string and return it to us.

此表达式指定我们要查找的是“ @”,后跟一个字母或数字,然后是一个或多个字母,数字,破折号,下划线或点,并以字母或数字结尾。 括号告诉表达式捕获该字符串并将其返回给我们。

We can test it using the regex101 tester:

我们可以使用regex101测试仪进行测试:

Image for post
https://regex101.com/r/gVNS9f/1/https://regex101.com/r/gVNS9f/1/

So that regex works great! But now let’s test it against some comment text containing Unicode characters:

因此,正则表达式效果很好! 但是,现在让我们针对一些包含Unicode字符的注释文本进行测试:

“This comment mentions @Adriàn, @François, @Noël, @David, and @ひなた”

“此评论提到@Adriàn,@ François,@Noël,@ David和@ひなた”

Image for post
https://regex101.com/r/b4ZGY2/2/https://regex101.com/r/b4ZGY2/2/

Unicode characters are not matched, so we either get incomplete usernames or no username at all.

Unicode字符不匹配,因此我们得到的用户名不完整或根本没有用户名。

The solution:

吨他的解决方案:

Unicode is a character set that aims to define all characters and glyphs from all human languages, living and dead.”

Unicode是一种字符集,旨在定义所有人类语言(生与死)中的所有字符和字形。”

http://www.regular-expressions.info/unicode.html

http://www.regular-expressions.info/unicode.html

It would seem incredibly difficult to write a regular expression encompassing the Unicode mission statement quoted above, but it’s fairly straight forward. To match a single letter grapheme (a complete letter as rendered on screen), we use the \p{L} notation.

编写包含上面引用的Unicode Mission语句的正则表达式似乎非常困难,但这很简单。 为了匹配单个字母字素(屏幕上呈现的完整字母),我们使用\ p {L}表示法。

Updating our regex to use this Unicode friendly notation for letters, we get:

更新我们的正则表达式以对字母使用此Unicode友好符号,我们得到:

Image for post

Let’s try it out in the regex101 tester:

让我们在regex101测试仪中尝试一下:

Image for post
https://regex101.com/r/b4ZGY2/1https://regex101.com/r/b4ZGY2/1

Close! But @Adriàn is not getting fully parsed. In fact, the string returned from the capture group is ‘Adria’, so we’ve got an incomplete username and lost the grave accent over the a. What’s going on?

关! 但是@Adriàn尚未完全解析。 实际上,从捕获组返回的字符串是“ Adria”,因此我们的用户名不完整,并且丢失了a字母的重音。 这是怎么回事?

To understand this, let’s take a look at how single characters rendered on a screen or page are represented in Unicode. The à is actually two Unicode characters, U+0061 representing the a and U+0300 representing the grave accent above the a. The grave accent is a combining mark. A character can be followed by any number of combining marks which will be assembled together when rendered.

为了理解这一点,让我们看一下屏幕或页面上呈现的单个字符如何以Unicode表示。 à实际上是两个 Unicode字符,U + 0061代表a ,U + 0300代表a上方的重音。 重音是一个结合的标志 。 字符后可以跟任意数量的组合标记,这些标记在渲染时将组装在一起。

Fortunately, our regex can look for combining marks as well with the \p{M} specifier. This matches on a Unicode character that is a combining mark. Our usernames as defined will never start with a combining mark, but we do need to check for them in the middle and at the end of the strings. The new regex looks like this:

幸运的是,我们的正则表达式也可以使用\ p {M}说明符来查找标记组合。 这与作为组合标记的Unicode字符匹配。 我们定义的用户名永远不会以组合标记开头,但是我们确实需要在字符串的中间和结尾检查它们。 新的正则表达式如下所示:

Image for post

Testing it:

测试它:

Image for post
https://regex101.com/r/uV38Y6/1https://regex101.com/r/uV38Y6/1

Success!

成功!

One detail worth knowing is that some combined characters like the à can also be specified in Unicode with a single character (U+00E0 in this case). But with our regex, it doesn’t matter. We’ll match the character if it has a single representation, with the /p{L} specifier, or if it is a combination of two characters, with the /p{M} specifier.

值得一提的一个细节是,也可以使用单个字符(在本例中为U + 00E0)在Unicode中指定诸如à之类的一些组合字符。 但是使用我们的正则表达式,没关系。 如果字符具有单个表示,则将其与/ p {L}说明符相匹配,或者,如果它是两个字符的组合,则将与/ p {M}说明符相匹配。

As long as we’re internationalizing, let’s deal with the digits as well. Unicode regex handling gives us a safe way to match any representation of the digits 0 through 9 using the \p{Nd} specifier. Using it, we get our final internationalized regular expression for matching and returning usernames in the body of a comment’s text:

只要我们正在国际化,我们也要处理数字。 Unicode正则表达式处理为我们提供了一种安全的方式,可以使用\ p {Nd}说明符来匹配数字0到9的任何表示形式。 使用它,我们得到了最终的国际化正则表达式,用于匹配和返回注释文本正文中的用户名:

Image for post

The exact details for handling Unicode in regular expressions can vary from language to language, so be sure to check out the differences for your code. The site regular-expressions.info is an excellent source for regular expression information in all programming languages and is what lead me to the solution I described in this article.

在不同的语言中,使用正则表达式处理Unicode的确切细节可能有所不同,因此请务必检查出代码的差异。 该网站regular-expressions.info是所有编程语言中正则表达式信息的绝佳来源,也是使我引向本文所述解决方案的原因。

翻译自: https://medium.com/@kennyflutes/the-one-thing-you-forgot-while-internationalizing-your-application-72c3323b253c

小程序 国际化

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/387841.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

三. 性能测试领域

能力验证: 概念:系统能否在A条件下具备B能力 应用:为客户进行系统上线后的验收测试,作为第三方对一个已经部署系统的性能验证 特点:需要在已确定的环境下运行 需要根据典型场景设计测试方案和用例 一个典型场景包括操…

PCA主成分分析Python实现

作者:拾毅者 出处:http://blog.csdn.net/Dream_angel_Z/article/details/50760130 Github源码:https://github.com/csuldw/MachineLearning/tree/master/PCA PCA(principle component analysis) ,主成分分…

scp

将文件或目录从本地通过网络拷贝到目标端。拷贝目录要带 -r 参数 格式:scp 本地用户名IP地址:文件名1 远程用户名IP地址:文件名 2 例: scp media.repo root192.168.20.32:/etc/yum.repos.d/ 将远程主机文件或目录拷贝到本机,源和目的参数调换…

robo 3t连接_使用robo 3t studio 3t连接到地图集

robo 3t连接Robo 3T (formerly Robomongo) is a graphical application to connect to MongoDB. The newest version now includes support for TLS/SSL and SNI which is required to connect to Atlas M0 free tier clusters.Robo 3T(以前称为Robomongo )是用于连接MongoDB的…

JavaWeb--JavaEE

一、JavaEE平台安装1、升级eclipseEE插件2、MyEclipse二、配置Eclipse工作空间1.字体设置 2.工作空间编码 UTF-83.JDK版本指定 4.集成Tomcat Server运行环境5.配置server webapps目录 端口号 启动时间等三、创建第一个Web项目1.创建 Web Project2.设置 tomcat、创建web.xml3.目…

软件需求规格说明书通用模版_通用需求挑战和机遇

软件需求规格说明书通用模版When developing applications there will be requirements that are needed on more than one application. Examples of such common requirements are non-functional, cookie consent and design patterns. How can we work with these types of…

python版PCA(主成分分析)

python版PCA(主成分分析) 在用统计分析方法研究这个多变量的课题时,变量个数太多就会增加课题的复杂性。人们自然希望变量个数较少而得到的信息较多。在很多情形,变量之间是有一定的相关关系的,当两个变量之间有一定…

干货|Spring Cloud Bus 消息总线介绍

2019独角兽企业重金招聘Python工程师标准>>> 继上一篇 干货|Spring Cloud Stream 体系及原理介绍 之后,本期我们来了解下 Spring Cloud 体系中的另外一个组件 Spring Cloud Bus (建议先熟悉 Spring Cloud Stream,不然无法理解 Spr…

一类动词二类动词三类动词_基于http动词的完全无效授权技术

一类动词二类动词三类动词Authorization is a basic feature of modern web applications. It’s a mechanism of specifying access rights or privileges to resources according to user roles. In case of CMS like applications, it needs to be equipped with advanced l…

主成份分析(PCA)详解

主成分分析法(Principal Component Analysis)大多在数据维度比较高的时候,用来减少数据维度,因而加快模型训练速度。另外也有些用途,比如图片压缩(主要是用SVD,也可以用PCA来做)、因…

thinkphp5记录

ThinkPHP5 隐藏index.php问题 thinkphp模板输出cookie,session中… 转载于:https://www.cnblogs.com/niuben/p/10056049.html

portainer容器可视化管理部署简要笔记

参考链接:https://www.portainer.io/installation/ 1、单个宿主机部署in Linux:$ docker volume create portainer_data$ docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer 2、单…

证明您履历表经验的防弹五步法

How many times have you gotten the question “Tell me more about your work experience at …” or “Describe an experience when you had to overcome a technical challenge”? Is your answer solid and bullet-proof every single time you have to respond? If no…

2018-2019-1 20165231 实验四 外设驱动程序设计

博客链接:https://www.cnblogs.com/heyanda/p/10054680.html 转载于:https://www.cnblogs.com/Yhooyon/p/10056173.html

如何安装pylab:python如何导入matplotlib模块

pylab是python下挺不错的一个画图模块,使用也非常简单,记得Mit的计算机科学及编程导论有节课也是用到了这个工具,但这个工具安装不象用起来那么方便,小编就图文全程直播下吧 工具/原料 python2.7.10win10 32位方法/步骤 1缺省状态…

微信扫描二维码和浏览器扫描二维码 ios和Android 分别进入不用的提示页面

实现微信扫描二维码和浏览器扫描二维码 ios和Android 分别进入不用的提示页面 而进入商城下载该项目 详情地址:gitee.com/DuJiaHui123… 1.创建完之后 替换文件里面的ios项目地址和Android地址 2.网页上线 3.百度搜索 二维码生成 把上线后的地址生成二维码 4.可以把…

详解getchar()函数与缓冲区

1、首先,我们看一下这段代码: 它的简单意思就是从键盘读入一个字符,然后输出到屏幕。理所当然,我们输入1,输出就是1,输入2,输出就是2。 那么我们如果输出的是12呢? 它的输出是1。 这…

windows下python安装Numpy、Scipy、matplotlib模块

python 2.7 针对2.7的软件。numpy :http://sourceforge.net/projects/numpy/files/NumPy/1.8.1/ 下载下面的numpy-1.8.2-win32-superpack-python2.7 scipy: http://sourceforge.net/projects/scipy/files/matplotlib:matplotlib-1.1.0.win32-py2.7 以上都是exe文件&#xff0…

restTemplate使用和踩坑总结

日常工作中肯定会遇到服务之间的调用,尤其是现在都是微服务的架构,所以总结一下restTemplate的最常用的用法以及自己踩过的坑。 restTemplate的使用 restTemplate底层调用的是Execute方法,而Execute底层调用的是doExecute,它是基于…

常见编码总结

本文总结自:https://blog.csdn.net/zmx729618/article/details/51821024 1. ISO 8859-1 字节数:1 范围:0-255(编码范围是0x00-0xFF),其中0x00-0x7F之间完全和ASCII一致(ASCII是7位编码&#xff…