SwiftGenStrings is a command line application that can be used as a drop-in replacement for the standard genstrings
command for Swift sources. The latter only supports the short form of the NSLocalizedString
function but breaks as soon as you use any parameters other than key
and comment
as in
NSLocalizedString("DATE_RANGE", value: "%@ โ %@", comment: "A range of dates")
The upstream issue is tracked here.
SwiftGenStrings files
SwiftGenStrings [-s <routine>] [-o <outputDir>] files
SwiftGenStrings [-h|--help]
OPTIONS
-h|--help
(Optional) Print help.
-s routine
(Optional) Substitute routine for NSLocalizedString, useful when different macro is used.
-o outputDir
(Optional) Specifies what directory Localizable.strings table is created in.
Not specifying output directory will print script output content to standard output (console).
files
List of files, that are used as source of Localizable.strings generation.
To gather strings in current directory, run:
$ find . -name "*.swift" | xargs SwiftGenStrings
If you have any 3rd party code like CocoaPods or Carthage in your project directory, you might want to exclude it from localization. To do that, run the following:
$ find . \( -name "*.swift" ! -path "./Carthage/*" ! -path "./Pods/*" \) | xargs SwiftGenStrings
We tag releases and upload prebuilt binaries to GitHub. Checkout the releases tab or go straight to the latest release.
The project provides a Makefile
. To export a binary run:
$ make release
The exported binary can be found under Products/SwiftGenStrings
A podspec file for the project was released (see here). To consume the project, simply add the following to your Podfile
:
pod 'SwiftGenStrings'
After running pod install
or pod update
, you will then find the binary under Pods/SwiftGenStrings/SwiftGenStrings
Xcode 9.2 seems to have a bug with running tests against macOS destination, luckily, xcodebuild
works just fine:
$ make test
- Xcode 9.2
- Swift 4.0.2
- SwiftGenStrings currently doesn't support multiple tables, only the default one -
Localizable.strings
. - It is not possible to use
NSLocalizedString
in string interpolation e.g.:let hello = "--- \(NSLocalizedString("Hello world!", comment: ""))"
will not pickup the localized string.