0
votes

I have an application that reads some strings and displays them in some UILabels, but these strings are not from one language so I need to be able to set the alignment of the label to right if the string is from a RTL language, and to left otherwise.

So is there a direct way to accomplish that, and if not what's the best way to get the language's direction from a string. I'm thinking of checking the first X characters of the string and see what is the larger percentage of the LTR and RTL characters to set the alignment of the label according to it. Is this a good solution and if so where could I find a table that shows what are the unicodes that belongs to LTR characters and what those for RTL.

1

1 Answers

0
votes

In programs with appropriate RTL support, you do not need to set the direction for any simple text like just words and spaces. Programs are expected to apply the properties of the characters themselves, as defined in character code standards.

If a piece of text to be rendered as a unit contains punctuation characters and/or a mix of LTR and RTL letters, the direction should be set either with control characters or at a higher protocol level. I don’t think you should do heuristics on this; rather, the overall direction should be a property of the text item, decided by the information provider (e.g., author, translator) and stored along with the text. In software localization, a set of localized values for texts normally has one language and the overall direction should be stored as part of the data set or inferred from the language.

Note that writing direction should also affect the overall layout direction (e.g., table columns should run from right to left for RTL languages) and the text alignment.