SkillAgentSearch skills...

SwiftGenStrings

genstrings replacement for Swift that actually works

Install / Use

/learn @kayak/SwiftGenStrings
About this skill

Quality Score

0/100

Supported Platforms

Zed

README

SwiftGenStrings

⚠️ This repository is no longer needed as genstrings now supports Swift localized strings with key, value, comment arguments. Use xcrun extractLocStrings instead.

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.

Usage

USAGE: SwiftGenStrings <files> ... [-s <s>] [-o <o>] [--exclude-comments]

ARGUMENTS:
  <files>                 List of files, that are used as source of
                          Localizable.strings generation.

OPTIONS:
  -s <s>                  (Optional) Substitute for NSLocalizedString, useful when different macro is used.
  -o <o>                  (Optional) Specifies what directory Localizable.strings table is created in. Not specifying output directory will print script output
                          content to standard output (console).
  -e, --exclude-comments  (Optional) Formatted output does not include comments
  --version               Show the version.
  -h, --help              Show help information.

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

Installation

Mint

The quickest and easiest way to install SwiftGenStrings is via Mint

$ mint install kayak/SwiftGenStrings

Prebuilt Binaries

We tag releases and upload prebuilt binaries to GitHub. Checkout the releases tab or go straight to the latest release.

From Git

The project provides a Makefile. To export a binary run:

$ make release

The exported binary can be found under Products/SwiftGenStrings. Alternatively you can use make install to install the compiled library directly into /usr/local/bin/SwiftGenStrings

Testing

Since SwiftGenStrings is a SPM package, running tests is easy:

$ swift test

Requirements

  • Xcode 12
  • Swift 5.3

Limitations

  • 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.
View on GitHub
GitHub Stars39
CategoryDevelopment
Updated8mo ago
Forks6

Languages

Swift

Security Score

87/100

Audited on Jul 31, 2025

No findings