Swiftpack.co - Package - seatcode/Unstringify


PRs Welcome

☝️ What?

  • unstringify (CLI): Code generator for strong-typing localizable strings.
  • Unstringified (module): Strong-typed localizable strings static source code.

🤔 Why?

It makes your localized strings code:

  • compile time checked,
  • strong typed,
  • autocompletable by Xcode.

🛠 How?


There are several methods to install Unstringify:


Add unstringify specs to your Podfile:

pod 'Unstringify'

Add Unstringified as dependency in the podspec of the module that contains the strings files:

s.dependency 'Unstringified'

Note: If your app is not modularized, simply add pod 'Unstringified' to your Podfile too.

Add a Build Phase that generates the code for the Unstringified enumerations:

"$PODS_ROOT/Unstringify/unstringify" "$SRCROOT/path/to/module/en.lproj/Localizable.strings" "$SRCROOT/path/to/module/Unstringified.generated.swift"

Swift Package Manager

Declare Unstringify dependency in your Package.swift file:

dependencies: [
    .package(url: "https://github.com/metrolab/Unstringify", from: "0.1.0"),

Execute the CLI passing as arguments the input strings file and the path to generated output file:

swift run unstringify path/to/module/en.lproj/Localizable.string path/to/module/Unstringified.generated.swift

In order to use the generated file, you will need to link Unstringified to the module that contains the generated file and the original strings files.


CLI usage:

$ ./unstringify
Usage: ./unstringify inputPath outputPath [templatePath]

Note: templatePath is optional.

Input (e.g. en.lproj/Localizable.strings):

"form_title" = "Contact";
"form_name_field" = "Name:";
"form_name_field_max_length" = "Maximum length is %d characters.";
"form_name_field_description" = "Enter your <b>full name</b>";

Output (e.g. Unstringified.generated.swift):

//  Generated by Unstringify.

import Foundation
import Unstringified

private final class _Unstringified {}

extension Unstringified {
    public var localizableStringsTableName: String? {
        return nil

    public var localizableStringsBundle: Bundle? {
        let _UnstringifiedBundle = Bundle(for: _Unstringified.self)
        guard _UnstringifiedBundle.bundleIdentifier != Bundle.main.bundleIdentifier else {
            return Bundle.main
        let bundleURL = _UnstringifiedBundle.bundleURL
        let bundleName = bundleURL.lastPathComponent
        let resource = (bundleName as NSString).deletingPathExtension
        guard let path = _UnstringifiedBundle.path(forResource: resource, ofType: "bundle") else {
            return nil
        return Bundle(path: path)

public enum Text: String, Unstringified {
    public typealias StringType = String
    case form_title, form_name_field

public enum Format: Unstringified {
    public typealias StringType = String
    case form_name_field_max_length(Int)

public enum RichText: String, Unstringified {
    public typealias StringType = NSAttributedString
    case form_name_field_description

public enum RichFormat: Unstringified {
    public typealias StringType = NSAttributedString
    case 👻(Void)


You can customize localizableStringsTableName and localizableStringsBundle for each enum (Text, Format, RichText, RichFormat) by reimplementing them in an extension:

extension Text {
    public var localizableStringsTableName: String? {
        return "xxx"


You can also customize the generated code by using a custom template.

Your template must contain the following variables:



See Examples directory.

📖 License

Unstringify is released under the MIT license. See LICENSE for details.



Stars: 2


Used By

Total: 0


- 2020-04-14 16:02:45

- 2020-04-14 14:27:07

- 2019-11-04 15:34:12

- 2019-10-30 09:42:43

- 2019-10-18 02:38:19

- 2019-10-14 14:04:07

- 2019-10-03 07:20:47

- 2019-10-02 08:02:36