Reputation: 41510
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
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
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
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
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
Reputation: 96994
To localize your application name:
Make a locale folder entitled en.lproj
for English, de.lproj
for German, fr.lproj
for French, etc. inside your Xcode project folder
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
In your Xcode project, navigate to the InfoPlist.strings
item and open its disclosure triangle
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
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
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