1

I have a weird inconsistency with my localizable strings where sometimes the value is shown and sometimes thee key is shown. It's about every other time I restart the app. I use a lot of localizable strings in the project and they all work fine except for the ones I use in conjunction with this enum, which of course makes me think there is something wrong with it:

enum ParameterDescription  {
    
    case parameterDescription(id: Int)
    
    var description: String {
        switch self {
        case .parameterDescription(let id):
            return "parameterDescription_\(id)"
        }
    }
}

This returns the string I expect, like parameterDescription_0 or parameterDescription_3. And then I hook on localized:

print(ParameterDescription.parameterDescription(id: 0).description.localized())

extension String {
    func localized() -> String {
        return NSLocalizedString(self, comment: "")
    }
}

And sometimes I get the correct associated value, but if I build and run the code again without changing anything, I (might) get the key printed as a string instead, which I guess means that Xcode couldn't find the string.

Is there something wrong with the enum or some reason it can't be used like this? Or is it something else? I have checked through the project folders so that there aren't any conflicting files, and as I previously said, I only experience this problem using this enum and/or this key. And there are thousands of localized strings in the project.

I have checked similar threads, but there doesn't seem to be any answer that is relevant for this.

Joakim Sjöstedt
  • 824
  • 2
  • 9
  • 18
  • Have you checked whether you have values for those `key`s in all `.lproj` files? – Jithin Aug 13 '20 at 08:48
  • I would check the localized strings for typos or for missing `;` at the end of lines. Also check that every case is covered (since the `id` can be an arbitrary number). And/or you could change your logic and have localizable parameters, like in https://stackoverflow.com/q/26277626/2227743 – Eric Aya Aug 13 '20 at 09:40

0 Answers0