Should NSLocalizedString be used directly to export XLIFF?

I used a NSLocalizedStringcustom function.

For example, to access Profile.stringsI define this function:

func LocalizedProfile(key: String, comment: String?) { NSLocalizedString(key, tableName: "Profile", comment: comment ?? "") }

And, it is called like this:

let localized = LocalizedProfile("Submit", comment: "For registration")

This method works fine except for exporting XLIFF.

In Xcode 6.3.2, execution Export for localizationcauses an error:

enter image description here

To get information about the error, I ran through the command line:

xcodebuild -exportLocalizations -localizationPath ./xliff -project MyApp.xcodeproj -exportLanguage ja

And I got this error:

Bad entry in file /Users/mono/Documents/Git/MyApp/Localization.swift (line = 29): Argument is not a literal string.

Defining a custom localization method is very useful for me, but I also want to use the XLIFF export function.

Are there any methods to address these requirements?

+5
source share
1 answer

Export For Localization xcodebuild -exportLocalizations NSLocalizedString(_:tableName:bundle:value:comment:) , , .

, , key, comment, value tableName .

- NSLocalizedString(_:comment:) , Xcode , NSLocalizedString(_:comment:), , NSLocalizedString(_:comment:) - , .

NSLocalizedString(_:tableName:comment:) .

, Bundle.localizedString(forKey:value:table:) -, -.

/// - parameter comment: This value is ignored, but should be provided for 
///   context at the call site about the requested localized string.
func LocalizedProfile(key: String, comment: String?) -> String {
    return Bundle.main.localizedString(forKey: key, value: nil, table: "Profile")
}
0

All Articles