-
-
Save wassim93/6d5de1b15206f7d6d7ac88ce93dc4b09 to your computer and use it in GitHub Desktop.
String extension to localize more easy way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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