SlideShare a Scribd company logo
Avoiding Pitfalls with
Internationalization & Localization
Nashville CocoaHeads - August 26th, 2015
What We’ll Cover
• Internationalization vs Localization
• Content Types
• Text
• Dates
• Numbers
• Images
• Directionality
• Xcode Tips & Tricks
Why do it?
• The App Store is available in over 150 countries.
• 69% of app revenue comes from outside the U.S.
• Some users may speak English, but it may not be
their primary language.
Internationalization
vs
Localization
• Localization is the process of translating your app
into multiple languages.
• Internationalization is the process of making your
app able to adapt to different languages, regions,
and cultures.
Text
Strings Tables
• Translated text is stored in strings tables.
• Localizable.strings
• Key value pairs
• XLIFF format
XLIFF
<file original="InternationalizationExample/Localizable.strings" source-language="en" datatype="plaintext"
target-language="es">
<header>
<tool tool-id="com.apple.dt.xcode" tool-name="Xcode" tool-version="6.4" build-num="6E35b"/>
</header>
<body>
<trans-unit id="Invalid Password">
<source>Invalid Password</source>
<target>Contraseña invalida</target>
<note>Title of the alert that is displayed when the user enters an invalid password.</note>
</trans-unit>
<trans-unit id="Please enter a password.">
<source>Please enter a password.</source>
<target>Por favor, introduzca una contraseña .</target>
<note>Instructions displayed when the user enters an invalid password.</note>
</trans-unit>
</body>
</file>
XML Localisation Interchange File Format
NSLocalizedString
• Parameters:
• Key - The key to use in the strings table.
• Comment - Provides context for translators.
<trans-unit id="Invalid Password">
<source>Invalid Password</source>
<target>Contraseña invalida</target>
<note>Title of the alert that is displayed when the user enters
an invalid password.</note>
</trans-unit>
NSLocalizedString(“Invalid Password”, comment: “Title of the alert
that is displayed when the user enters an invalid password.”)
Format Strings
[NSString localizedStringWithFormat:
NSLocalizedString(@“%@ is %d meters tall”, @“Name and
height (in meters) of a mountain”), mountain.name,
mountain.height];
<source>%@ is %d meters tall</source>
<target>%1$@ is %2$d meters tall</target>
<note>Name and height (in meters) of a mountain</note>
NSLocalizedString and DRY
• Don’t copy and paste NSLocalizedString macros/
functions everywhere if they are textually and
semantically the same.
• Instead of creating a constant for the key, create a
constant for the localized string. Otherwise, it won’t
be included in the XLIFF file when exported.
This string won’t get exported:
struct Constants {
struct Localization {
static let OkButtonTitle = "Ok"
}
}
let okButtonTitle = NSLocalizedString(Constants.Localization.OkButtonTitle,
comment: "Title of button to dismiss an alert")
This string will get exported and you only write the
comment once:
struct Constants {
struct Localization {
static let OkButtonTitle = NSLocalizedString("Ok", comment: "Title of
button to dismiss an alert")
}
}
let okButtonTitle = Constants.Localization.OkButtonTitle
Dates
NSDateFormatter
• Avoid format strings for user-visible dates
• Use Apple’s format styles
US English Aug 26, 2015
UK English Aug 26, 2015
Chinese 8⽉月 26, 2015
let df = NSDateFormatter()
df.dateFormat = “MMM d, y”
US English Aug 26, 2015
UK English 26 Aug 2015
Chinese 2015年8⽉月26⽇日
let df = NSDateFormatter()
df.dateStyle = .MediumStyle
Apple’s default styles don’t fit
your need?
let df = NSDateFormatter()
df.setLocalizedDateFormatFromTemplate("MMM d")
Numbers
NSNumberFormatter
• Just like NSDateFormatter, it is locale-sensitive
• NSNumberFormatter:
• +localizedStringFromNumber:numberStyle:
• NSString:
• +localizedStringWithFormat:
US English 1,234.56
France 1 234,56
Arabic ١٬٢٣٤٫٥٦
Currency
When using the currency style, the currency symbol
will change as well. No currency conversion is
performed. ($5 != £5)
Other Units
• NSMassFormatter
• NSEnergyFormatter
• And many more…
US English 44.092 pounds
Italian 20 chilogrammi
let weight = 20.0 // Store weight in metric units
let massFormatter = NSMassFormatter()
massFormatter.unitStyle = .Long
let formatted = massFormatter.stringFromKilograms(weight)
Images
Tips
• Avoid using images with text in them.
• Avoid image based puns. (🐝 Clever)
• Consider regional differences. A red octagon
symbolizes “stop” in the US, but in Japan, stop
signs are triangular.
Accessing Localized
Resources (iOS 9)
Don’t access the directories manually:
let lang = NSLocale.preferredLanguages().firstObject!
let lprojPath = lang.stringByAppendingPathExtension("lproj")
let filePath = NSBundle.mainBundle().pathForResource("stopSign", ofType: "png",
inDirectory: lprojPath)
NSBundle.mainBundle().imageForResource("stopSign")
NSBundle.mainBundle().pathForSoundResource("greeting")
NSBundle.mainBundle().URLForResource("help", withExtension: "pdf")
Use the NSBundle methods:
Directionality
Directionality
• Some languages such as Arabic or Hebrew are read
from right to left.
• AutoLayout leading and trailing constraints
cause views to automatically flip.
• To prevent flipping your UI, use right and left
attributes on your constraints instead of leading
and trailing.
What not to flip
• Video controls and timeline indicators
• Images, unless they communicate a sense of
direction, such as arrows
• Clocks
• Music notes and sheet music
• Graphs (x– and y–axes always appear in the same
orientation)
General Tips
Accessibility
Don’t forget to localize accessibility labels!
Sorting
• Use the “localizedStandardCompare:” selector for
sort descriptors used on user-facing strings. This will
sort according to the language rules of the current
locale.
compare: A, Ä, B, C, a, ä, b, c
localizedCaseInsensitiveCompare: A, a, b, B, c, C, ä, Ä
localizedStandardCompare: a, A, b, B, c, C, ä, Ä
Xcode Tips
Presentation continues in Xcode

More Related Content

PPTX
WEB DEVELOPMENT
PPT
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
PPTX
Oh , I broke the build!
PDF
Advancing Your Custom Fields - WordCamp 2014
PPTX
You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...
PDF
Ebook Accessibility: Why, How, and What For - ebookcraft 2016 - Laura Brady
PPTX
FFW Gabrovo PMG - jQuery
PPTX
FFW Gabrovo PMG - JavaScript 1
WEB DEVELOPMENT
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
Oh , I broke the build!
Advancing Your Custom Fields - WordCamp 2014
You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...
Ebook Accessibility: Why, How, and What For - ebookcraft 2016 - Laura Brady
FFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - JavaScript 1

What's hot (20)

PDF
Web Frameworks
PPT
EPUB vs. WEB: A Cautionary Tale - ebookcraft 2016 - Tzviya Siegman & Dave Cramer
PDF
#eprdctn tools & tips round up
PPT
Xml dom & sax by bhavsingh maloth
PPTX
CSS Overview and Examples
PPTX
Xml processors
PPTX
F# type providers
PPT
Andromeda
PDF
Web front end development introduction to html css and javascript
PPTX
FFW Gabrovo PMG - HTML
PDF
The beauty behind ebooks: CSS - ebookcraft 2015 - Iris Febres
KEY
Tenacity
PPT
AJAX Workshop Notes
PPT
Web development basics (Part-1)
PPTX
Python assignment help
PPT
JavaScript Workshop
PPT
HTML & CSS Workshop Notes
PPTX
PPT
XML and XSLT
PDF
Html css workshop, lesson 0, how browsers work
Web Frameworks
EPUB vs. WEB: A Cautionary Tale - ebookcraft 2016 - Tzviya Siegman & Dave Cramer
#eprdctn tools & tips round up
Xml dom & sax by bhavsingh maloth
CSS Overview and Examples
Xml processors
F# type providers
Andromeda
Web front end development introduction to html css and javascript
FFW Gabrovo PMG - HTML
The beauty behind ebooks: CSS - ebookcraft 2015 - Iris Febres
Tenacity
AJAX Workshop Notes
Web development basics (Part-1)
Python assignment help
JavaScript Workshop
HTML & CSS Workshop Notes
XML and XSLT
Html css workshop, lesson 0, how browsers work
Ad

Similar to Avoiding Pitfalls with Internationalization & Localization (20)

PDF
iOS localization
PDF
Mobile Warsaw - Efficient Localization for iOS Apps
PDF
Localization and Accessibility on iOS
PDF
Localization Realization
PDF
Beginning iOS App Localization
PDF
Localizing Mobile Apps
PDF
Internationalizing Your Apps
PDF
How do I - Localization and Internationalization (l10n, i18n) - Transcript.pdf
PPT
Cultural Awareness, Localization and the Impact on Content Creation of User I...
PDF
Localizing iOS Apps
PPTX
Localization for iOS
PDF
Best Practices for Software Localization
KEY
iOS Localization
PPTX
Localization and Shared Preferences in android
PDF
Improve your app localization
PDF
Designing Products for International Markets
PDF
This talk lasts 三十分钟
PPT
Software Internationalization & Localization: Basic Concepts
PDF
Localization of iPhone Apps
PDF
Tricks and Tips for Adding Localization Features to Your Mobile Apps
iOS localization
Mobile Warsaw - Efficient Localization for iOS Apps
Localization and Accessibility on iOS
Localization Realization
Beginning iOS App Localization
Localizing Mobile Apps
Internationalizing Your Apps
How do I - Localization and Internationalization (l10n, i18n) - Transcript.pdf
Cultural Awareness, Localization and the Impact on Content Creation of User I...
Localizing iOS Apps
Localization for iOS
Best Practices for Software Localization
iOS Localization
Localization and Shared Preferences in android
Improve your app localization
Designing Products for International Markets
This talk lasts 三十分钟
Software Internationalization & Localization: Basic Concepts
Localization of iPhone Apps
Tricks and Tips for Adding Localization Features to Your Mobile Apps
Ad

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
KodekX | Application Modernization Development
PDF
Approach and Philosophy of On baking technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Cloud computing and distributed systems.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
MIND Revenue Release Quarter 2 2025 Press Release
Building Integrated photovoltaic BIPV_UPV.pdf
The AUB Centre for AI in Media Proposal.docx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Programs and apps: productivity, graphics, security and other tools
Understanding_Digital_Forensics_Presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KodekX | Application Modernization Development
Approach and Philosophy of On baking technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Cloud computing and distributed systems.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Avoiding Pitfalls with Internationalization & Localization

  • 1. Avoiding Pitfalls with Internationalization & Localization Nashville CocoaHeads - August 26th, 2015
  • 2. What We’ll Cover • Internationalization vs Localization • Content Types • Text • Dates • Numbers • Images • Directionality • Xcode Tips & Tricks
  • 3. Why do it? • The App Store is available in over 150 countries. • 69% of app revenue comes from outside the U.S. • Some users may speak English, but it may not be their primary language.
  • 4. Internationalization vs Localization • Localization is the process of translating your app into multiple languages. • Internationalization is the process of making your app able to adapt to different languages, regions, and cultures.
  • 6. Strings Tables • Translated text is stored in strings tables. • Localizable.strings • Key value pairs • XLIFF format
  • 7. XLIFF <file original="InternationalizationExample/Localizable.strings" source-language="en" datatype="plaintext" target-language="es"> <header> <tool tool-id="com.apple.dt.xcode" tool-name="Xcode" tool-version="6.4" build-num="6E35b"/> </header> <body> <trans-unit id="Invalid Password"> <source>Invalid Password</source> <target>Contraseña invalida</target> <note>Title of the alert that is displayed when the user enters an invalid password.</note> </trans-unit> <trans-unit id="Please enter a password."> <source>Please enter a password.</source> <target>Por favor, introduzca una contraseña .</target> <note>Instructions displayed when the user enters an invalid password.</note> </trans-unit> </body> </file> XML Localisation Interchange File Format
  • 8. NSLocalizedString • Parameters: • Key - The key to use in the strings table. • Comment - Provides context for translators. <trans-unit id="Invalid Password"> <source>Invalid Password</source> <target>Contraseña invalida</target> <note>Title of the alert that is displayed when the user enters an invalid password.</note> </trans-unit> NSLocalizedString(“Invalid Password”, comment: “Title of the alert that is displayed when the user enters an invalid password.”)
  • 9. Format Strings [NSString localizedStringWithFormat: NSLocalizedString(@“%@ is %d meters tall”, @“Name and height (in meters) of a mountain”), mountain.name, mountain.height]; <source>%@ is %d meters tall</source> <target>%1$@ is %2$d meters tall</target> <note>Name and height (in meters) of a mountain</note>
  • 10. NSLocalizedString and DRY • Don’t copy and paste NSLocalizedString macros/ functions everywhere if they are textually and semantically the same. • Instead of creating a constant for the key, create a constant for the localized string. Otherwise, it won’t be included in the XLIFF file when exported.
  • 11. This string won’t get exported: struct Constants { struct Localization { static let OkButtonTitle = "Ok" } } let okButtonTitle = NSLocalizedString(Constants.Localization.OkButtonTitle, comment: "Title of button to dismiss an alert") This string will get exported and you only write the comment once: struct Constants { struct Localization { static let OkButtonTitle = NSLocalizedString("Ok", comment: "Title of button to dismiss an alert") } } let okButtonTitle = Constants.Localization.OkButtonTitle
  • 12. Dates
  • 13. NSDateFormatter • Avoid format strings for user-visible dates • Use Apple’s format styles
  • 14. US English Aug 26, 2015 UK English Aug 26, 2015 Chinese 8⽉月 26, 2015 let df = NSDateFormatter() df.dateFormat = “MMM d, y” US English Aug 26, 2015 UK English 26 Aug 2015 Chinese 2015年8⽉月26⽇日 let df = NSDateFormatter() df.dateStyle = .MediumStyle
  • 15. Apple’s default styles don’t fit your need? let df = NSDateFormatter() df.setLocalizedDateFormatFromTemplate("MMM d")
  • 17. NSNumberFormatter • Just like NSDateFormatter, it is locale-sensitive • NSNumberFormatter: • +localizedStringFromNumber:numberStyle: • NSString: • +localizedStringWithFormat: US English 1,234.56 France 1 234,56 Arabic ١٬٢٣٤٫٥٦
  • 18. Currency When using the currency style, the currency symbol will change as well. No currency conversion is performed. ($5 != £5)
  • 19. Other Units • NSMassFormatter • NSEnergyFormatter • And many more… US English 44.092 pounds Italian 20 chilogrammi let weight = 20.0 // Store weight in metric units let massFormatter = NSMassFormatter() massFormatter.unitStyle = .Long let formatted = massFormatter.stringFromKilograms(weight)
  • 21. Tips • Avoid using images with text in them. • Avoid image based puns. (🐝 Clever) • Consider regional differences. A red octagon symbolizes “stop” in the US, but in Japan, stop signs are triangular.
  • 22. Accessing Localized Resources (iOS 9) Don’t access the directories manually: let lang = NSLocale.preferredLanguages().firstObject! let lprojPath = lang.stringByAppendingPathExtension("lproj") let filePath = NSBundle.mainBundle().pathForResource("stopSign", ofType: "png", inDirectory: lprojPath) NSBundle.mainBundle().imageForResource("stopSign") NSBundle.mainBundle().pathForSoundResource("greeting") NSBundle.mainBundle().URLForResource("help", withExtension: "pdf") Use the NSBundle methods:
  • 24. Directionality • Some languages such as Arabic or Hebrew are read from right to left. • AutoLayout leading and trailing constraints cause views to automatically flip. • To prevent flipping your UI, use right and left attributes on your constraints instead of leading and trailing.
  • 25. What not to flip • Video controls and timeline indicators • Images, unless they communicate a sense of direction, such as arrows • Clocks • Music notes and sheet music • Graphs (x– and y–axes always appear in the same orientation)
  • 27. Accessibility Don’t forget to localize accessibility labels!
  • 28. Sorting • Use the “localizedStandardCompare:” selector for sort descriptors used on user-facing strings. This will sort according to the language rules of the current locale. compare: A, Ä, B, C, a, ä, b, c localizedCaseInsensitiveCompare: A, a, b, B, c, C, ä, Ä localizedStandardCompare: a, A, b, B, c, C, ä, Ä