如何解决BiDi支架问题?

发布于 2024-11-03 07:33:18 字数 879 浏览 0 评论 0原文

您可能知道,某些语言是从右向左书写/读取的,我们正在尝试支持某些 RTL 语言。对于 Web UI,在 html 中使用 dir="rtl" 可以完成大部分工作,这要归功于浏览器拥有的算法。但我在文本中遇到了这个带有括号的问题:

<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>

问题可以在这里看到:

在此处输入图像描述

所以我希望最后一个括号保留在最后。你的解决方案是什么?

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:

enter image description here

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

日记撕了你也走了 2024-11-10 07:33:18

这里有很多问题。根据 unicode 标准,括号是中性的,这意味着它们本质上不被视为 LTR 或 RTL。他们遵循周围语言的方向。在错误呈现的示例中,假定右括号的方向与英语相同,即 LTR。

第一个问题:
您告诉浏览器该段落应被视为 RTL。浏览器发现里面有英文,即LTR,所以它认为英文嵌入在RTL段落中,最后一个字符“)”被视为RTL。 (周围的段落是 RTL)。

第二个问题:
这里没有问题,从简单地查看您提供的源代码来看,您似乎已经正确提供了括号。但事实上,右括号应该位于 RTL 文本之后、结束

之前。实际上是在起始 RTL 文本之前。如果你输入正确,它看起来会是错误的(因为你使用的文本编辑器根据 unicode 假定结束括号是 LTR)。要验证这一点,请将内容复制到编辑器中,将光标放在“问题:”的末尾,然后反复按右箭头并观察最后一个括号的位置。

在不提供更多解释的情况下,这里有一些实现此功能的示例:

<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>

style="direction: ltr;" 的方式存在差异有效并且 dir="ltr" 有效,所以我给出了两者的示例。另外,因为我假设您基本上需要解决第二个问题,即您主要在 LTR 文档中包含 RTL 文本,所以我提供了最后两个示例。

注意:如果最后两个示例正是您要查找的内容,并且您要使用 CSS,则需要 unicode-bidi 属性,这使得工作与不工作之间存在很大差异。

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.

江南月 2024-11-10 07:33:18

您只需在最后一个括号后面添加 LRM 字符即可。 HTML 实体:

<html dir="rtl">
<body>
<p>hello (world)‎</p>
</body></html>

这告诉浏览器将括号解释为从左到右阅读。

You just need to add the LRM character after the last bracket. HTML entity:

<html dir="rtl">
<body>
<p>hello (world)‎</p>
</body></html>

This tells the browser to interpret the brackets as left-to-right reading.

转身泪倾城 2024-11-10 07:33:18

Silkfield 的回答引导我进入 页面显示了 BiDi 布局的许多可能的问题,包括括号问题

在此输入图像描述

silkfield's answer led me on to this page which shows many of the possible problems with BiDi layouts including the bracket issue

enter image description here

留一抹残留的笑 2024-11-10 07:33:18

您可以针对您的问题添加以下 css
在 body 标签中添加“unicode-bidi:embed”,它会正常工作

you can put the following css for your issue
"unicode-bidi:embed" in the body tag, it will work fine

笑红尘 2024-11-10 07:33:18

只需添加 style="direction: rtl"> 到您的 textTag (

)

Just add style="direction: rtl"> to your textTag (<p style="direction: rtl">)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文