Skip to content

Instantly share code, notes, and snippets.

@klein-artur
Last active March 10, 2019 21:15
Show Gist options
  • Save klein-artur/ee9213af8242ac28ac75f1c83e57c9d8 to your computer and use it in GitHub Desktop.
Save klein-artur/ee9213af8242ac28ac75f1c83e57c9d8 to your computer and use it in GitHub Desktop.
Simple way to localize your String. I don't know why, but somehow I hate alway entering this NSLocalizedString methods. Do your stuff easy with this extension by just "localize your string".localize()
extension String {
func localize() -> String {
return NSLocalizedString(self, comment: "")
}
func localize(_ args: CVarArg...) -> String {
return String(format: NSLocalizedString(self, comment: ""), args)
}
}
func localizeSomeString() {
"This is the localization key".localize()
"This %@ should be localized in %@ languages.".localized("string", 4)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment