Android Hebrew (RTL) Integration - android

I'm working on a relatively simple Android app. I want it to have an English version as well as a Hebrew version. (RTL Right to Left Alignment)
I have manually change the alignment to right in layout xml file. When a sentence contains digits (in the middle of it), the digits appear in a mirror view:
29 appears as 92, 21:45 appears as 54:12 and 2,000 appears as 000,2.
Also, when a sentence starts with digits or English characters, they get thrown to the end of the sentence messing it all up.
I think for android version 4.0.3 it supports Hebrew. I have check that in emulator.
So for older versions is there correct way to implement Hebrew?
Please help.

I think that Android's bidi analysis algorithm has some flaws. Unicode has two invisible, strongly directional characters that might help with these problems:
U+200E - left-to-right mark
U+200F - right-to-left mark
For the digit order problem, try putting left-to-right marks (U+200E) on both sides of the digit sequence.
Unicode also has the following bidi formatting codes:
U+202A - left-to-right embedding
U+202B - right-to-left embedding
U+202C - pop directional formatting (cancels the previous embedding or override)
U+202D - left-to-right override
U+202E - right-to-left override
For the problem with English fragments in Hebrew text, it might be as simple as putting a right-to-left mark before the English. (Android's algorithm may be under the impression that the paragraph is left-to-right since the first characters are English.) If that doesn't work, perhaps try surrounding selected text with some combination of formatting codes. (I'd try left-to-right embedding followed by pop directional formatting. I'd also try right-to-left embedding around everything combined with selective explicit right-to-left embeddings.)
The way these are supposed to affect text layout are defined by the Unicode Bidirectional Algorithm Unicode Standard Annex #9. However, if Android's implementation is broken (and I suspect it is), the best you can do is trial-and-error until you get things looking right. Good luck.
EDIT
As far as code is concerned, here's an example of how it might be done in Java:
String text = "גרסה \u200e2.100\u200e זמינה";
In XML, it might be:
<string name="update_available">גרסה ‎2.100‎ זמינה</string>

here is an example from my hebrew string xml, Thanks to Ted Hopp's answer:
you need to add '\u200e' before the char that causes you the problem:
<string name="basic_text1">המר על תוצאת המשחק\u200e:</string>
and the result will be:
:המר על תוצאת המשחק

Related

Zero-width space with special characters

Interesting problem here, wondering if anyone has come across it.
I am building an Android app that has some special characters as text (mainly Japanese characters) and our designers want some soft returns strategically placed, incase the text needs to wrap due to width limitations on smaller devices.
The problem is that since the text is essentially Japanese, there are no spaces between words.
I know we can use \u200b as a zero-width space resulting in a string like this:
abcdef\u200bghijklmnop
appearing like this when there is enough room:
abcdefghijklmnop
and like this if it needs to wrap:
abcdef
ghijklmnop
The problem is that if instead of standard English characters, we use Japanese characters it doesn't seem to work. We don't get soft line breaks at all. It instead always breaks right where it runs out of space regardless of where we put the \u200b
ヘルプヘルプ\u200bヘルプヘルプ
results in:
ヘルプヘルプヘルプヘ
ルプ
Has anyone dealt with this before or have any ideas on how to solve this?

What is android:layout_marginStart

I would like to add some space between the left display border and an ImageView. Android SDK made me aware of "android:layout_marginStart".
Consider adding android:layout_marginStart="10dp" to better support right-to-left layouts
Why should I use android:layout_marginStart="10dp" instead of android:layout_marginLeft="10dp"? I have never done so and never encountered any problems with so-called "right-to-left layouts".
start and end are the same as left and right for left-to-right (LTR) languages. For right-to-left (RTL) languages (Arabic, Hebrew, etc.), start and end reverse and become equivalent to right and left, respectively.
This Android Developers Blog post gets into a bit more detail.
Some APIs were introduced to support languages that use a right to left reading direction e.g Arabic and Hebrew.
One of which is android:layout_marginStart
See the link for more info : http://developer.android.com/about/versions/android-4.2.html#RTL

Right to Left support for TextView in Android

I'm developing an application for Android in Persian. I fetch data from SQLite database and display them, using TextView. How can I display the text (that contains multiple lines ) from right to left?
Any Idea?
If the ROM supports right-to-left, which is most likely the case if you bought your mobile in the middle east, then you can set the gravity to right.
If Android does not support this natively (I'm not sure), you could create a string reverser that swaps the nth char with the string.length() - nth character until you have a reflected string, and then post that right justified.
If the ROM doesn't support right-to-left rendering, you could possibly use the java.text.Bidi class that implements the Unicode Bidi Algorithm.
This is an old question but since it wasn't asked very good it was not answered.
#Farina, I believe the answer you are looking for is here:
http://developer.android.com/guide/topics/resources/providing-resources.html
In essence: By creating a layout-ar folder right next to your layout folder and placing an rtl oriented layout file in it you can get it to show only on rtl selected devices. (ar stands for Arab, if using a different rtl language you may find the code here. Be-were that some devices support old-deprecated language codes so if it doesn't work try looking for older codes)

Android How to get rid of question mark at end of ellipsize

I've defined the following TextView:
<TextView
android:id="#+id/textview_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_alignParentTop="true"
android:layout_marginRight="25dip"
android:ellipsize="end"/>
And as expected the text is cut off if it's too long and replaced by "...". But at the end of the three points appears a question mark surrounded by a square.
How can I get rid off this question mark?
Thanks!
To quote myself from one of my books:
Android's TextView class has the built-in ability to "ellipsize" text,
truncating it and adding an ellipsis if the text is longer than the available
space. You can use this via the android:ellipsize attribute, for example.
This works fairly well, at least for single-line text.
The ellipsis that Android uses is not three periods. Rather it uses an actual
ellipsis character, where the three dots are contained in a single glyph.
Hence, any font that you use that you also use the "ellipsizing" feature will
need the ellipsis glyph.
Beyond that, though, Android pads out the string that gets rendered on-
screen, such that the length (in characters) is the same before and after
"ellipsizing". To make this work, Android replaces one character with the
ellipsis, and replaces all other removed characters with the Unicode
character 'ZERO WIDTH NO-BREAK SPACE' (U+FEFF). This means the
"extra" characters after the ellipsis do not take up any visible space on
screen, yet they can be part of the string.
However, this means any custom fonts you use for TextView widgets that
you use with android:ellipsize must also support this special Unicode
character. Not all fonts do, and you will get artifacts in the on-screen
representation of your shortened strings if your font lacks this character
(e.g., rogue X's appear at the end of the line).
Had the same problem. Somebody with FontForge knowledge fixed the U+FEFF in my custom fonts and now they work well. Here is how he described what he did:
"I'm not good with Fontforge, so I cheated. Basically, opened the font in Fontforge, selected the space character, ctrl+c for copy, then selected FEFF, ctrl+v for paste. Then menu Metrics->Set Width and set to zero. Then File->Generate Fonts."

Android. Problem with arabic keyboard

I make arabic virtual keyboard, and I have a problem.
If you write only arabic characters - all works (written right to left). But the numbers and punctuation marks are written to the right of the previous word. Although should be written to the left of the word. For example:
You write:
word_2011 where '_' is space
Must be:
'2011_drow' (look right to left, numbers read left to right)
but is:
'_drow2011'
Now more interesting. If you write 'NOW' you get
'_drow201WON1' (must be 'WON2011_drow')
This is Android problem? Or is it possible to solve it?
This is due to the way Android mis-implements bidi (bi-directional) logic.
You will also have issues with arabic letters not displaying the mid and start letters correctly.
To work around the space problem you could try to insert a direction character between them see: http://en.wikipedia.org/wiki/Unicode_control_characters. This will work, but will get a square displayed instead of a space in some phones.

Categories

Resources