Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #61 from mojio/master
Browse files Browse the repository at this point in the history
Fixed lookup for languageBundle. For cases like "en_CA"
  • Loading branch information
Adrian Kosmaczewski authored Sep 19, 2016
2 parents 613e1eb + fd6446c commit 1391d0f
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions SwiftMoment/SwiftMoment/MomentFromNow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,27 @@ extension Moment {
guard let bundle = NSBundle(URL: path) else {
return ""
}

let localeIdentifer = self.locale.localeIdentifier
guard let languagePath = bundle.pathForResource(localeIdentifer, ofType: "lproj"),
languageBundle = NSBundle(path: languagePath)
else {
return ""

if let languageBundle = getLanguageBundle(bundle) {
return languageBundle.localizedStringForKey(key, value: "", table: "NSDateTimeAgo")
}

return ""
}

private func getLanguageBundle(bundle: NSBundle) -> NSBundle? {
let localeIdentifer = self.locale.localeIdentifier
if let languagePath = bundle.pathForResource(localeIdentifer, ofType: "lproj") {
return NSBundle(path: languagePath)
}

let langDict = NSLocale.componentsFromLocaleIdentifier(localeIdentifer)
let languageCode = langDict["kCFLocaleLanguageCodeKey"]
if let languagePath = bundle.pathForResource(languageCode, ofType: "lproj") {
return NSBundle(path: languagePath)
}

return languageBundle.localizedStringForKey(key, value: "", table: "NSDateTimeAgo")
return nil
}

private func getLocaleFormatUnderscoresWithValue(value: Double) -> String {
Expand Down

0 comments on commit 1391d0f

Please sign in to comment.