/generate-string-symbols

Create a header file containing symbols for the given strings file keys.

Primary LanguageObjective-CBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

What is it?

generate-string-symbols is a tiny little Mac command-line tool that creates a header file containing NSString constants for the keys in the given .strings files. Combined with a custom build step in your Xcode project and a bit of macro magic, it can be used to automatically give compile-time checked keys for your localised strings.

You can find a discussion on this over on my blog.

License

generate-string-symbols is licensed under three-clause BSD. The license document can be found here.

Building

  1. Clone create-ram-disk using $ git clone git://github.com/iKenndac/generate-string-symbols.git.
  2. Open the project and build away!

Usage

$ generate-string-symbols -strings <path to .strings file> -out <output path>

  • -strings The path to a valid .strings file.

  • -out The path to write the output header file to. Missing directories will be created along the way. If a file already exists at the given path, it will be overwritten.

Example

Given a strings file like this:

"OKTitle" = "OK";
"CancelTitle" = "Cancel";
"DownloadingTitle" = "Downloading…";

This tool will output a header file like this:

// Generated by generate-string-symbols on 2014-08-10 13:08:47 +02:00
// Source file: /Users/dkennett/Projects/Cascable/Cascable/Base.lproj/GeneralUI.strings
// WARNING: This file was auto-generated. Do not modify by hand.

#import <Foundation/Foundation.h>

static NSString * const OKTitle = @"OKTitle";
static NSString * const CancelTitle = @"CancelTitle";
static NSString * const DownloadingTitle = @"DownloadingTitle";

Note that key order isn't guaranteed.