-
Notifications
You must be signed in to change notification settings - Fork 1
/
NSBundleType.swift
90 lines (71 loc) 路 2.68 KB
/
NSBundleType.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// NSBundleType.swift
// CourseMeta
//
// Created by JohnP on 3/10/17.
// Copyright 漏 2017 JohnP. All rights reserved.
//
import Foundation
public enum KickstarterBundleIdentifier: String {
case alpha = "com.jp.coursemeta.alpha"
case beta = "com.jp.coursemeta.beta"
case release = "com.jp.coursemeta"
}
public protocol NSBundleType {
var bundleIdentifier: String? { get }
static func create(path: String) -> NSBundleType?
func path(forResource name: String?, ofType ext: String?) -> String?
func localizedString(forKey key: String, value: String?, table tableName: String?) -> String
var infoDictionary: [String : Any]? { get }
}
extension NSBundleType {
public var identifier: String {
return self.infoDictionary?["CFBundleIdentifier"] as? String ?? "Unknown"
}
public var shortVersionString: String {
return self.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown"
}
public var version: String {
return self.infoDictionary?["CFBundleVersion"] as? String ?? "0"
}
public var isAlpha: Bool {
return self.identifier == KickstarterBundleIdentifier.alpha.rawValue
}
public var isBeta: Bool {
return self.identifier == KickstarterBundleIdentifier.beta.rawValue
}
public var isRelease: Bool {
return self.identifier == KickstarterBundleIdentifier.release.rawValue
}
}
extension Bundle: NSBundleType {
public static func create(path: String) -> NSBundleType? {
return Bundle(path: path)
}
}
public struct LanguageDoubler: NSBundleType {
fileprivate static let mainBundle = Bundle.main
public init() {
}
public let bundleIdentifier: String? = "com.language.doubler"
public static func create(path: String) -> NSBundleType? {
return DoublerBundle(path: path)
}
public func localizedString(forKey key: String, value: String?, table tableName: String?) -> String {
return LanguageDoubler.mainBundle.localizedString(forKey: key, value: value, table: tableName)
}
public func path(forResource name: String?, ofType ext: String?) -> String? {
return LanguageDoubler.mainBundle.path(forResource: name, ofType: ext)
}
public var infoDictionary: [String : Any]? {
return [:]
}
}
public final class DoublerBundle: Bundle {
public override func localizedString(forKey key: String,
value: String?,
table tableName: String?) -> String {
let s = super.localizedString(forKey: key, value: value, table: tableName)
return "\(s) \(s)"
}
}