mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-26 13:29:31 -04:00
Localization fixes
This commit is contained in:
parent
d486d9336a
commit
409be22b29
@ -16,12 +16,12 @@ public enum LibraryRefreshError: LocalizedError {
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .retrieve(let description):
|
||||
let prefix = "library_refresh_error.retrieve.description".localized(withComment: "Library Refresh Error")
|
||||
let prefix = "library_refresh_error.retrieve.description".localizedWith(comment: "Library Refresh Error")
|
||||
return [prefix, description].compactMap({ $0 }).joined(separator: " ")
|
||||
case .parse:
|
||||
return "library_refresh_error.parse.description".localized(withComment: "Library Refresh Error")
|
||||
return "library_refresh_error.parse.description".localizedWith(comment: "Library Refresh Error")
|
||||
case .process:
|
||||
return "library_refresh_error.process.description".localized(withComment: "Library Refresh Error")
|
||||
return "library_refresh_error.process.description".localizedWith(comment: "Library Refresh Error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,38 +11,42 @@ import Foundation
|
||||
extension String {
|
||||
|
||||
var localized: String {
|
||||
NSLocalizedString(
|
||||
self,
|
||||
tableName: nil,
|
||||
bundle: DefaultLanguages.currentBundle,
|
||||
value: "",
|
||||
comment: ""
|
||||
)
|
||||
localizedWithFallback()
|
||||
}
|
||||
|
||||
func localized(withComment: String) -> String {
|
||||
return NSLocalizedString(
|
||||
self,
|
||||
tableName: nil,
|
||||
bundle: DefaultLanguages.currentBundle,
|
||||
value: "",
|
||||
comment: withComment
|
||||
)
|
||||
func localizedWith(comment: String) -> String {
|
||||
localizedWithFallback(comment: comment)
|
||||
}
|
||||
|
||||
func localizedWithFormat(withArgs: CVarArg...) -> String {
|
||||
let format = NSLocalizedString(
|
||||
self,
|
||||
tableName: nil,
|
||||
bundle: DefaultLanguages.currentBundle,
|
||||
value: "",
|
||||
comment: ""
|
||||
)
|
||||
|
||||
let format = localizedWithFallback()
|
||||
switch withArgs.count {
|
||||
case 1: return String.localizedStringWithFormat(format, withArgs[0])
|
||||
case 2: return String.localizedStringWithFormat(format, withArgs[0], withArgs[1])
|
||||
default: return String.localizedStringWithFormat(format, withArgs)
|
||||
}
|
||||
}
|
||||
|
||||
private func localizedWithFallback(
|
||||
bundle: Bundle = DefaultLanguages.currentBundle,
|
||||
comment: String = ""
|
||||
) -> String {
|
||||
let englishValue: String
|
||||
if let path = Bundle.main.path(forResource: "en", ofType: "lproj"),
|
||||
let bundle = Bundle(path: path) {
|
||||
englishValue = NSLocalizedString(self, bundle: bundle, comment: comment)
|
||||
if NSLocale.preferredLanguages.first == "en" {
|
||||
return englishValue
|
||||
}
|
||||
} else {
|
||||
englishValue = ""
|
||||
}
|
||||
return NSLocalizedString(
|
||||
self,
|
||||
tableName: nil,
|
||||
bundle: bundle,
|
||||
value: englishValue, // fall back to this, if translation not found
|
||||
comment: comment
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ struct Favicon: View {
|
||||
if let data = imageData, let image = UIImage(data: data) {
|
||||
Image(uiImage: image).resizable()
|
||||
} else {
|
||||
Image(category.name).resizable()
|
||||
Image(category.icon).resizable()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user