Skip to content

Instantly share code, notes, and snippets.

@alsedi
Last active October 8, 2015 10:06
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 alsedi/357c99ff6d138cf94804 to your computer and use it in GitHub Desktop.
Save alsedi/357c99ff6d138cf94804 to your computer and use it in GitHub Desktop.
Localization of String, Int, Float, etc (Swift)
import Foundation
// Usage "String".localize will search for "String" key in Localizeble
// Works for all types that conform CustomStringConvertible protocol, e.g. Int, Float.
// Raw value will be converted to string and used as key, e.g.
// 10.localize, will search for "10" key.
// If key not exists, then string value will be returned
// Gist: https://gist.github.com/alsedi/357c99ff6d138cf94804
extension CustomStringConvertible {
var localize: String {
return NSLocalizedString(self.description, comment: "")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment