Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add line break to a rtl string in strings.xml in Android?

I'm trying to translate my android app from English to Hebrew by adding a strings.xml file to values directory and translating all English strings.

My problem is that adding a line break (\n) to the Hebrew string as i do with my English strings.xml strings doesn't work. An example to an English string with a line break:

<string name="no_group_instructions">You don\'t have a group yet!\n\nPlease choose whether to create a new group, or to join an existing one...</string>

How can i add line breaks to my non-English strings?

EDIT

I eventually did manage to do the line break in the Hebrew string using \n. I guess that the right-to-left writing, which is not supported well enough in Android Studio, caused the problem in the first place. I solved it by copying the string with the \n's from notepad straight to the strings.xml file, and not wrote it directly in the Android Studio.

like image 865
milyoav Avatar asked Feb 04 '23 16:02

milyoav


2 Answers

I had the same problem. To solve it, just copy-paste "\n" into your string as I did:

<string name="ta_tv_button_text">?היוםn\אכלתn\מה</string>

Make sure you support RTL in both your manifest and the TextView.

I could not copy-paste my string into here (it mixed up the string). I believe it will mix it up again if you try to copy-paste it to your project, so do not copy-paste my string to your project. This is how the string looks like in my project.

like image 113
Hadas Avatar answered Feb 07 '23 11:02

Hadas


You have to use <br /> to break line in xml instead of \n for example :

<string name="no_group_instructions">You don\'t have a group yet!
<br/><br/>Please choose whether to create a new group, or to join an existing one...
</string>

Result

like image 42
YCF_L Avatar answered Feb 07 '23 12:02

YCF_L