如何解决BiDi括号问题? [英] How to solve BiDi bracket issues?

查看:672
本文介绍了如何解决BiDi括号问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如你可能知道的一些语言是从右到左书写/读取,我们正试图支持一些RTL语言。对于在html中使用dir =rtl的Web UI,大多数工作都要归功于浏览器具有的算法。但是我在文本中用括号插入了这个问题:

 < html> 
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title> BiDi的括号问题< / title>
< / head>
< body>

< p style =direction:rtl;>括号问题:hello(world):< / p>
< p style =direction:rtl;>没有括号问题:hello(world)something:< / p&
< p style =direction:rtl;>括号问题:(السلام(عليكم< / p>
< p style =direction:rtl;& السلام(عليكم)عليكم< / p>

< / body>
< / html>

问题可以在这里看到:
截图


解决方案

因此,我希望最后一个括号可以结束。这里的许多问题,根据unicode标准,括号是中性的,意味着它们不是固有地被当作LTR或RTL,它们采取他们周围语言的方向。在不正确呈现的例子中,括号假定与英语相同,即LTR。



第一个问题:
您告诉浏览器该段落应该被视为RTL。浏览器在里面找到英语,这是LTR,所以它认为英语嵌入在RTL段落内,最后一个字符)被视为RTL。 (周围的段落是RTL)。



第二个问题:
这里没有问题,从简单看你提供的源代码,你似乎已经提供了括号。但实际上,应该在RTL文本之后和结束之前的结束括号< / P>实际上是在启动RTL文本之前。如果你正确键入它,它会显得错误(因为你使用的文本编辑器假定end括号是LTR根据unicode)。要验证这一点,将内容复制到编辑器,将光标放在问题:的末尾,并重复按向右箭头并观察最后一个括号的位置。



没有给出更多解释,以下是一些使这项工作成功的例子:

 < html> 
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title> BiDi的括号问题< / title>
< / head>

< body>
< p style =direction:rtl;>< span dir =ltr>括号问题没有了:hello(world):< / span>< / p&
< p style =direction:rtl;>< span style =direction:ltr; unicode-bidi:embed>括号问题没有更多:hello(world):< / span> < / p>
< p style =direction:rtl;>括号问题不再显示:السلام(عليكم)< / p>

<! - 下面p标签的样式默认为ltr - >
< p>括号问题不再显示:< span dir =rtl>السلام(عليكم)< / span>< / p&
< p>括号问题不再显示:< span style =direction:rtl; unicode-bidi:embed>السلام(عليكم)< / span>< / p&
< / body>
< / html>

style =direction:ltr; works和dir =ltr的作品,所以我给了两个例子。另外,因为我假设你基本上需要解决你的第二个问题,你在其他LTR文档主要有RTL文本,我提供了最后两个例子。



注意:如果最后两个例子是你正在寻找的,并且你要使用CSS,unicode-bidi属性是必需的,这使得工作和不工作之间的所有区别。


As you might know some languages are written/read from right to left and we are trying to support some RTL languages. For the web UI using dir="rtl" in html does most of the job thanks to algorithms that browsers have. But I came across this issue with brackets in text:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Bracket problems with BiDi</title>
</head>
<body>

<p style="direction: rtl;">Bracket problem: hello (world):</p>
<p style="direction: rtl;">No bracket problem: hello (world) something:</p>
<p style="direction: rtl;">Bracket problem: (السلام (عليكم </p>
<p style="direction: rtl;">No bracket problem: السلام (عليكم) عليكم </p>

</body>
</html>

Problem can be seen here: Screenshot

So I want that last bracket stay in the end. What would be your solution?

解决方案

There are many problems here. According to the unicode standard, brackets are neutral, meaning they are not inherently treated as LTR or RTL. They take the direction of their surrounding language. In the examples where it is being incorrectly rendered, the direction of the closing bracket is assumed to be the same as of English, ie LTR.

1st problem: You tell the browser that the paragraph should be treated to be RTL. The browser finds English inside, which is LTR, so it thinks English is embedded inside an RTL paragraph, and the last character ")" is treated to be RTL. (the surrounding paragraph is RTL).

2nd problem: There is no problem here, from a simple look at the source code you have provided, it appears you have provided the brackets properly. But in fact, the closing bracket which should be after the RTL text and before the closing </P> is actually before the starting RTL text. If you type it properly, it would look wrong (because the text editor you are using assumes the end bracket is LTR according to unicode). To verify this, copy the contents on to your editor, put your cursor at the end of "problem:", and press the right arrow repeatedly and observe the location of the last bracket.

Without giving much more explaination, here are some examples to get this working:

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Bracket problems with BiDi</title>
</head>

<body>
  <p style="direction: rtl;"><span dir="ltr">Bracket problem no more: hello (world):</span></p>
  <p style="direction: rtl;"><span style="direction: ltr; unicode-bidi: embed">Bracket problem no more: hello (world):</span></p>
  <p style="direction: rtl;">Bracket problem no more: السلام (عليكم)</p>

  <!-- style for p tag below is ltr by default -->
  <p>Bracket problem no more: <span dir="rtl">السلام (عليكم)</span></p>
  <p>Bracket problem no more: <span style="direction: rtl; unicode-bidi: embed">السلام (عليكم)</span></p>
</body>
</html>

There are differences in how style="direction: ltr;" works and dir="ltr" works, so I've given examples of both. Also, because I assume you basically need to get your second problem solved, where you majorly have RTL text in an otherwise LTR document, I've provided the last two examples.

NOTE: If the last two examples are what you are looking for, and you are going to use CSS, the unicode-bidi property is required, and that makes all the difference between working and not working.

这篇关于如何解决BiDi括号问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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