Skip to content

Commit 19d0fc2

Browse files
committed
Added SPLocale.
1 parent 0a210ad commit 19d0fc2

File tree

4 files changed

+92
-6
lines changed

4 files changed

+92
-6
lines changed

Sources/SparrowKit/Foundation/Classes/SPFileManagerDestination.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ import Foundation
2323

2424
public struct SPFileManagerDestination {
2525

26+
// MARK: - Data
27+
2628
public var file: String
2729
public var directory: URL
2830

29-
public var url: URL {
30-
return directory.appendingPathComponent(file)
31-
}
31+
public var url: URL { directory.appendingPathComponent(file) }
32+
33+
// MARK: - Init
3234

3335
public init(directory: FileManager.SearchPathDirectory = .documentDirectory, path: String, file: String) {
3436
let fileManager = FileManager.default
@@ -46,10 +48,12 @@ public struct SPFileManagerDestination {
4648

4749
public init(fileName: String) {
4850
let bundleFileURL = Bundle.main.url(forResource: fileName, withExtension: nil)
49-
self.directory = bundleFileURL?.deletingLastPathComponent() ?? URL.init(string: "")!
50-
self.file = bundleFileURL?.lastPathComponent ?? ""
51+
self.directory = bundleFileURL?.deletingLastPathComponent() ?? URL.init(string: .empty)!
52+
self.file = bundleFileURL?.lastPathComponent ?? .empty
5153
}
5254

55+
// MARK: - Private
56+
5357
private static func cleaned(_ path: String) -> String {
5458
return path.removedPrefix("/").removedSuffix("/")
5559
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2020 Ivan Varabei ([email protected])
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
22+
import Foundation
23+
24+
public enum SPLocale: String {
25+
26+
case ru = "ru" // Russian
27+
case en = "en" // English
28+
case uk = "uk" // Ukrainian
29+
case es = "es" // Spanish
30+
case ar = "ar" // Arabic
31+
case fa = "fa" // Persian
32+
case de = "de" // German
33+
case fr = "fr" // French
34+
case it = "it" // Italian
35+
case nl = "nl" // Dutch
36+
case id = "id" // Indonesian
37+
case ms = "ms" // Malay
38+
case tr = "tr" // Turkish
39+
case hy = "hy" // Armenian
40+
case zh = "zh" // Chinese
41+
case ja = "ja" // Japanese
42+
case ur = "ur" // Urdu
43+
case be = "be" // Belarusian
44+
case pt = "pt" // Portuguese
45+
case pl = "pl" // Polish
46+
case gsw = "gsw" // Swiss German
47+
case fil = "fil" // Filipino
48+
49+
/**
50+
SparrowKit: Uniq identifier.
51+
*/
52+
public var identifier: String { rawValue }
53+
54+
/**
55+
SparrowKit: Code if language which using Apple without split.
56+
*/
57+
public var languageCode: String { rawValue }
58+
59+
/**
60+
SparrowKit: Current locale, which using in app
61+
*/
62+
public static var current: SPLocale {
63+
get {
64+
var code = Locale.preferredLanguages.first ?? "en"
65+
var locale = SPLocale(rawValue: code)
66+
if locale == nil {
67+
code = String(code.split(separator: "-").first ?? "en")
68+
locale = SPLocale(rawValue: code)
69+
}
70+
return locale ?? .en
71+
}
72+
}
73+
74+
/**
75+
SparrowKit: Localize description of language.
76+
*/
77+
public func description(in locale: SPLocale) -> String {
78+
let locale = NSLocale(localeIdentifier: locale.languageCode)
79+
let text = locale.displayName(forKey: NSLocale.Key.identifier, value: languageCode) ?? .empty
80+
return text.localizedCapitalized
81+
}
82+
}

SparrowKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = 'SparrowKit'
4-
s.version = '3.2.5'
4+
s.version = '3.2.6'
55
s.summary = 'Collection of native Swift extensions to boost your development. Support tvOS and watchOS.'
66
s.homepage = 'https://github.com/ivanvorobei/SparrowKit'
77
s.source = { :git => 'https://github.com/ivanvorobei/SparrowKit.git', :tag => s.version }

0 commit comments

Comments
 (0)