Boon
Boon

Reputation: 41510

How to localize app title and date/time an iPhone app

I know how to localize strings for iPhone app (via the use of NSLocalizedString and Localizable.strings) How can I do the same for date time display? Right now I am using NSDateFormatter for date/time.

Upvotes: 2

Views: 4395

Answers (7)

thierryb
thierryb

Reputation: 3738

I had to localize hours and display hours regarding user pref (military time, 24H) Here is my code :

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setLocale: [NSLocale currentLocale]];
[dateFormatter setDateStyle:kCFDateFormatterNoStyle];
[dateFormatter setTimeStyle:kCFDateFormatterShortStyle];

NSLog([dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:currentSong.timestamp]]);

Upvotes: 2

Narayana Rao Routhu
Narayana Rao Routhu

Reputation: 6323

If you want localize the date first convert date into double using following method double double_date = (double)[date timeIntervalSince1970]; after that you can convert this double value in any format using below code

    NSDateFormatter *dateformater =[[NSDateFormatter alloc] init];
    [dateformater setLocale:[NSLocale currentLocale]];
    [dateformater setDateStyle:NSDateFormatterLongStyle];//set current locale
    [dateformater setTimeStyle:NSDateFormatterShortStyle];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:dateinDouble];//it return the the date according to the locale formate

Upvotes: 2

jeka
jeka

Reputation: 330

You don't need to do anything special to localize date-time. NSDateFormatter does this by default. The reason you are not seeing the desired behavior (I assume that's why you are asking the question) is that you probably don't have your Region Format set properly. Setting the language alone is not enough. Change the "Region Format" on your test device and you shall see your dates localized: Settings->International->Region Format

Upvotes: 1

Jonny
Jonny

Reputation: 16338

Select the "appname"-Info.plist, command-I and in the window you select the "Make File Localizable". Go back into the General tab, and add localized settings with the "Add localization" button.

Upvotes: 0

Alex Reynolds
Alex Reynolds

Reputation: 96994

To localize your application name:

  1. Make a locale folder entitled en.lproj for English, de.lproj for German, fr.lproj for French, etc. inside your Xcode project folder

  2. In each *.lproj folder, create a file called InfoPlist.strings through Xcode:

    a. Click on the File menu and select New File...

    b. Select the Other group and click on Strings

    c. Add the new strings file with the required name in the desired locale folder

  3. In your Xcode project, navigate to the InfoPlist.strings item and open its disclosure triangle

  4. Click on en for English, and add the string:

    CFBundleDisplayName = "AppNameInEnglish";

    For German, click on de and add the string:

    CFBundleDisplayName = "AppNameAufDeutsch";

    And so forth...

Upvotes: 2

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81878

For the app title you have to look into Localizing Property List Values. In short: use InfoPlist.strings files in your localized directories.

Upvotes: 0

Ryan McCuaig
Ryan McCuaig

Reputation: 2279

You probably want to look at NSLocale ... check the Locales Programming Guide. Getting your date formatters with constants from NSDateFormatter.h like

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];

should do the right thing with respect to the locale set by the user in their system settings.

You can check a formatter's current locale with [dateFormatter locale].

Upvotes: 0

Related Questions