Skip to content

Xcode .stringsdict Localization

Lingo.dev supports Xcode's .stringsdict format, which is crucial for handling pluralization and other variable substitutions in your iOS, macOS, watchOS, and visionOS apps.

Setting Up

To use Lingo.dev with .stringsdict files, configure your i18n.json as follows:

json
{
  "version": 1.2,
  "locale": {
    "source": "en",
    "targets": ["es", "fr", "de"]
  },
  "buckets": {
    "xcode-stringsdict": {
      "include": ["MyApp/[locale].lproj/Localizable.stringsdict"]
    }
  }
}

TIP

Note the use of [locale] in the path, which Lingo.dev will replace with the appropriate locale code.

How It Works

The .stringsdict file is an XML-based plist format that Xcode uses for complex localizations, especially for pluralization. Lingo.dev parses this format, translates the content, and generates new .stringsdict files for each target language.

Here's an example of a .stringsdict file structure:

xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>key</key>
  <dict>
    <key>NSStringLocalizedFormatKey</key>
    <string>%#@count@</string>
    <key>count</key>
    <dict>
      <key>NSStringFormatSpecTypeKey</key>
      <string>NSStringPluralRuleType</string>
      <key>NSStringFormatValueTypeKey</key>
      <string>d</string>
      <key>zero</key>
      <string>No items</string>
      <key>one</key>
      <string>One item</string>
      <key>other</key>
      <string>%d items</string>
    </dict>
  </dict>
</dict>
</plist>

Lingo.dev parses this format, translates the content, and generates new .stringsdict files for each target language.

Localizing

To localize your .stringsdict files, run:

bash
npx lingo.dev@latest i18n

Lingo.dev will process your source .stringsdict file and create or update the target language files.

Features

  1. Pluralization: Lingo.dev handles complex pluralization rules, including zero, one, two, few, many, and other forms.

  2. Variable Substitution: The loader preserves format specifiers like %lld and %@.

  3. XML Structure: Lingo.dev maintains the correct XML and plist structure required by Xcode.

  4. Incremental Updates: Only new or changed strings are translated, saving time and processing power.

Pro Tips

  1. Consistency with .strings and .xcstrings: Ensure your pluralization keys in .stringsdict match those in your .strings or .xcstrings files for proper integration in your app.

  2. Language-Specific Plural Rules: Be aware that different languages have different pluralization rules. Lingo.dev handles these differences automatically.

  3. Multiple Files: If your project uses multiple .stringsdict files, you can include them all in your i18n.json config:

    json
    "xcode-stringsdict": {
      "include": [
        "MyApp/[locale].lproj/Localizable.stringsdict",
        "MyApp/[locale].lproj/InfoPlist.stringsdict"
      ]
    }

By leveraging these features and tips, you can maintain a robust, scalable localization setup for your Xcode projects using the .stringsdict format, seamlessly integrating with your existing development workflow.

For more information on other Xcode localization formats supported by Lingo.dev, check out the documentation for .xcstrings and .strings files.