<!--
{
  "documentType" : "article",
  "framework" : "Swift Playgrounds",
  "identifier" : "/documentation/Swift-Playgrounds/localizing-code-comments-and-string-literals",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Localizing Code Comments and String Literals"
}
-->

# Localizing Code Comments and String Literals

In Swift Playgrounds 3.0 and later, mark up code zones to replace them with code that’s localized for the current user.

## Overview

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:

```swift
/*
//#-localizable-zone(welcome1)
Welcome!
//#-end-localizable-zone
*/
```

Each delimiter carries a unique *zone identifier* (for example, `welcome1`, `welcome2`,
and so forth) that matches an entry in the `LocalizableCode.strings` file you define
for each page.

You can also use inline comment delimiters to make string literals localizable; for
example:

```swift
let message = "/*#-localizable-zone(welcome2)*/Hello!/*#-end-localizable-zone*/"
```

> Important: Only use localization delimiters to surround code comments and string
> literals. Doing so helps ensure that you don’t introduce locale-sensitive compilation
> errors.

### 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 `PrivateResources/de.lproj` directory for strings
localized in German) for the `LocalizableCode.strings` 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 `welcome1` and `welcome2`:

```other
/* Initial greeting. */
"welcome1" = "Willkommen!";

/* Second greeting. */
"welcome2" = "Guten Tag!";
```

Localized versions of comments and strings appear on devices set to the appropriate
locale:

```swift
/*
Willkommen!
*/

let message = "Guten Tag!"
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)