Skip to content

Instantly share code, notes, and snippets.

@foxfriends
Created September 6, 2019 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxfriends/9f7f372703b5610aece9529373e32cb1 to your computer and use it in GitHub Desktop.
Save foxfriends/9f7f372703b5610aece9529373e32cb1 to your computer and use it in GitHub Desktop.
Wrapper around NSLocalizableString to make it a lot easier to use
extension String {
/// Loads the localized version of the current string
@inline(__always)
func localized(comment: String = "") -> String {
return NSLocalizedString(self, comment: "")
}
/// Loads the localized version of the current string, interpolating the provided values into the string
func localized(comment: String = "", _ args: CVarArg...) -> String {
return withVaList(args) {
NSString(format: localized(comment: comment), arguments: $0) as String
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment