mvasco
mvasco

Reputation: 5107

Month and week day language on a real device

I am creating an app that will be used mostly by spanish users.

I don't have access to a real device to test the app, but I have changed the iOS simulator language to spanish and the region to Spain.

In the app I am using NSDateFormatter to convert NSDate to strings, but on the simulator the strings for week day and month are in english.

This is the result :

enter image description here

My question is: should I change the strings to spanish programmatically or will they be shown in spanish on a real device?

Thank you.

UPDATED

Here the code I have so far:

 //convertir fecha
    NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
    NSLog(@"LOCALE = %@",language);

//NSLog result = es

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *date = [formatter dateFromString:fecha];

    [formatter setLocale:[NSLocale currentLocale]];

    NSDateFormatter *weekDay = [[NSDateFormatter alloc] init] ;
    [weekDay setDateFormat:@"EEEE"];
    [weekDay setLocale:[NSLocale currentLocale]];

UPDATE 2

I have changed the simulator configuration to spanish/Spain, as you may see in the picture, but dates appear in english !!! WHhy?

enter image description here

Upvotes: 1

Views: 298

Answers (1)

mackworth
mackworth

Reputation: 5953

Make sure in the simulator that you have set the region to Spanish/Spain (as opposed to Spain, which can be English in Spain). (The language setting is irrelevant to dates.) On the Settings/General/International screen it will show you a sample of the current Region Format; that must be in Spanish for your code to work.

International Settings page

To see in your app, add the following code:

NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
NSCalendar * calendar = [[NSLocale currentLocale] objectForKey:NSLocaleCalendar];
NSLog(@"LOCALE = %@/%@",language,   [calendar.locale localeIdentifier ] );

The calendar Locale can be en_ES, which means English in Spain or es_ES, which means Spanish in Spain.

All of which means that your code is fine; on a real device in Spain, you'll have no problem, and to see this, you just need to set your simulator's settings like a device in Spain.

Upvotes: 1

Related Questions