Android (Java) 中包含英语、希伯来语和数字的字符串中的 RTL 问题 [英] RTL issue in string containing English, Hebrew and digits in Android (Java)

查看:39
本文介绍了Android (Java) 中包含英语、希伯来语和数字的字符串中的 RTL 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在混合一个字符串英语、希伯来语和数字时遇到问题.希伯来语旁边的数字顺序正在颠倒,无论我按什么顺序——先是数字,然后是文本,第一个文本然后是希伯来语——它被颠倒为:在左边的数字上,在右边的文本上.我的文字示例是:

I have an issue when mixing in one string English, Hebrew and digits. The order of digits next to Hebrew is getting reversed, no matter what order I make - fist digit and then text, of first text and then Hebrew - it's getting reversed to: on the left digit, on the right text. My text example is:

String leftPart = "10 gr";
int numder = 8;
String hebrewText = "כפות";
String rightPart = hebrewText + " " + number;
String finalString = leftPart + " · " + rightPart; //10 gr · כפות 8

我想在这个字符串的末尾显示数字 8,在希伯来语单词之后,而不是在它之前,但即使在这里我也无法做到......因为乞讨中的英文文本,它正在被颠倒.

I want to display the digit 8 in the end of this string, after the Hebrew word, not before it, but I'm unable to do it even here...it's getting reversed because of the English text in the begging.

即使我将顺序更改为:

String rightPart = number + " " + hebrewText ;

结果是一样的...

有什么想法吗?看起来很简单,我错过了

Any ideas? It's looks like something simple that I'm missing

推荐答案

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

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.

这篇关于Android (Java) 中包含英语、希伯来语和数字的字符串中的 RTL 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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