Skip to content

Commit

Permalink
Merge pull request #9 from rshev/master
Browse files Browse the repository at this point in the history
Much type-safer swift .localize implementation
  • Loading branch information
marmelroy committed Nov 3, 2015
2 parents e968146 + 5d45340 commit 8f7b58f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Localize/Localize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ public let LCLLanguageChangeNotification : String = "LCLLanguageChangeNotificati

// Swift 1.x friendly localization syntax, replaces NSLocalizedString
public func Localized(string: String) -> String {
let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj")
let bundle = NSBundle(path: path!)
let string = bundle?.localizedStringForKey(string, value: nil, table: nil)
return string!
if let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj"), bundle = NSBundle(path: path) {
return bundle.localizedStringForKey(string, value: nil, table: nil)
}
return string
}

// Swift 2 friendly localization syntax, replaces NSLocalizedString
public extension String {
func localized() -> String {
let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj")
let bundle = NSBundle(path: path!)
let string = bundle?.localizedStringForKey(self, value: nil, table: nil)
return string!
if let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj"), bundle = NSBundle(path: path) {
return bundle.localizedStringForKey(self, value: nil, table: nil)
}
return self
}
}

Expand Down

0 comments on commit 8f7b58f

Please sign in to comment.