///
//NSLocal可获取国家地区
NSLocale* TTCurrentLocale() {
//获取用户选择语言
if (languages.count > 0) {
NSString* currentLanguage = [languages objectAtIndex:0];
return [[[NSLocale alloc] initWithLocaleIdentifier:currentLanguage] autorelease];
} else {
//返回系统默认
}
}
///
NSString* TTLocalizedString(NSString* key, NSString* comment) {
static NSBundle* bundle = nil;
if (nil == bundle) {
NSString* path = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"Three20.bundle"];
bundle = [[NSBundle bundleWithPath:path] retain];
}
return [bundle localizedStringForKey:key value:key table:nil];
}
///
NSString* TTDescriptionForError(NSError* error) {
TTDINFO(@"ERROR %@", error);
if ([error.domain isEqualToString:NSURLErrorDomain]) {
// Note: If new error codes are added here, be sure to document them in the header.
if (error.code == NSURLErrorTimedOut) {
return TTLocalizedString(@"Connection Timed Out", @"");
} else if (error.code == NSURLErrorNotConnectedToInternet) {
return TTLocalizedString(@"No Internet Connection", @"");
} else {
return TTLocalizedString(@"Connection Error", @"");
}
}
return TTLocalizedString(@"Error", @"");
}
///
//格式化数据
NSNumber* number = [NSNumber numberWithInt:num];
NSNumberFormatter* formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSString* formatted = [formatter stringFromNumber:number];
[formatter release];
return formatted;
}
