Numbers inside TextView getting reversed when formatted in RTL

后端 未结 4 1684
清酒与你
清酒与你 2021-02-10 17:04

Numbers inside TextView are getting reversed when formatted in RTL. When numbers are at the end of a text inside a TextView they getting reversed. How

4条回答
  •  误落风尘
    2021-02-10 17:45

    The misunderstand: Digits in RTL languages like ARABIC should be written from RTL with the arabic digits to avoid any problems i.e: "تم إرسال رسالة نصية للرقم ١٢٣٤" Note that I wrote "رسالة نصية" NOT "SMS رسالة".

    The problem and it's solution: Mixing more than one direction languages required more steps, you need to tell the system "hey this is RTL word, add as it to sequence". So you may need to do this implicitly, i.e:

    \u200f + تم إرسال رسالة نصية إلى + number

    Consider StringBuilder: It's very painful for developer to develop something for RTL language using plus(+) notation, this much confusing and error prone.

    A better way:

    builder.append("\u061C").append(" تم إرسال رسالة نصية لـ").append("\u200E").append("+0123456789")
    

    Consider BidiFormatter: Utility class for formatting text for display in a potentially opposite-directionality context without garbling

    Example:

    String text = "{0} تم إرسال رسالة نصية لـ ";
    String phone = BidiFormatter.getInstance().unicodeWrap("+961 01 234 567");
    String result = MessageFormat.format(text,phone);
    

    Now, result will be formatted properly.

    More examples on how BidiFormatter work.

提交回复
热议问题