且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android (Java) 中包含英语、希伯来语和数字的字符串中的 RTL 问题

更新时间:2023-02-26 12:17:52

这里没有任何问题,这实际上是正确的行为.数字出现在希伯来语词的结尾之后——希伯来语词的结尾在左边.您似乎想要的是数字出现在希伯来语单词之前.但是当你把它和英语结合起来时,它不知道这个数字应该绑定到希伯来语部分而不是英语部分,所以把它放在希伯来语之前也不起作用.

Nothing is screwing up here, this is actually correct behavior. The number is coming after the end of the hebrew word- the end of the hebrew word is on the left. What you seem to want is for the number to come before the hebrew word. But when you combine it with english like that it doesn't know tht the number is supposed to be bound to the hebrew part and not the english part, so putting it before the hebrew doesn't work either.

我建议将数字放在希伯来语部分之前,并将数字和希伯来语文本包装在 unicode 从右到左标记字符中,以明确告诉它 8 是从右到左文本的一部分.

I'd suggest putting the number before the hebrew part and wrapping the number and hebrew text in unicode right to left mark characters, to tell it explicitly the 8 is part of the right to left text.

或者,您可以将数字放在希伯来语文本之后,但在希伯来语之前使用 rtl 标记,在之后使用 ltr 标记.如果您想在其他地方进行更复杂的嵌入,这可能是一种更好的整体处理方式.

Alternatively you could put the number after the hebrew text but use an rtl mark before the hebrew and a ltr mark after. Which is probably a slightly better way of doing things overall if you want more complex embedding elsewhere.