自学Swift-斯坦福笔记整理(十七) Internationalization and Settings

来源:互联网 发布:java常用对象及api 编辑:程序博客网 时间:2024/05/03 14:58
Internationalization
Internationalization(i18n)
localization(l10n)


func NSLocalizedString(
     key: String,//这是唯一方式去验证字符.通常想哟啊放到屏幕上的开发者语言
     tableName: String,bundle: NSBundle,
     value: String//它将使用如m果它不能找到这个一个翻译者并不能翻译这些key
     comment: String //这个将高速翻译者,这些是内容
) -> String
大部分情况 tableName和bundle都是默认的,这个tableName需要本地化bundle将作为你主要的bundle(你的app)
String.localizedStringWithFormat(
     NSLocalizedString(“the result is %g”,comment:”give numeric result to the user”),theNumber
)

formatters是基于本地的
一个是语言,另一个是位置
NSNumberFormatter()
NSDateFormatter
NSDateComponentsFormatter
NSByteCountFormatter
MKDistanceFormatter

NSNumberFormatter Demo
let formatter = NSNumberFormatter()

var nsmberStyle: NSNumberFormatterStyle //.DecimalStyle,.CurrencyStyle
let stringToDisplay = formatter.stringFromNumber(theNumber)

Settings
所有设置设置用户界面是通过NSUserDefaults
设置Settings Bundle
NSUserDefaults.standardUserDefaults().doubleForKey(“")

//通知,因为如果在设置里进行了设置用户不重启APP的话设置是没用的
NSNotificationCenter.defaultCenter().addObserverForNamr(NSUserDefaultsDidChangeNotification,nil,nil){}//闭包里在放设置SettingBundle的值
0 0
原创粉丝点击