Day 50: Stanford CS193p – Internationalization and Settings

Day 50: CS193p – Internationalization and Settings

Screen Shot 2015-06-29 at 8.11.58 PM

Lecture 17!!!

Making our app marketable around the world!

Screen Shot 2015-06-29 at 11.28.20 PM

adding UI to General Settings application


2 steps to international versions of app

process making strings externally
involves using certain “formatting” classes for things like dates, numbers, etc
developers do this side of it

process of translating those external strings
usually hire localization company to do this work

Storyboards localized by changing strings inside only”
rely on Autolayout to make it look nice

Registering Localizable Languages
*Project pane in xCode, in Navigator, then Info tab to add Localization

Storyboards in Navigator will now support “localizations”

What about strings not in storyboards?
literal strings “string”
replace with calls to NSLocalizedString()

Most of the parameters have good defaults:
let localString = NSLocalizedString(“Foo”, comment: “This string is shown when..”)
Bundle defaults to NSBundle.mainBundle() and tableName to “Localizable”

Strings created from a format(println-like) string:
any string created for UI with a format string, should use method:
let string = String.localizedStringWithFormat(NSLocalizedString(“the result is %g”, comment: “gives numeric result to the user”), theNumber)

Localizers can specify the order of arguments like this:
“result number %d is %d = “%2$d is the result at position %1$d”

formatting for locale:
locale is a region of world
separate from language
app might be localized to Spanish, but user might be in Spain or Mexico
regions might display things differently: numbers, dates, currency

iOS will format these things for you if you let it:
but must use appropriate formatter class

lots here, check documentation

Displaying numbers:
let formatter = NSNumberFormatter()
var numberStyle: NSNumberFormatterStyle
let stringToDisplay = formatter.stringFromNumber(theNumber)

Parsing numbers:
formatter.numberStyle = .DecimalStyle
let parsedNumber = formatter.numberFromString(userInputtedString) {}

Dates complicated:
var timeStyle: NSDateFormatterStyle
var dataStyle: NSDateFormatterStyle
.ShortStyle or .MediumStyle or .LongStyle or .FullStyle or .NoStyle

Localizing images:
File Inspector (made localized)
keep in Images.xcassets and use NSLocalizedString for image name

By now the app is Internationalized
generate .xliff file for each language
.xliff will contain all strings and comments
.xliff comes back from localizer, import it
then export/import/export/import without losing any translations

new for iOS8

Previewing a Localization:
in xCode, if want to see storyboard localized
create “Scheme” to Run app in that language

That’s it!

Screen Shot 2015-06-29 at 10.55.19 PM

Get Autolayout right
Get NSLocalizedString calls in there
Use formatters


Lecture went into demo mode to demonstrate all of the above. It was very helpful in putting all this new information into some sorta context.


Only appropriate for rarely used settings or default behavior
appears in via NSUserDefaults
specify the UI and the associated defaults in property list file

Adding settings specific to our app:
very limited possibilities

A “sample” settings bundle is created:
check documentation for all possibilities
sample is a good place to start when trying to understand how things work

Localization of Settings:
create strings file inside the .lproj directories in Settings bundle
send them to your translators separately from the .xliffs

Demo mode for Settings

Screen Shot 2015-06-29 at 11.44.39 PM


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s