mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-28 14:35:03 -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? {
|
public var errorDescription: String? {
|
||||||
switch self {
|
switch self {
|
||||||
case .retrieve(let description):
|
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: " ")
|
return [prefix, description].compactMap({ $0 }).joined(separator: " ")
|
||||||
case .parse:
|
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:
|
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 {
|
extension String {
|
||||||
|
|
||||||
var localized: String {
|
var localized: String {
|
||||||
NSLocalizedString(
|
localizedWithFallback()
|
||||||
self,
|
|
||||||
tableName: nil,
|
|
||||||
bundle: DefaultLanguages.currentBundle,
|
|
||||||
value: "",
|
|
||||||
comment: ""
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func localized(withComment: String) -> String {
|
func localizedWith(comment: String) -> String {
|
||||||
return NSLocalizedString(
|
localizedWithFallback(comment: comment)
|
||||||
self,
|
|
||||||
tableName: nil,
|
|
||||||
bundle: DefaultLanguages.currentBundle,
|
|
||||||
value: "",
|
|
||||||
comment: withComment
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func localizedWithFormat(withArgs: CVarArg...) -> String {
|
func localizedWithFormat(withArgs: CVarArg...) -> String {
|
||||||
let format = NSLocalizedString(
|
let format = localizedWithFallback()
|
||||||
self,
|
|
||||||
tableName: nil,
|
|
||||||
bundle: DefaultLanguages.currentBundle,
|
|
||||||
value: "",
|
|
||||||
comment: ""
|
|
||||||
)
|
|
||||||
|
|
||||||
switch withArgs.count {
|
switch withArgs.count {
|
||||||
case 1: return String.localizedStringWithFormat(format, withArgs[0])
|
case 1: return String.localizedStringWithFormat(format, withArgs[0])
|
||||||
case 2: return String.localizedStringWithFormat(format, withArgs[0], withArgs[1])
|
case 2: return String.localizedStringWithFormat(format, withArgs[0], withArgs[1])
|
||||||
default: return String.localizedStringWithFormat(format, withArgs)
|
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) {
|
if let data = imageData, let image = UIImage(data: data) {
|
||||||
Image(uiImage: image).resizable()
|
Image(uiImage: image).resizable()
|
||||||
} else {
|
} else {
|
||||||
Image(category.name).resizable()
|
Image(category.icon).resizable()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user