TeraUserMessages.swift (6357B)
1 import Foundation 2 import RadrootsKit 3 4 enum TeraUserMessageKey: String, CaseIterable, Sendable { 5 case addMediaUnavailable = "error.add.media_unavailable" 6 case addOperationFailed = "error.add.operation_failed" 7 case backgroundTransferFailed = "error.background_transfer.failed" 8 case backgroundTransferUnavailable = "error.background_transfer.unavailable" 9 case configurationInvalid = "error.configuration.invalid" 10 case diagnosticsExportFailed = "error.diagnostics.export_failed" 11 case diagnosticsExportSucceeded = "status.diagnostics.export_succeeded" 12 case diagnosticsPrepareFailed = "error.diagnostics.prepare_failed" 13 case fileOperationFailed = "error.file.operation_failed" 14 case identityOperationFailed = "error.identity.operation_failed" 15 case invalidRequest = "error.request.invalid" 16 case locationUnavailable = "error.location.unavailable" 17 case networkUnavailable = "error.network.unavailable" 18 case networkPolicy = "error.network.policy" 19 case operationCancelled = "error.operation.cancelled" 20 case operationConflict = "error.operation.conflict" 21 case operationOutcomeUnknown = "error.operation.outcome_unknown" 22 case permissionDenied = "error.permission.denied" 23 case partialResult = "error.result.partial" 24 case profileUnavailable = "error.profile.unavailable" 25 case protectedDataUnavailable = "error.protected_data.unavailable" 26 case runtimeObservationUnavailable = "error.runtime.observation_unavailable" 27 case runtimeOperationFailed = "error.runtime.operation_failed" 28 case runtimeUnavailable = "error.runtime.unavailable" 29 case searchUnavailable = "error.search.unavailable" 30 case secureStateUnavailable = "error.secure_state.unavailable" 31 case settingsOperationFailed = "error.settings.operation_failed" 32 case shutdownFailed = "error.shutdown.failed" 33 case startupFailed = "error.startup.failed" 34 case stateChanged = "error.state.changed" 35 case receiptCapacityExceeded = "error.storage.receipt_capacity" 36 case storageFull = "error.storage.full" 37 case todayChanged = "error.today.changed" 38 case todaySelectNetwork = "error.today.select_network" 39 case todayUnavailable = "error.today.unavailable" 40 case tryAgain = "error.operation.try_again" 41 case userPresenceUnavailable = "error.user_presence.unavailable" 42 case versionUnsupported = "error.version.unsupported" 43 44 var defaultValue: String { 45 switch self { 46 case .addMediaUnavailable: 47 "Photo handling is unavailable." 48 case .addOperationFailed: 49 "The Add operation could not be completed." 50 case .backgroundTransferFailed: 51 "The background transfer did not complete." 52 case .backgroundTransferUnavailable: 53 "Background transfer is unavailable." 54 case .configurationInvalid: 55 "Tera configuration is invalid." 56 case .diagnosticsExportFailed: 57 "Diagnostics export was cancelled or failed." 58 case .diagnosticsExportSucceeded: 59 "Diagnostics exported." 60 case .diagnosticsPrepareFailed: 61 "Diagnostics export could not be prepared." 62 case .fileOperationFailed: 63 "The file operation could not be completed." 64 case .identityOperationFailed: 65 "The local identity operation could not be completed." 66 case .invalidRequest: 67 "The request is invalid." 68 case .locationUnavailable: 69 "Location is unavailable." 70 case .operationCancelled: 71 "The operation was cancelled." 72 case .networkUnavailable: 73 "The service could not be reached. Check your connection." 74 case .networkPolicy: 75 "The service requires attention. Review its settings before trying again." 76 case .partialResult: 77 "Some results are unavailable. Refresh to check again." 78 case .operationConflict: 79 "This request conflicts with saved work. Review the existing operation." 80 case .operationOutcomeUnknown: 81 "The result is not yet known. Check the existing operation before trying again." 82 case .protectedDataUnavailable: 83 "Unlock your device to access saved work." 84 case .stateChanged: 85 "Saved state changed. Reload it before continuing." 86 case .receiptCapacityExceeded: 87 "Transfer receipt storage has reached its limit. Keep the original transfer for recovery; clearing photo cache does not resolve this limit." 88 case .storageFull: 89 "Storage is full. Free space, then check the original work before retrying. Saving may be unavailable." 90 case .versionUnsupported: 91 "This version cannot safely use the saved state or request. Check for an update." 92 case .permissionDenied: 93 "Permission was denied." 94 case .profileUnavailable: 95 "Your profile is unavailable." 96 case .runtimeObservationUnavailable: 97 "Runtime observation is temporarily unavailable." 98 case .runtimeOperationFailed: 99 "The Tera runtime could not complete the operation." 100 case .runtimeUnavailable: 101 "The Tera runtime is unavailable." 102 case .searchUnavailable: 103 "Search is unavailable." 104 case .secureStateUnavailable: 105 "Secure local state is unavailable." 106 case .settingsOperationFailed: 107 "The requested settings operation could not be completed." 108 case .shutdownFailed: 109 "Tera could not finish shutting down." 110 case .startupFailed: 111 "Tera could not start." 112 case .todayChanged: 113 "Today changed while loading. Refresh to continue." 114 case .todaySelectNetwork: 115 "Choose a local network to load Today." 116 case .todayUnavailable: 117 "Today could not be loaded." 118 case .tryAgain: 119 "The operation could not be completed temporarily." 120 case .userPresenceUnavailable: 121 "User verification is unavailable." 122 } 123 } 124 } 125 126 enum TeraUserMessages { 127 static func text(_ key: TeraUserMessageKey, bundle: Bundle? = nil) -> String { 128 let bundle = bundle ?? defaultBundle 129 return bundle.localizedString(forKey: key.rawValue, value: key.defaultValue, table: nil) 130 } 131 132 static func text( 133 for error: Error, 134 fallback: TeraUserMessageKey, 135 bundle: Bundle? = nil 136 ) -> String { 137 text(key(for: error, fallback: fallback), bundle: bundle) 138 } 139 140 static func key( 141 for error: Error, 142 fallback: TeraUserMessageKey 143 ) -> TeraUserMessageKey { 144 TeraUserMessageClassifier.key(for: error, fallback: fallback) 145 } 146 147 private static var defaultBundle: Bundle { 148 #if SWIFT_PACKAGE 149 Bundle.module 150 #else 151 Bundle.main 152 #endif 153 } 154 }