Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode 9 localization export/import doesn't include NSLocalizedString() or comments

Situation:

We use XCode exporting/importing tools to generate localizable files for our translators. This was going fine in XCode 8. Since we updated to XCode 9 we see a couple of problems.

Problems:

  1. When exporting a localization via Editor-->Export for localization...-->Development language only, it doesn't include NSLocalizedString() key/values as it should according to this documentation: When you export localizations, Xcode searches your code for the macros and includes the strings files in the exported localization file for translation.
  2. Comments that are added to the Localizable.strings development-language file seem to be non-existent in the export .xliff file.
  3. When importing a translated .xliff file, XCode seems to delete all the comments that are in the file. It gets replaced by "(No Comment)"

Configuration:

  • XCode 9.0 (9A235)
  • Dev language: NL
  • Localized languages: Base, NL, DE, BE, LU
  • Objective-C & Swift hybrid project

What I've tried:

  • I have tried looking at XCode 9 documentation or changelog to see what has changed in Localization, though nothing I can find mentions this change
  • I can get my NSLocalizedString() strings to show up in the export when I first generate the development Localizable.strings file manually, by using the commandline command find ./ -name "*.m" -print0 | xargs -0 xcrun extractLocStrings -o . (I run it a second time for .swift files as my project is a swift/objc hybrid). Then combine the results, which let my strings show up in the export, however without comments, which are needed as guides for translators.

Question:

Is this an XCode 9 bug? Did I miss any documentation or new feature/option for localization exports/imports? Are there workarounds?

like image 417
Thermometer Avatar asked Oct 19 '17 13:10

Thermometer


People also ask

What is Nslocalizedstring?

Returns a localized version of a string from the default table, which Xcode autogenerates when exporting localizations. iOS 2.0+ iPadOS 2.0+ macOS 10.0+ Mac Catalyst 13.0+ tvOS 9.0+ watchOS 2.0+

How do you import localization?

Import Localizations Using XcodeIn the Project navigator, select the project, then choose Product > Import Localizations. In the import dialog that appears, select the Xcode Localization Catalog folder, and click Import. Xcode ingests the files and warns you if there are untranslated files.

What is localizable strings?

Localizable. strings stores application strings as key-value pairs for each language. Let's create this file for the base language first. Select File → New → File… or just tap Ctrl+N or Cmd+N .


1 Answers

This is an older question, but I had this same issue with Xcode 10.

The solution is to simply place the strings files (e.g. InfoPlist.strings) in the same folder as plist.info. Only then are existing translations included in localization exports.

Previously I had them in a dedicated "Localizations" group. While this works for the localization itself (i.e. when running the app), localization exports seem to only include translations from existing strings files that are "near" plist.info.

like image 82
bcause Avatar answered Sep 28 '22 03:09

bcause