Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I learned how to make English and Arabic project from previous question I asked.

Same Project at github

Now what I did is added a label in this project and wrote "Welcome".

The problem is the layout. When I have English text it is at left side (obviously), but when the Arabic text comes, it should start from right to left. But it is aligned to left only.

Any idea how to deal with such case?

Below are the screenshots...

English

enter image description here

Arabic

enter image description here

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Below is what I did...

Added fonts in projects folder (english.ttf & arabic.ttf) as shown here.

In Localizable.strings added "myFont"="ACS Zomorrod"; (Arabic) & "myFont"="Armalite Rifle"; (English)

and then had those font in condition

NSString *myFont = localize(@"myFont");
NSString *cpFont = @"Armalite Rifle";
if ([myFont isEqualToString:cpFont]) {
    self.myLabel.textAlignment = NSTextAlignmentLeft; // this is for English
} else {
    self.myLabel.textAlignment = NSTextAlignmentRight; // this is for Arabic
}

Edit 1

Also you could have "myLang"="arabic"; & "myLang"="english"; in Localizable.strings and then have code as

NSString *myLang = localize(@"myFont");
NSString *myActualLang = @"english";
if ([myFont isEqualToString:myActualLang]) {
    self.myLabel.textAlignment = NSTextAlignmentLeft; // this is for English
} else {
    self.myLabel.textAlignment = NSTextAlignmentRight; // this is for Arabic
}

I will prefer the second option instead of first as tomorrow if I change the font, I would have to do changes at line NSString *cpFont = @"Armalite Rifle"; in all files.

share|improve this answer
add comment

Conditional if-else

Check for your font and change the alignment.

Or,

Make two labels for each of them setting their alignemnt Left-Right and Right-Left and show the text on either by checking the language.

share|improve this answer
 
how to check font? –  Fahim Parkar Jan 15 at 10:27
 
Who will show the string in your textbox? You only will be passing text and font type to show it, am I wrong? –  Anoop Vaidya Jan 15 at 10:30
 
I don't have any textbox... i have label and button... how to deal in this case? –  Fahim Parkar Jan 15 at 10:47
 
and how can i set two font for same textbox?? –  Fahim Parkar Jan 15 at 10:49
 
same thing if(fontName==ArbicOrSomehing){...} else{...} –  Anoop Vaidya Jan 15 at 10:50
show 7 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.