From d5788312678437ee87e59f00cc46e3e7175c7aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20B=C3=B8dskov?= Date: Tue, 18 Jan 2022 15:43:46 +0100 Subject: [PATCH 1/4] Enables the ability to skip looking up persisted translations Will be needed when NStackSDK uses updateOptions .never --- .../Classes/Manager/LocalizationManager.swift | 31 ++++++++++++------- .../Tests/LocalizationManagerTests.swift | 1 + Podfile.lock | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/LocalizationManager/Classes/Manager/LocalizationManager.swift b/LocalizationManager/Classes/Manager/LocalizationManager.swift index 721b5ee..b3425a8 100644 --- a/LocalizationManager/Classes/Manager/LocalizationManager.swift +++ b/LocalizationManager/Classes/Manager/LocalizationManager.swift @@ -200,6 +200,7 @@ public class LocalizationManager w contextRepository: LocalizationContextRepository, localizableModel: LocalizableModel.Type, updateMode: UpdateMode = .automatic, + lookupPersistedLocalizations: Bool = true, fileManager: FileManager = .default, userDefaults: UserDefaults = .standard) { // Set the properties @@ -215,7 +216,8 @@ public class LocalizationManager w stateObserver.startObserving() // Load persisted or fallback translations - if (try? localization()) == nil { + + if (try? localization(lookupPersistedLocalizations: lookupPersistedLocalizations)) == nil { parseFallbackJSONLocalizations() } @@ -563,7 +565,7 @@ public class LocalizationManager w /// If a persisted version cannot be found, the fallback json file in the bundle will be used. /// /// - Returns: A localizations object. - public func localization(localeId: String? = nil) throws -> T { + public func localization(localeId: String? = nil, lookupPersistedLocalizations: Bool = true) throws -> T { guard let locale = localeId ?? bestFitLanguage?.locale.identifier ?? languageOverride?.locale.identifier ?? getAvailablePreferredLanguageLocale() @@ -584,7 +586,7 @@ public class LocalizationManager w } // Load persisted or fallback localizations - try createLocalizationObject(locale) + try createLocalizationObject(locale, lookupPersistedLocalizations: lookupPersistedLocalizations) // Now we must have correct localizations, so return it if let to = localizableObjectDictonary[locale] as? T { @@ -620,22 +622,27 @@ public class LocalizationManager w } /// Loads and initializes the localizations object from either persisted or fallback dictionary. - func createLocalizationObject(_ localeId: String) throws { + func createLocalizationObject(_ localeId: String, lookupPersistedLocalizations: Bool = true) throws { let localization: LocalizationResponse var shouldUnwrapLocalization = false - //try to use persisted localizations for locale - if let persisted = try persistedLocalization(localeId: localeId), - let typeString = userDefaults.string(forKey: Constants.Keys.persistedLocalizationType), - let localizationType = PersistedLocalizationType(rawValue: typeString) { - localization = persisted - shouldUnwrapLocalization = localizationType == .all // only unwrap when all localizations are stored + if lookupPersistedLocalizations { + //try to use persisted localizations for locale + if let persisted = try persistedLocalization(localeId: localeId), + let typeString = userDefaults.string(forKey: Constants.Keys.persistedLocalizationType), + let localizationType = PersistedLocalizationType(rawValue: typeString) { + localization = persisted + shouldUnwrapLocalization = localizationType == .all // only unwrap when all localizations are stored + } else { + //otherwise search for fallback + localization = try fallbackLocalization(localeId: localeId) + } } else { - //otherwise search for fallback localization = try fallbackLocalization(localeId: localeId) } + // Figure out and set localizations guard let parsed = try processAllLocalizations(localization, shouldUnwrap: shouldUnwrapLocalization) else { localizableObjectDictonary.removeValue(forKey: localeId) @@ -759,7 +766,7 @@ public class LocalizationManager w // Iterate through bundle until we find the localizations file for bundle: Bundle in [Bundle(for: localizableModel.self)] + contextRepository.getLocalizationBundles() { // Check if bundle contains localizations file, otheriwse continue with next bundle - guard let filePath = bundle.path(forResource: "Localizations_\(localeId)", ofType: "json") else { + guard let filePath = bundle.path(forResource: "Localization_\(localeId)", ofType: "json") else { continue } diff --git a/LocalizationManagerTests/Tests/LocalizationManagerTests.swift b/LocalizationManagerTests/Tests/LocalizationManagerTests.swift index 364d2e7..2398397 100644 --- a/LocalizationManagerTests/Tests/LocalizationManagerTests.swift +++ b/LocalizationManagerTests/Tests/LocalizationManagerTests.swift @@ -160,6 +160,7 @@ class LocalizationManagerTests: XCTestCase { let expect = expectation(description: "") let config = mockLocalizationConfigWithUpdate let localizations: [DefaultLocalizationDescriptor] = [config, mockLocalizationConfigWithUpdate, mockLocalizationConfigWithoutUpdate] + expect.expectedFulfillmentCount = 3 repositoryMock.availableLocalizations = localizations repositoryMock.localizationsResponse = nil manager.updateLocalizations { (error) in diff --git a/Podfile.lock b/Podfile.lock index 390516e..fd0c61d 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -17,4 +17,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 54f5f694e106ddcbcd3724c53daeefebfe959bc1 -COCOAPODS: 1.8.4 +COCOAPODS: 1.11.2 From fcc03189bd720a931cb73bf4875b0cfa549ece82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20B=C3=B8dskov?= Date: Wed, 19 Jan 2022 07:45:45 +0100 Subject: [PATCH 2/4] changes filename back to correct format when falling back to JSON --- .../ApplicationStateObserverDelegate.swift | 2 +- .../ApplicationStateObserverType.swift | 2 +- .../Classes/Manager/AcceptLanguageProvider.swift | 2 +- LocalizationManager/Classes/Manager/LocalizationManager.swift | 2 +- .../Classes/Protocols/LocalizationManagerDelegate.swift | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/LocalizationManager/Classes/Application State Observer/ApplicationStateObserverDelegate.swift b/LocalizationManager/Classes/Application State Observer/ApplicationStateObserverDelegate.swift index 9d38d20..c3b9df4 100644 --- a/LocalizationManager/Classes/Application State Observer/ApplicationStateObserverDelegate.swift +++ b/LocalizationManager/Classes/Application State Observer/ApplicationStateObserverDelegate.swift @@ -10,7 +10,7 @@ import Foundation /// A delegate protocol for application state observer which you should implement if you /// want to listen to application state changes. -internal protocol ApplicationStateObserverDelegate: class { +internal protocol ApplicationStateObserverDelegate: AnyObject { /// A function called whenever an application state changes. /// diff --git a/LocalizationManager/Classes/Application State Observer/ApplicationStateObserverType.swift b/LocalizationManager/Classes/Application State Observer/ApplicationStateObserverType.swift index 4c64d75..c6d2643 100644 --- a/LocalizationManager/Classes/Application State Observer/ApplicationStateObserverType.swift +++ b/LocalizationManager/Classes/Application State Observer/ApplicationStateObserverType.swift @@ -9,7 +9,7 @@ import Foundation /// A type of class that can observe application state. -internal protocol ApplicationStateObserverType: class { +internal protocol ApplicationStateObserverType: AnyObject { var delegate: ApplicationStateObserverDelegate? { get set } func startObserving() func stopObserving() diff --git a/LocalizationManager/Classes/Manager/AcceptLanguageProvider.swift b/LocalizationManager/Classes/Manager/AcceptLanguageProvider.swift index 0d55f91..6b12758 100644 --- a/LocalizationManager/Classes/Manager/AcceptLanguageProvider.swift +++ b/LocalizationManager/Classes/Manager/AcceptLanguageProvider.swift @@ -8,7 +8,7 @@ import Foundation -public protocol AcceptLanguageProviderType: class { +public protocol AcceptLanguageProviderType: AnyObject { /// Creates the accept language provider. /// diff --git a/LocalizationManager/Classes/Manager/LocalizationManager.swift b/LocalizationManager/Classes/Manager/LocalizationManager.swift index b3425a8..72165cb 100644 --- a/LocalizationManager/Classes/Manager/LocalizationManager.swift +++ b/LocalizationManager/Classes/Manager/LocalizationManager.swift @@ -766,7 +766,7 @@ public class LocalizationManager w // Iterate through bundle until we find the localizations file for bundle: Bundle in [Bundle(for: localizableModel.self)] + contextRepository.getLocalizationBundles() { // Check if bundle contains localizations file, otheriwse continue with next bundle - guard let filePath = bundle.path(forResource: "Localization_\(localeId)", ofType: "json") else { + guard let filePath = bundle.path(forResource: "Localizations_\(localeId)", ofType: "json") else { continue } diff --git a/LocalizationManager/Classes/Protocols/LocalizationManagerDelegate.swift b/LocalizationManager/Classes/Protocols/LocalizationManagerDelegate.swift index 59dd7ba..4e6d986 100644 --- a/LocalizationManager/Classes/Protocols/LocalizationManagerDelegate.swift +++ b/LocalizationManager/Classes/Protocols/LocalizationManagerDelegate.swift @@ -8,6 +8,6 @@ import Foundation -public protocol LocalizationManagerDelegate: class { +public protocol LocalizationManagerDelegate: AnyObject { func localizationManager(languageUpdated: LanguageModel?) } From 004a9b7b0028d67e58c7108b6478194ded5c9329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20B=C3=B8dskov?= Date: Wed, 19 Jan 2022 11:13:49 +0100 Subject: [PATCH 3/4] fixing some of the failing tests --- LocalizationManager.xcodeproj/project.pbxproj | 48 +++++++++---------- ...on_da-DK.json => Localizations_da-DK.json} | 0 ...on_en-GB.json => Localizations_en-GB.json} | 0 ...on_fr-FR.json => Localizations_fr-FR.json} | 0 .../Tests/LocalizationManagerTests.swift | 11 +++-- 5 files changed, 31 insertions(+), 28 deletions(-) rename LocalizationManagerTests/Resources/{Localization_da-DK.json => Localizations_da-DK.json} (100%) rename LocalizationManagerTests/Resources/{Localization_en-GB.json => Localizations_en-GB.json} (100%) rename LocalizationManagerTests/Resources/{Localization_fr-FR.json => Localizations_fr-FR.json} (100%) diff --git a/LocalizationManager.xcodeproj/project.pbxproj b/LocalizationManager.xcodeproj/project.pbxproj index 10dfd08..ab9e083 100644 --- a/LocalizationManager.xcodeproj/project.pbxproj +++ b/LocalizationManager.xcodeproj/project.pbxproj @@ -91,15 +91,15 @@ B464DB702319CCAE00713265 /* LocalizationManager+ApplicationState.swift in Sources */ = {isa = PBXBuildFile; fileRef = B464DB6C2319CCAE00713265 /* LocalizationManager+ApplicationState.swift */; }; B4B6C94F231ECB8B001A8E5C /* DefaultLanguage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4B6C94E231ECB8B001A8E5C /* DefaultLanguage.swift */; }; B4B6C954231ED7B8001A8E5C /* LocalizationManager_iOS.h in Headers */ = {isa = PBXBuildFile; fileRef = B4B6C953231ED7B7001A8E5C /* LocalizationManager_iOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; - B4B6C966231ED7D4001A8E5C /* Localization_da-DK.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C956231ED7D4001A8E5C /* Localization_da-DK.json */; }; - B4B6C967231ED7D4001A8E5C /* Localization_da-DK.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C956231ED7D4001A8E5C /* Localization_da-DK.json */; }; - B4B6C968231ED7D4001A8E5C /* Localization_da-DK.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C956231ED7D4001A8E5C /* Localization_da-DK.json */; }; - B4B6C969231ED7D4001A8E5C /* Localization_fr-FR.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C957231ED7D4001A8E5C /* Localization_fr-FR.json */; }; - B4B6C96A231ED7D4001A8E5C /* Localization_fr-FR.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C957231ED7D4001A8E5C /* Localization_fr-FR.json */; }; - B4B6C96B231ED7D4001A8E5C /* Localization_fr-FR.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C957231ED7D4001A8E5C /* Localization_fr-FR.json */; }; - B4B6C96C231ED7D4001A8E5C /* Localization_en-GB.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C958231ED7D4001A8E5C /* Localization_en-GB.json */; }; - B4B6C96D231ED7D4001A8E5C /* Localization_en-GB.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C958231ED7D4001A8E5C /* Localization_en-GB.json */; }; - B4B6C96E231ED7D4001A8E5C /* Localization_en-GB.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C958231ED7D4001A8E5C /* Localization_en-GB.json */; }; + B4B6C966231ED7D4001A8E5C /* Localizations_da-DK.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C956231ED7D4001A8E5C /* Localizations_da-DK.json */; }; + B4B6C967231ED7D4001A8E5C /* Localizations_da-DK.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C956231ED7D4001A8E5C /* Localizations_da-DK.json */; }; + B4B6C968231ED7D4001A8E5C /* Localizations_da-DK.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C956231ED7D4001A8E5C /* Localizations_da-DK.json */; }; + B4B6C969231ED7D4001A8E5C /* Localizations_fr-FR.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C957231ED7D4001A8E5C /* Localizations_fr-FR.json */; }; + B4B6C96A231ED7D4001A8E5C /* Localizations_fr-FR.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C957231ED7D4001A8E5C /* Localizations_fr-FR.json */; }; + B4B6C96B231ED7D4001A8E5C /* Localizations_fr-FR.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C957231ED7D4001A8E5C /* Localizations_fr-FR.json */; }; + B4B6C96C231ED7D4001A8E5C /* Localizations_en-GB.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C958231ED7D4001A8E5C /* Localizations_en-GB.json */; }; + B4B6C96D231ED7D4001A8E5C /* Localizations_en-GB.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C958231ED7D4001A8E5C /* Localizations_en-GB.json */; }; + B4B6C96E231ED7D4001A8E5C /* Localizations_en-GB.json in Resources */ = {isa = PBXBuildFile; fileRef = B4B6C958231ED7D4001A8E5C /* Localizations_en-GB.json */; }; B4B6C96F231ED7D4001A8E5C /* Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4B6C95A231ED7D4001A8E5C /* Localization.swift */; }; B4B6C970231ED7D4001A8E5C /* Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4B6C95A231ED7D4001A8E5C /* Localization.swift */; }; B4B6C971231ED7D4001A8E5C /* Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4B6C95A231ED7D4001A8E5C /* Localization.swift */; }; @@ -193,9 +193,9 @@ B490AD7123356F4B00260A17 /* AutoMockable.generated.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutoMockable.generated.swift; sourceTree = ""; }; B4B6C94E231ECB8B001A8E5C /* DefaultLanguage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultLanguage.swift; sourceTree = ""; }; B4B6C953231ED7B7001A8E5C /* LocalizationManager_iOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizationManager_iOS.h; sourceTree = ""; }; - B4B6C956231ED7D4001A8E5C /* Localization_da-DK.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Localization_da-DK.json"; sourceTree = ""; }; - B4B6C957231ED7D4001A8E5C /* Localization_fr-FR.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Localization_fr-FR.json"; sourceTree = ""; }; - B4B6C958231ED7D4001A8E5C /* Localization_en-GB.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Localization_en-GB.json"; sourceTree = ""; }; + B4B6C956231ED7D4001A8E5C /* Localizations_da-DK.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Localizations_da-DK.json"; sourceTree = ""; }; + B4B6C957231ED7D4001A8E5C /* Localizations_fr-FR.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Localizations_fr-FR.json"; sourceTree = ""; }; + B4B6C958231ED7D4001A8E5C /* Localizations_en-GB.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Localizations_en-GB.json"; sourceTree = ""; }; B4B6C95A231ED7D4001A8E5C /* Localization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Localization.swift; sourceTree = ""; }; B4B6C95D231ED7D4001A8E5C /* LocalizationsRepositoryMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalizationsRepositoryMock.swift; sourceTree = ""; }; B4B6C95E231ED7D4001A8E5C /* FileManagerMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileManagerMock.swift; sourceTree = ""; }; @@ -350,9 +350,9 @@ B4B6C955231ED7D4001A8E5C /* Resources */ = { isa = PBXGroup; children = ( - B4B6C956231ED7D4001A8E5C /* Localization_da-DK.json */, - B4B6C957231ED7D4001A8E5C /* Localization_fr-FR.json */, - B4B6C958231ED7D4001A8E5C /* Localization_en-GB.json */, + B4B6C956231ED7D4001A8E5C /* Localizations_da-DK.json */, + B4B6C957231ED7D4001A8E5C /* Localizations_fr-FR.json */, + B4B6C958231ED7D4001A8E5C /* Localizations_en-GB.json */, ); path = Resources; sourceTree = ""; @@ -752,9 +752,9 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - B4B6C96D231ED7D4001A8E5C /* Localization_en-GB.json in Resources */, - B4B6C96A231ED7D4001A8E5C /* Localization_fr-FR.json in Resources */, - B4B6C967231ED7D4001A8E5C /* Localization_da-DK.json in Resources */, + B4B6C96D231ED7D4001A8E5C /* Localizations_en-GB.json in Resources */, + B4B6C96A231ED7D4001A8E5C /* Localizations_fr-FR.json in Resources */, + B4B6C967231ED7D4001A8E5C /* Localizations_da-DK.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -776,9 +776,9 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - B4B6C96E231ED7D4001A8E5C /* Localization_en-GB.json in Resources */, - B4B6C96B231ED7D4001A8E5C /* Localization_fr-FR.json in Resources */, - B4B6C968231ED7D4001A8E5C /* Localization_da-DK.json in Resources */, + B4B6C96E231ED7D4001A8E5C /* Localizations_en-GB.json in Resources */, + B4B6C96B231ED7D4001A8E5C /* Localizations_fr-FR.json in Resources */, + B4B6C968231ED7D4001A8E5C /* Localizations_da-DK.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -793,9 +793,9 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - B4B6C96C231ED7D4001A8E5C /* Localization_en-GB.json in Resources */, - B4B6C969231ED7D4001A8E5C /* Localization_fr-FR.json in Resources */, - B4B6C966231ED7D4001A8E5C /* Localization_da-DK.json in Resources */, + B4B6C96C231ED7D4001A8E5C /* Localizations_en-GB.json in Resources */, + B4B6C969231ED7D4001A8E5C /* Localizations_fr-FR.json in Resources */, + B4B6C966231ED7D4001A8E5C /* Localizations_da-DK.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/LocalizationManagerTests/Resources/Localization_da-DK.json b/LocalizationManagerTests/Resources/Localizations_da-DK.json similarity index 100% rename from LocalizationManagerTests/Resources/Localization_da-DK.json rename to LocalizationManagerTests/Resources/Localizations_da-DK.json diff --git a/LocalizationManagerTests/Resources/Localization_en-GB.json b/LocalizationManagerTests/Resources/Localizations_en-GB.json similarity index 100% rename from LocalizationManagerTests/Resources/Localization_en-GB.json rename to LocalizationManagerTests/Resources/Localizations_en-GB.json diff --git a/LocalizationManagerTests/Resources/Localization_fr-FR.json b/LocalizationManagerTests/Resources/Localizations_fr-FR.json similarity index 100% rename from LocalizationManagerTests/Resources/Localization_fr-FR.json rename to LocalizationManagerTests/Resources/Localizations_fr-FR.json diff --git a/LocalizationManagerTests/Tests/LocalizationManagerTests.swift b/LocalizationManagerTests/Tests/LocalizationManagerTests.swift index 2398397..69daa4e 100644 --- a/LocalizationManagerTests/Tests/LocalizationManagerTests.swift +++ b/LocalizationManagerTests/Tests/LocalizationManagerTests.swift @@ -159,17 +159,20 @@ class LocalizationManagerTests: XCTestCase { func testUpdateLocalizationsFail() { let expect = expectation(description: "") let config = mockLocalizationConfigWithUpdate + let expectedNumberOfNilValues = 2 + var currentNumberOfNilValuesReceived = 0 let localizations: [DefaultLocalizationDescriptor] = [config, mockLocalizationConfigWithUpdate, mockLocalizationConfigWithoutUpdate] expect.expectedFulfillmentCount = 3 repositoryMock.availableLocalizations = localizations repositoryMock.localizationsResponse = nil manager.updateLocalizations { (error) in - XCTAssertNotNil(error) + if error != nil { + currentNumberOfNilValuesReceived += 1 + } + XCTAssertTrue(currentNumberOfNilValuesReceived <= expectedNumberOfNilValues) expect.fulfill() } - waitForExpectations(timeout: 1.0) { (_) in - XCTFail() - } + wait(for: [expect], timeout: 1.0) } func testUpdateCurrentLanguageWithBestFit() { From 707f568f4b18fe5398047d42feb9411b92f0b870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20B=C3=B8dskov?= Date: Wed, 19 Jan 2022 16:26:01 +0100 Subject: [PATCH 4/4] removes lookupPersistedLocalizations again and introduces new updateMode enum value instead --- .../Manager/LocalizationManager+ApplicationState.swift | 4 +++- .../Classes/Manager/LocalizationManager.swift | 8 ++++---- LocalizationManager/Classes/Models/UpdateMode.swift | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/LocalizationManager/Classes/Manager/LocalizationManager+ApplicationState.swift b/LocalizationManager/Classes/Manager/LocalizationManager+ApplicationState.swift index 2560eb1..4d2e9c8 100644 --- a/LocalizationManager/Classes/Manager/LocalizationManager+ApplicationState.swift +++ b/LocalizationManager/Classes/Manager/LocalizationManager+ApplicationState.swift @@ -18,10 +18,12 @@ extension LocalizationManager: ApplicationStateObserverDelegate { case .automatic: // Update localizations when we go to foreground and update mode is automatic updateLocalizations() - case .manual: // Don't do anything on manual update mode break + case .never: + // Same goes for never + break } case .background: diff --git a/LocalizationManager/Classes/Manager/LocalizationManager.swift b/LocalizationManager/Classes/Manager/LocalizationManager.swift index 72165cb..5861b9c 100644 --- a/LocalizationManager/Classes/Manager/LocalizationManager.swift +++ b/LocalizationManager/Classes/Manager/LocalizationManager.swift @@ -200,7 +200,6 @@ public class LocalizationManager w contextRepository: LocalizationContextRepository, localizableModel: LocalizableModel.Type, updateMode: UpdateMode = .automatic, - lookupPersistedLocalizations: Bool = true, fileManager: FileManager = .default, userDefaults: UserDefaults = .standard) { // Set the properties @@ -216,8 +215,7 @@ public class LocalizationManager w stateObserver.startObserving() // Load persisted or fallback translations - - if (try? localization(lookupPersistedLocalizations: lookupPersistedLocalizations)) == nil { + if (try? localization(lookupPersistedLocalizations: updateMode != .never)) == nil { parseFallbackJSONLocalizations() } @@ -225,10 +223,12 @@ public class LocalizationManager w case .automatic: // Try updating the localizations updateLocalizations() - case .manual: // Don't do anything on manual update mode break + case .never: + // Same goes for never + break } } diff --git a/LocalizationManager/Classes/Models/UpdateMode.swift b/LocalizationManager/Classes/Models/UpdateMode.swift index 715fe98..aaa9d89 100644 --- a/LocalizationManager/Classes/Models/UpdateMode.swift +++ b/LocalizationManager/Classes/Models/UpdateMode.swift @@ -15,4 +15,5 @@ import Foundation public enum UpdateMode { case automatic case manual + case never }