Has anyone got String type enums to work with genstrings?

143 Views Asked by At

I'm trying to use genstrings in my project to output a localized strings file. It works fine and dandy when, say, you have a string represented like this:

NSLocalizedString("My String", comment: "My String")

However, I've decided to use String-type enums to represent my application's strings. The reasoning behind this is so that if the app requires a copy change, it's easier to edit the string in location than having to go through the entire project switching strings out.

The solution I'm using for my strings is quite simple - like so:

enum MyStrings {
    enum Actions: String {
        case ok = "OK"
        case cancel = "Cancel"
    }
}

Then, to grab the localized string, I've implemented the following extension:

extension RawRepresentable where RawValue == String {
    var localizedString: String {
        return NSLocalizedString(self.rawValue, comment: "")
    }
}

Pretty simple, right? It works fine, however I run into issues when trying to use genstrings (I've tried extractLocStrings too as was suggested on the Apple Developer Forums) - I get issues like this:

Bad entry in file .xxxx/MyViewController.swift (line = 1305): Argument is not a literal string.

This is obviously because genstrings seems to be scanning the uncompiled files. I'm not very hopeful here but I was wondering if someone has come up with a solution to this? I'd like to think that I don't have to workspace-search my projects to change strings everywhere every time a copy change is required (our projects are rather large).

I'd greatly appreciate any help with this! Thanks in advance.

J

0

There are 0 best solutions below