nslocale

How do I get a list of countries in Swift ios?

家住魔仙堡 提交于 2019-12-03 09:52:04
I've already seen two similar questions to mine, but the answers for those questions do not work for me. I have an old project with a list of countries manually typed out inside a set of square brackets. I can easily use this in my pickerView but I'm wondering if there is a more efficient way to do this? I will be using the list of countries in a UIPickerView. Ian You can get a list of countries using the NSLocale class's isoCountryCodes which returns an array of [String] . From there, you get the country name by using NSLocale 's displayName(forKey:) method. It looks like this: var countries:

Converting Country codes to country names on Device with non-english language

人走茶凉 提交于 2019-12-02 07:04:36
问题 This is the code I am using (Taken from - Converting Country Codes to Country Names) NSLocale *locale = [NSLocale currentLocale]; NSString *countryCode = [locale objectForKey: NSLocaleCountryCode]; NSString *identifier = [NSLocale localeIdentifierFromComponents: [NSDictionary dictionaryWithObject: countryCode forKey: NSLocaleCountryCode]]; NSString *country = [[NSLocale currentLocale] displayNameForKey: NSLocaleIdentifier value: identifier]; On device with english I'll get this: "Argentina"

Detect language in use by iOS application

本小妞迷上赌 提交于 2019-12-02 02:42:00
问题 How can I detect the current application language ? I am not talking about NSLocale user preferences. In my app there are currently two supported languages. A default 'en' and a specific 'it'. I just wanted to know which one is actually in use. If it is relevant, as a further explanation, I am providing content trough a web service only for the two supported languages. When invoking the service I need to pass a language parameter. Currently I am doing this, it works, but I totally dislike it:

Detect language in use by iOS application

本秂侑毒 提交于 2019-12-02 01:03:39
How can I detect the current application language ? I am not talking about NSLocale user preferences. In my app there are currently two supported languages. A default 'en' and a specific 'it'. I just wanted to know which one is actually in use. If it is relevant, as a further explanation, I am providing content trough a web service only for the two supported languages. When invoking the service I need to pass a language parameter. Currently I am doing this, it works, but I totally dislike it: NSString *preferredLanguage = [[NSLocale preferredLanguages] objectAtIndex:0]; if (![preferredLanguage

iOS NSDateFormatter needs NSLocale even it's UTC

若如初见. 提交于 2019-12-01 22:41:05
I have a doubt that I cannot understand why is the way it is and I appeal to the Gods of this site :) I have a date coming like this: "1982-01-01T00:00:00Z" As I'm displaying whatever the server sends (I know, customer requirement, not good practice...), I'm forcing the device to have that TimeZone with the following method, simplified without error checking, not optimized, and all that kind of things: + (NSString *) yearStringFromDate: (NSDate *) date { NSDateFormatter *formatter = [NSDateFormatter new]; [formatter setDateFormat:@"YYYY"]; [formatter setTimeZone:[self timezoneForSIHF]]; return

NSLocale returning wrong value in iOS 11

北战南征 提交于 2019-11-30 22:46:41
Starting from iOS 11.0, the following code returns "de_US" instead of "en_US" : // => Returns "de_US" NSString *regionCode = [[NSLocale currentLocale] objectForKey:NSLocaleIdentifier]; NSLog(@"Region code: %@", regionCode); Below iOS 11, it returns "en_US". My device has for language and region English / United States. Preferred languages (despite I do not use them in my code) are in order: English Deutsch French Is it a known issue of iOS 11? Has the API changed? Found it! It's a change behaviour starting from iOS 11. Under iOS 11, [NSLocale currentLocale] only returns languages supported by

Check language in iOS app

左心房为你撑大大i 提交于 2019-11-30 08:49:13
Task is : I have got two UIImageViews, and I want present ImageView1 if system language is Ukrainian, and if it is not Ukrainian(English/Polish etc) I want present ImageView2. I tried : println(NSUserDefaults.standardUserDefaults().objectForKey("AppleLanguages")) but this code gives only list of available languages. I also tried var language: AnyObject? = NSLocale.preferredLanguages().first but how can I compare this variable with English or Ukrainian language? Jonauz Swift 3 You can take the language code like this let preferredLanguage = NSLocale.preferredLanguages[0] And then you need to

Uppercase All String According to Locale - Swift

被刻印的时光 ゝ 提交于 2019-11-30 05:48:49
问题 I'm trying to uppercase all string according to 'Locale' but it is not working. var text = "istanbul, izmir" println(text.uppercaseStringWithLocale(NSLocale.currentLocale())) In Turkish language the uppercase for i is İ not I. My Result is ISTANBUL, IZMIR but It should returns İSTANBUL, İZMİR. Please where would be my issue? 回答1: NSLocale.currentLocale() is the locale which was selected in the Settings of the device. If that is "en_US" then text.uppercaseStringWithLocale(NSLocale

How to get country code using NSLocale in Swift 3

强颜欢笑 提交于 2019-11-29 23:34:37
Could you please help on how to get country code using NSLocale in Swift 3 ? This is the previous code I have been using. NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as! String I can get Language Code as below in Swift 3. Locale.current.languageCode! As I can see, fetching languageCode is straight forward but countryCode property is not available. Martin R See Wojciech N.'s answer for a simpler solution! Similarly as in NSLocale Swift 3 , you have to cast the overlay type Locale back to its Foundation counterpart NSLocale in order to retrieve the country code: if let countryCode

Set default language at first run IOS

折月煮酒 提交于 2019-11-29 14:31:51
I'm trying to set the language for my app at first run. After seeing this question, I decided to do the same. Setting default language for iPhone app on first run I adapted a bit the code, and made this: int main(int argc, char * argv[]) { @autoreleasepool { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:@[[ITConf getStringForKey:ITConfLocale]] forKey:@"AppleLanguages"]; [defaults synchronize]; return UIApplicationMain(argc, argv, nil, NSStringFromClass([ITAppDelegate class])); } } But this code does not works (changes are made after second startup).