06153
06153

Reputation: 329

Get a key by value in Localizable.strings

I'm getting an input string in language 1 and I'd like to find what key it corresponds to in my Localizable.strings. Later I will use this key to retrieve its value in language 2.

How can I find a key by value?

Upvotes: 1

Views: 1609

Answers (1)

Myaaoonn
Myaaoonn

Reputation: 997

  let stringsPath = Bundle.main.path(forResource: "Localizable", ofType: "strings")
        var dictionary = NSDictionary (contentsOfFile: stringsPath ?? "")

        if let temp = dictionary?.allValues.filter({$0 as? String == "Your Value to be searched"}), temp.count > 0 {
            print("nice found")
        }

Check with above code.

Upvotes: 1

Related Questions