Tag: nslocale

使用NSNumberFormatter在十进制后生成带尾随零的数字

在Swift中,你将如何创build一个NSNumberFormatter来保存十进制(12.000)后面的零,同时生成一个适合当前语言环境的数字? 我目前的代码和示例输出: let formatter = NSNumberFormatter() formatter.numberStyle = .DecimalStyle formatter.locale = NSLocale.currentLocale() formatter.maximumFractionDigits = 10 var doubleNumString = "12.0" println(formatter.numberFromString(doubleNumString)) //in English it prints 12, want it to print 12.0 var doubleNumString = "12.000" println(formatter.numberFromString(doubleNumString)) //prints 12, want it to print 12.000 var doubleNumString = "12.125" println(formatter.numberFromString(doubleNumString)) //prints 12.125 as expected var doubleNumString = "1234" […]

Iphone,从MonoTouch获取国家列表

是否有可能复制MonoTouch中的代码? 这是我迄今为止所尝试的: foreach(string countryCode in NSLocale.ISOCountryCodes){ // How to convert this objective-c code to c#? // [[NSLocale currentLocale] displayNameForKey:NSLocaleCountryCode value:countryCode] }

我怎样才能找出一个NSDate是否是一个工作日?

我怎样才能找出一个NSDate是否是一个工作日? 也就是说,根据用户当前的语言环境和日历设置是否是周末 – 所以不能硬编码为星期一至星期五? NSCalendar具有第一个firstWeekday属性,但这似乎只是一个表象的东西; 星期天在美国,周一在英国。 编辑:我不担心假期,我只是想能够像内置的日历应用程序相同的方式阴影的日历周末。

NSLocaleCountryCode返回nil

我有一个bugreport,在下面的行中,其中客户端是一个NSMutableDictionary的实例崩溃 [client setObject:[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] forKey:@"country"]; 我的猜测是, NSLocaleCountryCode在这一行返回nil,这导致添加一个零对象的NSDictionary ,这将导致崩溃。 问题是,有没有人遇到过这样的问题? 有没有什么原因NSLocaleCountryCode可能为零当前的currentLocale ? 文档没有说任何关于返回一个零值,我认为这将始终返回一个有效的国家。 最好的问候,迈克尔

我如何获得当前的应用程序语言环境?

我需要获取当前的语言环境。 不是用户区域设置,但我的应用程序区域设置 假设我的应用程序有两个本地化(在项目设置中):英语(默认)和法语。 如果用户在iPhone上设置法语,那么我的应用程序将显示法语界面。 如果用户在iPhone上设置德语,那么我的应用程序将显示英文界面(因为英文是默认的)。 那么如何获得当前正在显示的当前应用程序语言环境? 提前致谢。

iOS中有NSDecimalNumber的错误十进制分隔符

我试图用下面的方式输出正确的小数点分隔符的十进制数的描述: NSString* strValue = @"9.94300"; NSDecimalNumber* decimalNumber = [NSDecimalNumber decimalNumberWithString: strValue]; NSLocale* locale = [NSLocale currentLocale]; NSLog(@"%@", [locale localeIdentifier]); NSLog(@"%@", [decimalNumber descriptionWithLocale: locale] ); 输出是: de_DE 9.943 小数点分隔符应该是','而不是'。' 为这个地方。 错误在哪里? 如何输出正确的小数点分隔符取决于本地?

Swift – 获取国家列表

我怎样才能得到一个在Swift中所有国家名称的数组? 我试图转换我在Objective-C中的代码,这是这样的: if (!pickerCountriesIsShown) { NSMutableArray *countries = [NSMutableArray arrayWithCapacity: [[NSLocale ISOCountryCodes] count]]; for (NSString *countryCode in [NSLocale ISOCountryCodes]) { NSString *identifier = [NSLocale localeIdentifierFromComponents: [NSDictionary dictionaryWithObject: countryCode forKey: NSLocaleCountryCode]]; NSString *country = [[NSLocale currentLocale] displayNameForKey: NSLocaleIdentifier value: identifier]; [countries addObject: country]; } 在斯威夫特,我不能从这里过去: if (!countriesPickerShown) { var countries: NSMutableArray = NSMutableArray() countries = NSMutableArray.arrayWithCapacity((NSLocale.ISOCountryCodes).count) […]

在iOS应用程序中检查语言

任务是:我有两个UIImageViews,如果系统语言是乌克兰语,并且如果它不是乌克兰语(英语/波兰语等),我想要目前ImageView1我想目前ImageView2。 我试过了 : println(NSUserDefaults.standardUserDefaults().objectForKey("AppleLanguages")) 但是这个代码只给出了可用语言的列表。 我也试过了 var language: AnyObject? = NSLocale.preferredLanguages().first 但我怎样才能比较这个variables与英语或乌克兰语?

如何在Swift 3中使用NSLocale获取国家代码

你可以请帮忙在Swift 3使用NSLocale获取国家代码吗? 这是我以前使用的代码。 NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as! String 我可以在Swift 3中获得如下语言代码。 Locale.current.languageCode! 正如我所看到的,获取languageCode是直接的,但countryCode属性不可用。

使用NSLocale获取基于国家代码或国家/地区名称的货币符号

我想显示货币符号基于国名或国家代码使用NSLocale我有所有的国家名单。 假设我select了美国,那么它返回$货币 代码: NSLocale *locale = [NSLocale currentLocale]; NSString *countryCode = [locale objectForKey: NSLocaleCountryCode]; NSString *country = [locale displayNameForKey: NSLocaleCurrencyCode value: countryCode];