Merge pull request #605 from kiwix/603-proper-handling-of-ui-languages

Remove default/enforced language code solution
This commit is contained in:
Kelson 2023-12-30 22:33:08 +01:00 committed by GitHub
commit cd1c730e98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1 additions and 42 deletions

View File

@ -19,9 +19,6 @@ struct Kiwix: App {
private let fileMonitor: DirectoryMonitor
init() {
if let enforcedLanguage: String = Config.value(for: .enforcedLanguage) {
DefaultLanguages.enforce(language: enforcedLanguage)
}
fileMonitor = DirectoryMonitor(url: URL.documentDirectory) { LibraryOperations.scanDirectory($0) }
LibraryOperations.registerBackgroundTask()
UNUserNotificationCenter.current().delegate = appDelegate

View File

@ -19,9 +19,6 @@ struct Kiwix: App {
private let notificationCenterDelegate = NotificationCenterDelegate()
init() {
if let enforcedLanguage: String = Config.value(for: .enforcedLanguage) {
DefaultLanguages.enforce(language: enforcedLanguage)
}
UNUserNotificationCenter.current().delegate = notificationCenterDelegate
}

View File

@ -113,7 +113,6 @@
9882080D2B2CF57A00D6B1AE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 988207FE2B2CF57A00D6B1AE /* Localizable.strings */; };
9882080E2B2CF57A00D6B1AE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 988208012B2CF57A00D6B1AE /* Localizable.strings */; };
9882080F2B2CF57A00D6B1AE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 988208042B2CF57A00D6B1AE /* Localizable.strings */; };
98B5D3252B2F36680047CC13 /* DefaultLanguages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B5D3242B2F36680047CC13 /* DefaultLanguages.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -258,7 +257,6 @@
988207FF2B2CF57A00D6B1AE /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = Localizable.strings; sourceTree = "<group>"; };
988208022B2CF57A00D6B1AE /* mk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = mk; path = Localizable.strings; sourceTree = "<group>"; };
988208052B2CF57A00D6B1AE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = Localizable.strings; sourceTree = "<group>"; };
98B5D3242B2F36680047CC13 /* DefaultLanguages.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultLanguages.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -571,7 +569,6 @@
97E94B26271EF359005B0295 /* Support */ = {
isa = PBXGroup;
children = (
98B5D3242B2F36680047CC13 /* DefaultLanguages.swift */,
988207FD2B2CF57A00D6B1AE /* de.lproj */,
988208032B2CF57A00D6B1AE /* en.lproj */,
988207EE2B2CF57A00D6B1AE /* he.lproj */,
@ -946,7 +943,6 @@
974E7EE92930201500BDF59C /* ZimFileService.swift in Sources */,
973A0DFD283100C300B41E71 /* ZimFilesOpened.swift in Sources */,
9744068A28CF65AE00916BD4 /* LibraryOperations.swift in Sources */,
98B5D3252B2F36680047CC13 /* DefaultLanguages.swift in Sources */,
972DE4B62814A502004FD9B9 /* Enum.swift in Sources */,
9744068728CE263800916BD4 /* DirectoryMonitor.swift in Sources */,
974C33A9285589E900DF6F4C /* Patches.swift in Sources */,

View File

@ -66,7 +66,6 @@ enum Config: String {
case showSearchSnippetInSettings = "SETTINGS_SHOW_SEARCH_SNIPPET"
case aboutText = "CUSTOM_ABOUT_TEXT"
case aboutWebsite = "CUSTOM_ABOUT_WEBSITE"
case enforcedLanguage = "ENFORCED_LANGUAGE"
static func value<T>(for key: Config) -> T? where T: LosslessStringConvertible {
guard let object = Bundle.main.object(forInfoDictionaryKey: key.rawValue) else {

View File

@ -28,7 +28,7 @@ extension String {
}
private func localizedWithFallback(
bundle: Bundle = DefaultLanguages.currentBundle,
bundle: Bundle = Bundle.main,
comment: String = ""
) -> String {
let englishValue: String

View File

@ -1,30 +0,0 @@
//
// DefaultLanguages.swift
// Kiwix
//
import Foundation
import Defaults
/// Enforce the selected languages on start up time
/// It fully works on 2nd launch, as @main cannot be easily overriden in SwiftUI
/// For the first launch we can override the bundle we use for localization
enum DefaultLanguages {
/// We need a work around bundle with a specific
static var currentBundle: Bundle = Bundle.main
static func enforce(language: String) {
if UserDefaults.standard[.isFirstLaunch] {
UserDefaults.standard[.isFirstLaunch] = false
// override the system picked languages at start
UserDefaults.standard.set([language], forKey: "AppleLanguages")
// override the bundle used on first launch of the app:
if let path = Bundle.main.path(forResource: language, ofType: "lproj") {
if let langBundle = Bundle.init(path: path) {
currentBundle = langBundle
}
}
}
}
}