Mark up code zones to replace them with code that’s localized for the current user.
- Swift Playgrounds 3.0+
If you’re writing a playground book for distribution in multiple locales, you can localize the comments and string literals on each page using a comment syntax that delimits a zone for localization.
Add Localization Delimiters
Specify the code you want to make localizable by wrapping it within a delimiter; for example:
Each delimiter carries a unique zone identifier (for example,
welcome2, and so forth) that matches an entry in the
Localizable file you define for each page.
You can also use inline comment delimiters to make string literals localizable; for example:
Create a Localization Strings File
When a user opens a page in your book, the system looks in the appropriate language directory (for example, the page’s
Private directory for strings localized in German) for the
Localizable file. It then matches the delimeters with their corresponding zone ID, and substitutes the text string in the page with the localized text.
Format localization strings files as a list of localization identifiers followed by the localized string. The following example defines localized forms of the content identified by
Localized versions of comments and strings appear on devices set to the appropriate locale: