Renamed the Sources folder as Libraries.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftLibs open source project
|
||||
//
|
||||
// Copyright (c) 2023 Röck+Cöde VoF. and the SwiftLibs project authors
|
||||
// Licensed under the EUPL 1.2 or later.
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftLibs project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
public extension Bool {
|
||||
|
||||
// MARK: Initialisers
|
||||
|
||||
/// Initialise a boolean primitive out of a given string.
|
||||
/// - Parameter string: A string to initialise the boolean with.
|
||||
init(_ string: String) {
|
||||
let strings: [String] = [
|
||||
.Constants.oneNumber,
|
||||
.Constants.oneWord,
|
||||
.Constants.true,
|
||||
.Constants.yes
|
||||
]
|
||||
|
||||
self = strings.contains(string.lowercased())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - String+Constants
|
||||
|
||||
private extension String {
|
||||
enum Constants {
|
||||
static let yes = "yes"
|
||||
static let `true` = "true"
|
||||
static let oneWord = "one"
|
||||
static let oneNumber = "1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftLibs open source project
|
||||
//
|
||||
// Copyright (c) 2023 Röck+Cöde VoF. and the SwiftLibs project authors
|
||||
// Licensed under the EUPL 1.2 or later.
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftLibs project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension Bundle {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
/// Retrieve a localisation bundle for a given language code or identifier, if exist inside a certain bundle.
|
||||
/// - Parameter languageCode: A string that represent a language code or identifier.
|
||||
/// - Returns: A `Bundle` instance that contains localised resources based on a given language code or identifier.
|
||||
/// - Throws: A `BundleError` error in case the localisation bundle for a given language code or identifier is not found inside a certain bundle.
|
||||
func localisation(for languageCode: String) throws -> Bundle {
|
||||
guard
|
||||
let path = path(forResource: languageCode, ofType: .ResourceType.localisationBundle),
|
||||
let bundle = Bundle(path: path)
|
||||
else {
|
||||
throw BundleError.bundleNotFound
|
||||
}
|
||||
|
||||
return bundle
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - String+Constants
|
||||
|
||||
private extension String {
|
||||
enum ResourceType {
|
||||
static let localisationBundle = "lproj"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftLibs open source project
|
||||
//
|
||||
// Copyright (c) 2023 Röck+Cöde VoF. and the SwiftLibs project authors
|
||||
// Licensed under the EUPL 1.2 or later.
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftLibs project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
public extension Collection {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
/// A Boolean value indicating whether a collection is not empty.
|
||||
var isNotEmpty: Bool { !isEmpty }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftLibs open source project
|
||||
//
|
||||
// Copyright (c) 2023 Röck+Cöde VoF. and the SwiftLibs project authors
|
||||
// Licensed under the EUPL 1.2 or later.
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftLibs project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
public extension Optional {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
/// A Boolean value indicating whether an optional has not been set.
|
||||
var isNil: Bool { self == nil }
|
||||
|
||||
/// A Boolean value indicating whether an optional has been set.
|
||||
var isNotNil: Bool { !isNil }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftLibs open source project
|
||||
//
|
||||
// Copyright (c) 2023 Röck+Cöde VoF. and the SwiftLibs project authors
|
||||
// Licensed under the EUPL 1.2 or later.
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftLibs project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
public extension String {
|
||||
|
||||
// MARK: Constants
|
||||
|
||||
/// A string that represents an empty string.
|
||||
static let empty = ""
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
/// A Boolean value indicating whether a string is not empty.
|
||||
var isNotEmpty: Bool { !isEmpty }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftLibs open source project
|
||||
//
|
||||
// Copyright (c) 2023 Röck+Cöde VoF. and the SwiftLibs project authors
|
||||
// Licensed under the EUPL 1.2 or later.
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftLibs project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension String {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
/// Localise a string based on a given language code or identifier in an specific bundle.
|
||||
/// - Parameters:
|
||||
/// - languageCode: A string that represent a language code or identifier.
|
||||
/// - bundle: A bundle in which to retrieve a localisation bundle.
|
||||
/// - value: A default value to return if key is nil or if a localized string for key can't be found in the table.
|
||||
/// - table: The receiver's string table to search. In case of nil or an empty string, the method attempts to use the table in `Localizable.strings`.
|
||||
/// - Returns: A localized version of the string in case it is found. Otherwise, it returns the original string or a default string, if provided.
|
||||
func localise(
|
||||
for languageCode: String,
|
||||
in bundle: Bundle,
|
||||
value: String? = nil,
|
||||
table: String? = nil
|
||||
) -> String {
|
||||
do {
|
||||
return try bundle
|
||||
.localisation(for: languageCode)
|
||||
.localizedString(
|
||||
forKey: self,
|
||||
value: value,
|
||||
table: table
|
||||
)
|
||||
} catch {
|
||||
return value ?? self
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import Foundation
|
||||
|
||||
public extension TimeZone {
|
||||
|
||||
// MARK: Zones
|
||||
|
||||
/// A time zone indicating it is Greenwich Mean Time or UTC+0
|
||||
static let gmt = TimeZone(secondsFromGMT: 0)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user