Skip to content

Instantly share code, notes, and snippets.

@asalom
Last active June 28, 2016 09:01
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 asalom/cfade69708bf300c479bea614f39bc41 to your computer and use it in GitHub Desktop.
Save asalom/cfade69708bf300c479bea614f39bc41 to your computer and use it in GitHub Desktop.
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)
}
}
@asalom
Copy link
Author

asalom commented Jun 28, 2016

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