An Apple tool called “genstrings” generates Localizable.strings
files through an examination of the source code (the developer does not need to manually create the strings file). It searches for usage of NSLocalizedStringWithDefaultValue
within the given search space.
To use genstrings, the CRS-IUA iOS application uses the method NSLocalizedStringWithDefaultValue
exclusively when displaying text for buttons, graphics, and other display items that are not returned from the server. The signature of this method is:
NSString *NSLocalizedStringWithDefaultValue(NSString *key, NSString *tableName, NSBundle *bundle, NSString *value, NSString *comment)
The key
should be a unique key for the string, and the value
should be the string to be localized and returned. The comment
is the hint for translators, as described previously. An example of the usage of NSLocalizedStringWithDefaultValue
within ATGAddressEditViewController
that produces the Localizable.strings
entry is:
textfield.placeholder = NSLocalizedStringWithDefaultValue (@"ATGAddressEditController.State", nil, [NSBundle mainBundle], @"State", @"State address text field placeholder");
This is an example of how the genstrings command could be used to generate Localizable.strings
from source for CRS-IUA:
find . -name \*.m -print0 | xargs -0 genstrings -o ./MobileCommerce/en.lproj
Implementers can choose to convert Localizable.strings
files into other formats, such as XLIFF, for translation. There are various free, open source, and commercial products available for this purpose. Similarly, implementers can choose to place strings into Xcode Nib files, in which case Apple’s “ibtool” provides some additional utilities.