4

So my scenario is basically this: If a user has an Arabic Locale, a date is formatted into this string: ١٩‏/١٠‏/٢٠١٢ ٣:٢١ م

The numerals are Arabic and the date is ordered/formatted a certain way according to the Arabic locale/region format. The problem is that some users might have a Locale of Arabic, but the Language set to English (because he/she might not be able to read Arabic).

Is there a way to change just the numerals to arabic, while preserving everything else in the formatter from the Locale? That is, format that date according to the locale/region format (preserving order) but to use English numerals rather than the Arabic numerals. I don't see any way that Apple has provided us with making such a change.

Thanks in advance!

baselq
  • 301
  • 6
  • 17
  • 2
    possible duplicate of [iPhone display date using a user locale but in other language](http://stackoverflow.com/questions/4217334/iphone-display-date-using-a-user-locale-but-in-other-language) – Pfitz Dec 07 '12 at 10:52
  • Why dont you use conditional as if font is english do ../../.... if font is arabic ../../.... ? – Anoop Vaidya Jan 17 '13 at 18:39

2 Answers2

1

You have to use one of the locale identifiers that have the English numeral symbols. E.g:

NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateFormat = @"EEEE dd MMM | hh:mm a";
dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"ar_TN"];
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);

This will print:

الخميس 14 جانفي | 02:02 م
odm
  • 888
  • 1
  • 14
  • 22
  • For a full list of dates in different locales check this: https://gist.github.com/devinfoley/5980066 – odm Jan 14 '16 at 19:08
-1

The following post may answer your question: String replacement in Objective-C

NSString *str = @"This is a string";

str = [str stringByReplacingOccurrencesOfString:@"string"
                                 withString:@"duck"];

For each formatted date string you would call this 10 times (0,1,2,...,8,9). Maybe this will help you.

Community
  • 1
  • 1
  • I wouldn't encourage doing that. We can at least look into changing the NSDateFormatter's locale - instead of string replacement. The issue is also with the order of the formatting itself. Right to left instead of left to right. – hishamaus Feb 20 '15 at 01:17