Skip to content

Commit e8fcc55

Browse files
authored
Merge pull request #12 from GoodRequest/localized-strings
Localized validation strings
2 parents 41a2f81 + 9ef1898 commit e8fcc55

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Sources/GRInputField/Common/ValidationError.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ public protocol ValidationError: LocalizedError {}
1414

1515
public enum InternalValidationError: ValidationError {
1616

17-
case alwaysError
17+
case invalid
1818
case required
1919
case mismatch
2020
case external(MainSupplier<String>)
2121

2222
public var errorDescription: String? {
2323
switch self {
24-
case .alwaysError:
25-
"Error"
24+
case .invalid:
25+
Bundle.main.localizedString(forKey: "invalid", value: "Invalid", table: "InternalValidationError")
2626

2727
case .required:
28-
"Required"
28+
Bundle.main.localizedString(forKey: "required", value: "Required", table: "InternalValidationError")
2929

3030
case .mismatch:
31-
"Elements do not match"
31+
Bundle.main.localizedString(forKey: "mismatch", value: "Mismatch", table: "InternalValidationError")
3232

3333
case .external(let description):
3434
MainActor.assumeIsolated {
@@ -48,7 +48,7 @@ public extension Criterion {
4848

4949
/// Always fails
5050
static let alwaysError = Criterion { _ in false }
51-
.failWith(error: InternalValidationError.alwaysError)
51+
.failWith(error: InternalValidationError.invalid)
5252

5353
/// Accepts any input with length > 0, excluding leading/trailing whitespace
5454
static let nonEmpty = Criterion { !($0 ?? "").trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }

Sources/GRInputField/Common/Validator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import GoodStructs
8181

8282
// MARK: - Variables
8383

84-
private(set) internal var error: any ValidationError = InternalValidationError.alwaysError
84+
private(set) internal var error: any ValidationError = InternalValidationError.invalid
8585

8686
// MARK: - Constants
8787

Sources/GRInputField/UIKit/ValidableInputFieldView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class ValidableInputFieldView: InputFieldView {
6868
/// Does not update the UI in any way.
6969
/// - Returns: `nil` when content is valid, otherwise validation error from failed criterion.
7070
public func validateSilently() -> (any ValidationError)? {
71-
guard let validator = validator?() else { return InternalValidationError.alwaysError }
71+
guard let validator = validator?() else { return InternalValidationError.invalid }
7272

7373
return validator.validate(input: self.text)
7474
}

0 commit comments

Comments
 (0)