MOTOSHARE 🚗🏍️

Rent Bikes & Cars Directly from Owners

Motoshare connects vehicle owners with people who need bikes and cars on rent. Owners earn from idle vehicles, and renters get flexible ride options.

Visit Motoshare

Mastering Localizable.xcstrings for iOS Localization

Uncategorized

Apple has always emphasized building apps that feel native to users worldwide. One powerful tool that simplifies this process is Localizable.xcstrings, introduced by Apple as a modern replacement for the older .strings files. This guide explains what Localizable.xcstrings is, its purpose, architecture, workflow, and how you can get started.


🔍 What is Localizable.xcstrings?

Localizable.xcstrings is a structured localization file format introduced by Apple in Xcode 12 and iOS 14+. It replaces traditional .strings files with a key-value JSON format, enhancing localization support with metadata, context, pluralization, and variant handling.

This format works with Xcode’s String Catalog, providing a more intuitive and scalable way to manage localized content across languages and regions.

Key Benefits Over .strings:

  • Supports contextual information for translators
  • Handles pluralization and formatting natively
  • Fully integrated into Xcode’s localization workflow
  • Reduces errors and ambiguities in translation

💡 Major Use Cases of Localizable.xcstrings

1. App Localization

Translate app UI text, labels, alerts, tooltips, and other interface strings into multiple languages seamlessly.

2. Dynamic Content Presentation

Localize plural forms (e.g., 1 item vs. 2 items) using Apple’s ICU-based syntax.

3. Enhanced Translator Experience

Provide context and notes for translators directly within the localization file.

4. Team Collaboration

Facilitates better coordination between developers, designers, and translators by reducing ambiguity in translations.

5. Automated Export/Import

Streamline translation workflows using Xcode or third-party tools to export .xcstrings to common translation platforms.


🏗 How Localizable.xcstrings Works (with Architecture)

📦 Architecture Overview:

  1. Xcode Source Code & UI Strings
    • Developers annotate localizable strings using NSLocalizedString or Swift String(localized:).
  2. Localization Extraction
    • Xcode extracts these strings into a centralized .xcstrings file using a structured JSON format.
  3. String Catalog (Strings Dict)
    • The .xcstrings file stores translation keys with:
      • Base string
      • Context (optional)
      • Variants (plural, gender, etc.)
      • Comments for translators
  4. Runtime Resolution
    • At runtime, iOS selects the appropriate localized string based on the device’s language settings.
  5. App Delivery
    • Compiled .xcstrings become part of the app bundle, loaded dynamically at runtime.

🧬 Sample Structure of Localizable.xcstrings

{
  "example.string": {
    "localizations": {
      "en": {
        "stringUnit": {
          "value": "Hello, World!",
          "comment": "Greeting shown on the main screen"
        }
      },
      "es": {
        "stringUnit": {
          "value": "¡Hola, Mundo!",
          "comment": "Saludo que se muestra en la pantalla principal"
        }
      }
    }
  }
}


🔄 Basic Workflow of Localizable.xcstrings

Step-by-Step Workflow:

  1. Define Strings in Code Use NSLocalizedString or Swift’s native String(localized:).
  2. Create .xcstrings via String Catalog In Xcode, go to File → New → File → String Catalog → Name it Localizable.
  3. Add Locales In the File Inspector, click “Localize…” and add required languages (e.g., French, German).
  4. Edit Translations Input translations in the table-like UI or JSON structure. Add notes for translators if needed.
  5. Export/Import for Translation Export .xliff for translation and re-import once translations are complete.
  6. Build & Test Build the app and run in different locales using Xcode scheme settings or simulator.

🚀 Step-by-Step Getting Started Guide

🛠️ Step 1: Create a String Catalog

  1. Open Xcode → File → New → File → String Catalog
  2. Name it Localizable.xcstrings
  3. Click “Create”

🌐 Step 2: Localize Your Catalog

  1. Select the .xcstrings file in the navigator.
  2. Go to File Inspector (right panel).
  3. Click “Localize…”
  4. Choose the base language (e.g., English).
  5. Then click “+” to add other languages.

✍️ Step 3: Add Translatable Strings

In code:

Text("welcome.message") // With localization

In your .xcstrings, this key (welcome.message) is added automatically if using String(localized:) in Swift.

Manually in JSON format:

{
  "welcome.message": {
    "localizations": {
      "en": {
        "stringUnit": {
          "value": "Welcome to our app!",
          "comment": "Shown on the welcome screen"
        }
      },
      "fr": {
        "stringUnit": {
          "value": "Bienvenue dans notre application!",
          "comment": "Affiché à l'écran de bienvenue"
        }
      }
    }
  }
}


🔁 Step 4: Export for Translation

  1. In Xcode: Product → Export for Localization
  2. Choose .xliff format for translators
  3. Share and later re-import using Product → Import Localizations

🧪 Step 5: Test Translations

  1. Run your app
  2. Change the device or simulator language
  3. Verify the localized content appears correctly
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x