How We Added Internationalization and Multi-Language Support to Our macOS App


How We Added Internationalization and Multi-Language Support to Our macOS App

 

Supporting multiple languages is essential for reaching a global audience. In this post, we’ll walk through how we added internationalization (i18n) and Chinese localization to our macOS app, iTrans, using Swift and Xcode.

1. Audit All User-Facing Text

The first step was to identify all user-facing strings in our codebase. We searched through our SwiftUI views, models, and operators for any hardcoded text that would be visible to users.

2. Extract Strings for Localization

We replaced all hardcoded strings with localization-friendly APIs:

  • For SwiftUI, we used LocalizedStringKey in Text views.
  • For other strings, we used NSLocalizedString.


Text(LocalizedStringKey("Unlock your iPhone"))
// or
NSLocalizedString("Untitled", comment: "File with no name")

3. Create Localization Files

We created Localizable.strings files for each supported language:

  • en.lproj/Localizable.strings for English
  • zh-Hans.lproj/Localizable.strings for Simplified Chinese
Each file contains key-value pairs for all user-facing text.

Example (English):


"Unlock your iPhone" = "Unlock your iPhone";
Example (Chinese):

"Unlock your iPhone" = "解锁你的 iPhone";

4. Add Localization Files to the Xcode Project

To ensure Xcode recognizes the localization files:

  • We added both Localizable.strings files to the project via the Project Navigator.
  • In the File Inspector, we enabled localization for each file and checked all supported languages.

5. Test Localization

Xcode makes it easy to test your app in different languages:

  • In the scheme editor, we set the Application Language to Chinese (Simplified) and ran the app.
  • We also verified that all UI text appeared correctly in both English and Chinese.

6. Results

With these steps, our app now fully supports both English and Chinese. All user-facing text is localized, and switching languages is seamless for users.


Conclusion:
Internationalization in Swift and Xcode is straightforward when you follow best practices: extract all user-facing text, use localization APIs, maintain .strings files for each language, and test thoroughly. This approach ensures your app is ready for a global audience.

❤️ Support This Blog


If this post helped you, you can support my writing with a small donation. Thank you for reading.


Comments

Popular posts from this blog

fixed: embedded-redis: Unable to run on macOS Sonoma

Copying MDC Context Map in Web Clients: A Comprehensive Guide

Reset user password for your own Ghost blog