Skip to content

Instantly share code, notes, and snippets.

Last active June 28, 2016 09:01
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(
tableName: tableName,
bundle: bundle,
value: "",
comment: comment)
Copy link

asalom commented Jun 28, 2016

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

"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