-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify localization code, remove extension
- Loading branch information
1 parent
1d8cfbf
commit 92684ac
Showing
1 changed file
with
25 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,34 @@ | ||
import Foundation | ||
|
||
extension Bundle { | ||
static var localizationBundle: Bundle { | ||
// When installed via the Swift Package Manager, the bundle name is "CalendarKit_CalendarKit", | ||
// via CocoaPods - "CalendarKit" | ||
let bundleNames = ["CalendarKit_CalendarKit", "CalendarKit"] | ||
|
||
let candidates = [ | ||
// Bundle should be present here when the package is linked into an App. | ||
Bundle.main.resourceURL, | ||
|
||
// Bundle should be present here when the package is linked into a framework. | ||
Bundle(for: DayViewController.self).resourceURL, | ||
|
||
// For command-line tools. | ||
Bundle.main.bundleURL, | ||
] | ||
|
||
for candidate in candidates { | ||
for bundleName in bundleNames { | ||
let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle") | ||
if let bundle = bundlePath.flatMap(Bundle.init(url:)) { | ||
return bundle | ||
} | ||
func localizedString(_ key: String) -> String { | ||
var localizationBundle = Bundle.main | ||
// When installed via the Swift Package Manager, the bundle name is "CalendarKit_CalendarKit", | ||
// via CocoaPods - "CalendarKit" | ||
let bundleNames = ["CalendarKit_CalendarKit", "CalendarKit"] | ||
|
||
let candidates = [ | ||
// Bundle should be present here when the package is linked into an App. | ||
Bundle.main.resourceURL, | ||
|
||
// Bundle should be present here when the package is linked into a framework. | ||
Bundle(for: DayViewController.self).resourceURL, | ||
|
||
// For command-line tools. | ||
Bundle.main.bundleURL, | ||
] | ||
|
||
outer: | ||
for candidate in candidates { | ||
for bundleName in bundleNames { | ||
let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle") | ||
if let bundle = bundlePath.flatMap(Bundle.init(url:)) { | ||
localizationBundle = bundle | ||
break outer | ||
} | ||
} | ||
return Bundle.main | ||
} | ||
} | ||
|
||
func localizedString(_ key: String) -> String { | ||
Bundle.localizationBundle.localizedString(forKey: key, | ||
return localizationBundle.localizedString(forKey: key, | ||
value: nil, | ||
table: nil) | ||
} |