let localizedString =
NSLocalizedString("dot.swift.localizedString", comment:
“NSLocalizedString OMG")
Slide 15
Slide 15 text
NOT ENOUGH
Slide 16
Slide 16 text
EXAMPLES
PRACTICAL TIPS
Slide 17
Slide 17 text
No content
Slide 18
Slide 18 text
No content
Slide 19
Slide 19 text
Currency
Slide 20
Slide 20 text
No content
Slide 21
Slide 21 text
let cash = 3.50
let cashString = String(format:
"€%.2f", arguments: [cash])
€3.50 3,50 €
X
Slide 22
Slide 22 text
NSNumberFormatter
Slide 23
Slide 23 text
let numberFormatter = NSNumberFormatter()
numberFormatter.numberStyle = .CurrencyStyle
numberFormatter.currencyCode = "EUR"
let cashString = numberFormatter.stringFromNumber(3.50)
3,50 €
Slide 24
Slide 24 text
NSNumberFormatter
DecimalStyle
CurrencyStyle
PercentStyle
ScientificStyle
SpellOutStyle
OrdinalStyle
CurrencyISOCodeStyle
CurrencyPluralStyle
CurrencyAccountingStyle
Use NSNumberFormatter every
time you are including a Double
or Float in a string
Mock up UI by doubling all
strings. Auto layout helps.
Slide 32
Slide 32 text
No content
Slide 33
Slide 33 text
No content
Slide 34
Slide 34 text
Capitalization
Slide 35
Slide 35 text
let turkey = "Türkiye"
let TURKEY = turkey.uppercaseString
TÜRKIYE TÜRKİYE
X
Slide 36
Slide 36 text
.localizedUppercaseString
(iOS9+)
Slide 37
Slide 37 text
let turkey = "Türkiye"
let TURKEY =
turkey.localizedUppercaseString
TÜRKİYE
Slide 38
Slide 38 text
.uppercaseStringWith
Locale()
(iOS6+)
Slide 39
Slide 39 text
When changing string
capitalization, always use
the localized variation
localizedUppercaseString()
localizedLowercaseString()
localizedCapitalizedString()
Slide 40
Slide 40 text
No content
Slide 41
Slide 41 text
No content
Slide 42
Slide 42 text
Plurals
Slide 43
Slide 43 text
if n == 1 {
secondString = "\(n) second"
}
else {
secondString = "\(n) seconds"
}
X
is 1: 1
is 2: 2
is 3-6: 3, 4, 5, 6
is 7-10: 7, 8, 9, 10
everything else: 0, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23 …
Slide 46
Slide 46 text
.stringsdict
(iOS7+)
Slide 47
Slide 47 text
dot.swift.plural
NSStringLocalizedFormatKey
%#@items@
items
NSStringFormatSpecTypeKey
NSStringPluralRuleType
NSStringFormatValueTypeKey
d
one
Установ. для %d выбранных друзей
few
Установ. для %d выбранных друзей
other
Установ. для %d выбранных друзей
Slide 48
Slide 48 text
One, two, few, many,
other
Slide 49
Slide 49 text
let localizedString = NSLocalizedString("dot.swift.plural",
comment: "Установ. для %d выбранных друзей")
let pluralString =
String.localizedStringWithFormat(localizedString, [number])
Slide 50
Slide 50 text
Use .stringsdict for plural
localized strings.
Slide 51
Slide 51 text
No content
Slide 52
Slide 52 text
No content
Slide 53
Slide 53 text
Address
Slide 54
Slide 54 text
Roy Marmelstein
The Stage
Dot.Swift
Théâtre des Variétés
8 boulevard Montmartre
75002 Paris
France
X
Slide 55
Slide 55 text
75002 Paris
8 boulevard Montmartre
Théâtre des Variétés
Dot.Swift
The Stage
Roy Marmelstein
Slide 56
Slide 56 text
CNPostalAddressFormatter
(iOS9+)
Slide 57
Slide 57 text
let postalFormatter = CNPostalAddressFormatter()
let postalAddress = CNMutablePostalAddress()
postalAddress.street = "8 boulevard Montmartre"
postalAddress.city = "Paris"
postalAddress.state = "Ile de France"
postalAddress.postalCode = "75002"
postalAddress.country = "France"
postalAddress.ISOCountryCode = "FR"
let addressString =
postalFormatter.stringFromPostalAddress(postalAddress)
Slide 58
Slide 58 text
Address formatter is hidden in
Contacts. Use it when
displaying addresses.
Slide 59
Slide 59 text
No content
Slide 60
Slide 60 text
No content
Slide 61
Slide 61 text
Distance + weight
Slide 62
Slide 62 text
Inch, foot, yard, mile.
Ounce, pound.
Slide 63
Slide 63 text
MKDistanceFormatter
Slide 64
Slide 64 text
let distance: CLLocationDistance = 100.0 // in Meters
let distanceFormatter = MKDistanceFormatter()
let localDistance =
distanceFormatter.stringFromDistance(distance)
350 feet
Slide 65
Slide 65 text
NSMassFormatter
Slide 66
Slide 66 text
let weight = 66.0 // in Kg
let massFormatter = NSMassFormatter()
massFormatter.forPersonMassUse = true
let localWeight =
massFormatter.stringFromKilograms(weight)
147.71 lb
Slide 67
Slide 67 text
Distance formatter is hidden in
MapKit. NSMassFormatter can
handle all weights.
Slide 68
Slide 68 text
No content
Slide 69
Slide 69 text
DIDN’T DISCUSS
Left to right. Better with iOS9.
A lot of work.