A variation of the existing answers:
Swift 5.1:
extension String {
func localized(withComment comment: String? = nil) -> String {
return NSLocalizedString(self, comment: comment ?? "")
}
}
You can then simply use it with or without comment:
"Goodbye".localized()
"Hello".localized(withComment: "Simple greeting")
Please note that genstrings
won't work with this solution.