Search code examples
swiftlocalizationios9nslocalizedstringgenstrings

genstrings does not work when setting tableName parameter in NSLocalizedString


I am getting Bad entry in file error when using genstrings command line for every call to NSLocalizedString that uses tableName parameter

See the following example when trying to generate localized strings (from Firefox-iOS)

find . -name *.swift | xargs genstrings -o en.lproj

Bad entry in file ./StorageTests/TestSQLiteHistory.swift (line = 100): Argument is not a literal string.

Bad entry in file ./StorageTests/TestSQLiteHistory.swift (line = 101): Argument is not a literal string.

Bad entry in file ./StorageTests/TestSQLiteHistory.swift (line = 102): Argument is not a literal string.

Bad entry in file ./StorageTests/TestSQLiteHistory.swift (line = 103): Argument is not a literal string. Argument is not a literal string.

Here is the code for these lines

let titleMobile = NSLocalizedString("Mobile Bookmarks", tableName: "Storage", comment: "The title of the folder that contains mobile bookmarks. This should match bookmarks.folder.mobile.label on Android.")
let titleMenu = NSLocalizedString("Bookmarks Menu", tableName: "Storage", comment: "The name of the folder that contains desktop bookmarks in the menu. This should match bookmarks.folder.menu.label on Android.")
let titleToolbar = NSLocalizedString("Bookmarks Toolbar", tableName: "Storage", comment: "The name of the folder that contains desktop bookmarks in the toolbar. This should match bookmarks.folder.toolbar.label on Android.")
let titleUnsorted = NSLocalizedString("Unsorted Bookmarks", tableName: "Storage", comment: "The name of the folder that contains unsorted desktop bookmarks. This should match bookmarks.folder.unfiled.label on Android.")

When I searched for a solution I found this tool for generating and merging localized strings. It worked for this case, generated and merged the localized strings into Localizable.strings but in run time the app does not show the localized titles as it tries to load the localized strings form a file with the a name Storage.strings not from Localizable.strings

Is there is any solution to automatically generate these files instead of doing it manually?


Solution

  • It seems that I need to translate the resources according to the latest procedure from apple

    1. Export localization file .xliff using Xcode (select your Project in Xcode, then Editor -> Export for Localization)
    2. Use a translation tool to translate all keys (SwordFish, brightec online xliff editor)
    3. Import the translated file back into Xcode

    Reference: https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/LocalizingYourApp/LocalizingYourApp.html