[IOS7开发]Title: Lecture 18: Core Motion, Image Picker, Localization

所需积分/C币:7 2014-07-15 10:27:05 1.91MB PDF
收藏 收藏

Title: Lecture 18: Core Motion, Image Picker, Localization
Today o Localization Internationalization really o Settings Adding UI to the Settings application e Demo Internationalizing Potomania Adding a Bouncer setting Stanford CS193 Fall 2013 Internationalization a Two steps to making international versions of your application Internationalization (i18n) Localization((10n) o Internationalization This is a process of making strings externally editable(from storyboard or code) It also involves using certain formatting classes for things like dates, numbers, etc You(the developer) get to do this work o Localization A process of editing those externalized strings(and then QAing the result) for a given language You usually hire a localization company to do this work Stanford CS193 Fall 2013 Internationalization Storyboards are localized by changing its strings only And we rely on Autolayout to make it all look nice a First step though: Registering Localizable Languages Go to the Project pane in Xcode(top in Navigator), then Info tab to add Localizations If you click "Use Base Internationalization" the strings in your storyboards will be extracted into editable. strings files (one for each language H|圖 Potomania Potomania Built Sett ngs You must inspect the project itself oS Deployment Target 7.0 here, not the Target you build V Configurations > Debug No Configurations Set No Configurations Set Base" is the "localization where storyboards UseRelease :for command-line builds live that are localizable using only. strings files (hopefully this is all storyboards) Language Resource Click this+ to add more languages v Use Basc Internationalization that you intend to support Stanford CS193 Fall 2013 Localizing Storyboards e Storyboards in Navigator will now have localizations Send the strings files out to localizers to translate the strings Localizers appreciate a demo of your application in your Base language Or at least send them the storyboards so they can get context Navigator File Inspector Potomania Localization 2 targets, IOS SDK 7.0 过Base potomania OEnglish Localizable Strings > Ullage+CS193p French Localizable strings 国 Application Delegate Core data model a Main_iPhone storyboard a Main_iPhone storyboard (Base) Main_iPhone. strings(French) Main iPad storyboard E Main_iPad storyboard(Base) 9 Main_ iPad. strings (French) Controller Stanford CS193 Fall 2013 Internationalization o What about strings not in storyboards? i. e. literal strings @string Replace them with a variant of NSLocalizedString NSString *NSLocalizedStringWithDefaultvalue(NSString *key, NSString *table NSString *bundle, NSString *defaultvalue NSString *comment);// comment is for localizers Also NSLocalizedStringFromTableInBundle()(defaultvalue is the key and NSLocalizedStringFromTable()(defaultvalue is the key and uses mainBundle and NSLocalizedSt ring()(defaultvalue is key; mainBund le; table Localizable strings) Example: Change @"hello"to NSLocalizedString(@"hello",@"Greeting at start of application. " o What these macros do They send this method to [NSBundle mainBundlel ( or the specified bundle if macro takes one) (NSString *)localizedString Forkey: (NSString *)key value: (NSString *)defaultValue //if nil, will be key table: (NSString *)tableName // if nil: Localizable, strings Stanford CS193 Fall 2013 Localization o Generating. strings files with genstrings Once you have used NSLocalizedstring and its variants to eliminate literal strings You can use the command line utility genstrings to generate strings files from .m files cd <directory where all your m files are> genstrings *. m Example: NSLocalizedstring(@ hello",@Greeting at start of application.") would generate an entry in Localizable strings which looks like this /x Greeting at start of application.*/ Localization hell hello Localize a Drag the. strings into Xcode and then inspect to Localize Hit the button"Localize" in the File Inspector on the strings file or storyboard You can then pick languages for which there is a localization set up for your application. (As per the first slide on this topic. Localization E.g., French localizers would change entry to"hello"="bonjour English French Stanford CS193 Fall 2013 Bundles o Resources are drawn from a"bundle" using the users locale Inside a bundle, there will be". proj"directories (e.g. en. proj, fr. proj, etc.) Inside these .proj directories, there will be. strings files, images, sounds, etc When you get a path to a file from a bundle, it tries top-level first, then searches lprojs (depending on the language the user has chosen for his system in Settings app) a Bundles can be associated with a framework or an application 6 Using NSBundle API to get a resource(e.g. an image or sound) NSBundle *bundle [NSBundle bundleForClass: [self class]l NSString *path [bundle path ForResource: @" speedlimit ofType: @"jpg"I bundleForClass: knows whether that class came from a framework or just with the application Stanford CS193 Fall 2013 Localization o Debugging Set the NSUserDefault NS ShowNonLocalizedStrings to YES and a message will be logged to the console whenever these NSLocalizedString methods cannot find a string o Build Clean If changes you make to. strings files dont seem to be appearing when you run . try Build Clean Usually this is not necessary, but it's something to try if things get out of sync Stanford CS193 Fall 2013

试读 24P [IOS7开发]Title: Lecture 18: Core Motion, Image Picker, Localization
立即下载 低至0.43元/次 身份认证VIP会员低至7折
关注 私信
[IOS7开发]Title: Lecture 18: Core Motion, Image Picker, Localization 7积分/C币 立即下载
[IOS7开发]Title: Lecture 18: Core Motion, Image Picker, Localization第1页
[IOS7开发]Title: Lecture 18: Core Motion, Image Picker, Localization第2页
[IOS7开发]Title: Lecture 18: Core Motion, Image Picker, Localization第3页
[IOS7开发]Title: Lecture 18: Core Motion, Image Picker, Localization第4页
[IOS7开发]Title: Lecture 18: Core Motion, Image Picker, Localization第5页

试读结束, 可继续读3页

7积分/C币 立即下载 >