Skip to content

Instantly share code, notes, and snippets.

@wassim93
Forked from Juanpe/String+Localization.swift
Created February 20, 2020 15:55
Show Gist options
  • Select an option

  • Save wassim93/6d5de1b15206f7d6d7ac88ce93dc4b09 to your computer and use it in GitHub Desktop.

Select an option

Save wassim93/6d5de1b15206f7d6d7ac88ce93dc4b09 to your computer and use it in GitHub Desktop.
String extension to localize more easy way
extension String {
var localized: String {
return NSLocalizedString(self, comment: "\(self)_comment")
}
func localized(_ args: [CVarArg]) -> String {
return localized(args)
}
func localized(_ args: CVarArg...) -> String {
return String(format: localized, args)
}
}
/// How to use
// "hello".localized
// "hello %@! you are %d years old".localized("Mike", 25)
// "hello %@! you are %d years old".localized(["Mike", 25])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment