Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
public extension String {
public func localize(tableName tableName: String? = nil, bundle: NSBundle = NSBundle.mainBundle(), comment: String = "") -> String {
return NSLocalizedString(
self,
tableName: tableName,
bundle: bundle,
value: "",
comment: comment)
}
}
Owner

asalom commented Jun 28, 2016 edited

String extension to allow for a cleaner use of localized strings.
Usage:

"MENU".localize()
"MENU".localize(comment: "Menu title")

Or if you have other Localizable.strings files:

"MENU".localize(tableName: "SomeOtherLocalizable")

Or if you are in a different target:

"MENU".localize(tableName: "SomeOtherLocalizableAndTarget", bundle: NSBundle(forClass: DummyClass.self))
...
private class DummyClass { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment