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

Fixed lookup for languageBundle. For cases like "en_CA" #61

Merged
merged 1 commit into from
Sep 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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