|
| 1 | +# Unstringify |
| 2 | + |
| 3 | +## What? |
| 4 | + |
| 5 | +- `unstringify` (CLI): Code generator for strong-typing localizable strings. |
| 6 | +- `Unstringified` (module): Strong-typed localizable strings static source code. |
| 7 | + |
| 8 | +## Why? |
| 9 | + |
| 10 | +It makes your localized strings code: |
| 11 | + |
| 12 | +- compile time checked, |
| 13 | +- strong typed, |
| 14 | +- autocompletable by Xcode. |
| 15 | + |
| 16 | +## How? |
| 17 | + |
| 18 | +### Installation |
| 19 | + |
| 20 | +There are several methods to install Unstringify: |
| 21 | + |
| 22 | +- Via [CocoaPods](https://cocoapods.org) |
| 23 | +- Via [Swift Package Manager](https://swift.org/package-manager) |
| 24 | +- Others: |
| 25 | + - Download the ZIP for the [latest release](https://github.com/metrolab/Unstringify/releases/latest) |
| 26 | + - Via [Mint](https://github.com/yonaskolb/Mint) (system-wide installation) |
| 27 | + - Compile from [source](https://github.com/metrolab/Unstringify.git) (only recommended if you need features from master or want to test a PR) |
| 28 | + |
| 29 | +#### CocoaPods |
| 30 | + |
| 31 | +Add `unstringify` specs to your `Podfile`: |
| 32 | + |
| 33 | +```ruby |
| 34 | +pod 'Unstringify' |
| 35 | +``` |
| 36 | + |
| 37 | +Add `Unstringified` as dependency in the podspec of the module that contains the strings files: |
| 38 | + |
| 39 | +```ruby |
| 40 | +s.dependency 'Unstringified' |
| 41 | +``` |
| 42 | +**Note:** *If your app is not modularized, simply add `pod 'Unstringified'` to your `Podfile` too.* |
| 43 | + |
| 44 | +Add a Build Phase that generates the code for the `Unstringified` enumerations: |
| 45 | + |
| 46 | +```bash |
| 47 | +"$PODS_ROOT/Unstringify/unstringify" "$SRCROOT/path/to/module/en.lproj/Localizable.strings" "$SRCROOT/path/to/module/Unstringified.generated.string" |
| 48 | +``` |
| 49 | + |
| 50 | +#### Swift Package Manager |
| 51 | + |
| 52 | +Declare `Unstringify` dependency in your `Package.swift` file: |
| 53 | + |
| 54 | +```swift |
| 55 | +dependencies: [ |
| 56 | + .package(url: "https://github.com/metrolab/Unstringify", from: "0.1.0"), |
| 57 | +] |
| 58 | +``` |
| 59 | + |
| 60 | +Execute the CLI passing as arguments the *input strings file* and the *path to generated output file*: |
| 61 | + |
| 62 | +```sh |
| 63 | +swift run unstringify path/to/module/en.lproj/Localizable.string path/to/module/Unstringified.generated.string |
| 64 | +``` |
| 65 | + |
| 66 | +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. |
| 67 | + |
| 68 | +### Example |
| 69 | + |
| 70 | +CLI usage: |
| 71 | + |
| 72 | +``` |
| 73 | +$ ./unstringify |
| 74 | +Usage: ./unstringify inputPath outputPath |
| 75 | +``` |
| 76 | + |
| 77 | +Input (e.g. `en.lproj/Localizable.strings`): |
| 78 | + |
| 79 | +``` |
| 80 | +"form_title" = "Contact"; |
| 81 | +"form_name_field" = "Name:"; |
| 82 | +"form_name_field_max_length" = "Maximum length is %d characters."; |
| 83 | +"form_name_field_description" = "Enter your <b>full name</b>"; |
| 84 | +``` |
| 85 | + |
| 86 | +Output (e.g. `Unstringified.generated.swift`): |
| 87 | + |
| 88 | +``` |
| 89 | +// Generated by Unstringify. |
| 90 | +// DO NOT EDIT! |
| 91 | +
|
| 92 | +import Unstringified |
| 93 | +
|
| 94 | +private final class _Unstringified {} |
| 95 | +
|
| 96 | +extension Unstringified { |
| 97 | + public var localizableStringsBundle: Bundle { |
| 98 | + return Bundle(for: _Unstringified.self) |
| 99 | + } |
| 100 | +} |
| 101 | +
|
| 102 | +public enum Text: String, Unstringified { |
| 103 | + public typealias StringType = String |
| 104 | + case form_title, form_name_field |
| 105 | +} |
| 106 | +
|
| 107 | +public enum Format: Unstringified { |
| 108 | + public typealias StringType = String |
| 109 | + case form_name_field_max_length(Int) |
| 110 | +} |
| 111 | +
|
| 112 | +public enum RichText: String, Unstringified { |
| 113 | + public typealias StringType = NSAttributedString |
| 114 | + case form_name_field_description |
| 115 | +} |
| 116 | +
|
| 117 | +public enum RichFormat: Unstringified { |
| 118 | + public typealias StringType = NSAttributedString |
| 119 | + case 👻() |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +## License |
| 124 | + |
| 125 | +Unstringify is released under the MIT license. See `LICENSE` for details. |
| 126 | + |
| 127 | +# Alternatives |
| 128 | + |
| 129 | +- <https://github.com/mac-cain13/R.swift> |
| 130 | +- <https://github.com/bannzai/ResourceKit> |
| 131 | +- <https://github.com/kaandedeoglu/Shark> |
| 132 | +- <https://github.com/SwiftGen/SwiftGen> |
0 commit comments