28

Localization and Accessibility on iOS

Embed Size (px)

Citation preview

LOCALIZATION AND ACCESSIBILITY

AGENDA

Localizing Strings

Localizing Storyboards

Testing Localization

Locales

Accessibility

LOCALIZING STRINGS

LOCALIZING STRINGS

Requires developer to use specific API to retrieve strings in code

Additionally need .strings file with translation for each language

ADDING LOCALIZED STRINGS TO YOUR PROJECT - 1

Generate a localized strings file using the following command:

find . -name \*.swift | xargs genstrings -o .

Searches for all occurrences of NSLocalizedStringand extracts keys and comments into a separate file

ADDING LOCALIZED STRINGS TO YOUR PROJECT - 2

Add the Localizable.strings file to your project:

ADDING LOCALIZED STRINGS TO YOUR PROJECT - 3

Add a new language to your project:

ADDING LOCALIZED STRINGS TO YOUR PROJECT - 4

Add a new localization to your Localizable.strings file:

LOCALIZING STRINGS IN CODE

// Shortest version of NSLocalizedString; comment is used to inform translator // about the role of this string mainLabel.text = NSLocalizedString("com.makeschool.helloString", comment: "The string that greets the user") // Longest version of NSLocalizedString; You can choose which strings file from which // bundle you want to use. You can also provide a default translation value in case // the key cannot be found in the table mainLabel.text = NSLocalizedString("com.makeschool.helloString", tableName: "Other", bundle: NSBundle.mainBundle(), value: "Hello World", comment: "The string that greets the user")

LOCALIZING STORYBOARDS

LOCALIZING STORYBOARDS

TESTING LOCALIZATION

TESTING LOCALIZATION

TESTING LOCALIZATION

TESTING LOCALIZATION

LOCALES

LOCALES

Besides the language, the region we live in influences localization

Examples: Date formatting, currency symbols, time zones

LOCALES

dateLabel.text = NSDateFormatter.localizedStringFromDate(NSDate(), dateStyle: .MediumStyle, timeStyle: .MediumStyle)

23.10.2015, 08:35:31 Oct 23, 2015, 8:26:12 AM

German Locale (de-DE) US Locale (en-US)

ACCESSIBILITY

ACCESSIBILITY

Very important when building custom views! They are not accessible by default: self.isAccessibilityElement = true

Can enhance standard view components by providing hints, labels, traits and values

ACCESSIBILITY

accessibilityLabel short description of the

control, e.g. “Save” for button, “Rating” for label

accessibilityHint helps the user to understand

results of an action. E.g. “Saves the Document”, “Clears

the text”

ACCESSIBILITY

accessibilityTraits collection of constants that

describe the type of control and/or how it should be

treated, e.g: UIAccessibilityTraitImage,

UIAccessibilityTraitNotEnabled, etc.

accessibilityValue Used to describe the value of

a none-label UI component. E.g. “50%” for a progress

bar. “9 out of 10” for a rating view.

ACCESSIBILITY

Accessibility parameters can be defined in Interface Builder and in code!

SUMMARY

SUMMARY

Localization and Accessibility are important to

make your app available to a broader audience

Xcode / iOS provide tooling that allow you to

implement localization and accessibility with very

little effort

ADDITIONAL RESOURCES