From db322c091d8d020ac9b3b4c1dd0aa68a5bec6dc9 Mon Sep 17 00:00:00 2001 From: Adrian Bobrowski Date: Sat, 13 Jul 2024 12:26:29 +0200 Subject: [PATCH] [#38] Bugfix - AppleLanguages isn't updated in some conditions, leading to Apple UI Stock elements to show in the wrong language --- CHANGELOG.md | 3 +++ L10n-swift.podspec | 4 ++-- L10n_swift.xcodeproj/project.pbxproj | 18 ++---------------- .../xcshareddata/xcschemes/L10n iOS.xcscheme | 2 +- .../xcshareddata/xcschemes/L10n macOS.xcscheme | 2 +- .../xcshareddata/xcschemes/L10n tvOS.xcscheme | 2 +- .../xcschemes/L10n watchOS.xcscheme | 2 +- README.md | 2 +- Source/Core/Extensions/Bundle+utils.swift | 14 ++++++++------ Source/Core/Extensions/L10n+deprecated.swift | 2 +- Tests/DateExtensionTests.swift | 4 ++-- 11 files changed, 23 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73be544..f292782 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ # Change Log --- +## [5.10.2](https://github.com/Decybel07/L10n-swift/tree/5.10.3) (2024-07-13) +* Bugfix - AppleLanguages isn't updated in some conditions, leading to Apple UI Stock elements to show in the wrong language [#38](https://github.com/Decybel07/L10n-swift/issues/38) + ## [5.10.2](https://github.com/Decybel07/L10n-swift/tree/5.10.2) (2022-04-14) * Bugfix - Plurals does not work [#32](https://github.com/Decybel07/L10n-swift/issues/32) diff --git a/L10n-swift.podspec b/L10n-swift.podspec index f755ccd..89c0c9f 100644 --- a/L10n-swift.podspec +++ b/L10n-swift.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |spec| spec.name = 'L10n-swift' spec.module_name = 'L10n_swift' - spec.version = '5.10.2' + spec.version = '5.10.3' spec.summary = 'Localization of an application with ability to change language "on the fly" and support for plural forms in any language.' spec.description = <<-DESC @@ -24,7 +24,7 @@ Pod::Spec.new do |spec| spec.source = { :git => "https://github.com/Decybel07/L10n-swift.git", :tag => spec.version } spec.frameworks = 'Foundation' - spec.swift_versions = ['4.0', '4.1', '4.2', '5.0', '5.1', '5.2', '5.3'] + spec.swift_versions = ['4.0', '4.2', '5'] spec.ios.deployment_target = '9.0' spec.watchos.deployment_target = '2.0' diff --git a/L10n_swift.xcodeproj/project.pbxproj b/L10n_swift.xcodeproj/project.pbxproj index 3975345..08a7196 100644 --- a/L10n_swift.xcodeproj/project.pbxproj +++ b/L10n_swift.xcodeproj/project.pbxproj @@ -1388,7 +1388,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; ONLY_ACTIVE_ARCH = YES; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1422,7 +1422,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1488,7 +1488,6 @@ SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1549,7 +1548,6 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -1613,7 +1611,6 @@ SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1665,7 +1662,6 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; VALIDATE_PRODUCT = YES; }; name = Release; @@ -1731,7 +1727,6 @@ SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 4; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1792,7 +1787,6 @@ SDKROOT = watchos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 4; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -1861,7 +1855,6 @@ SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 12.0; VERSIONING_SYSTEM = "apple-generic"; @@ -1921,7 +1914,6 @@ SDKROOT = appletvos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 12.0; VALIDATE_PRODUCT = YES; @@ -1981,7 +1973,6 @@ SDKROOT = appletvos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = 12.0; }; name = Debug; @@ -2029,7 +2020,6 @@ PRODUCT_NAME = "$(PROJECT_NAME)Tests"; SDKROOT = appletvos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = 12.0; VALIDATE_PRODUCT = YES; }; @@ -2098,7 +2088,6 @@ SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -2159,7 +2148,6 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -2219,7 +2207,6 @@ SDKROOT = macosx; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -2269,7 +2256,6 @@ PRODUCT_NAME = "$(PROJECT_NAME)Tests"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/L10n_swift.xcodeproj/xcshareddata/xcschemes/L10n iOS.xcscheme b/L10n_swift.xcodeproj/xcshareddata/xcschemes/L10n iOS.xcscheme index 9897dee..2233881 100644 --- a/L10n_swift.xcodeproj/xcshareddata/xcschemes/L10n iOS.xcscheme +++ b/L10n_swift.xcodeproj/xcshareddata/xcschemes/L10n iOS.xcscheme @@ -1,6 +1,6 @@ =4.2) let firstIndex = preferredLanguages.firstIndex(of: newValue) #else @@ -25,13 +25,15 @@ internal extension Bundle { #endif if let index = firstIndex { - guard index > 0 else { - return - } preferredLanguages.remove(at: index) } - UserDefaults.standard.set([newValue] + preferredLanguages, forKey: "AppleLanguages") - UserDefaults.standard.synchronize() + preferredLanguages.insert(newValue, at: 0) + + let userDefaults = UserDefaults.standard + if preferredLanguages != (userDefaults.array(forKey: "AppleLanguages") as? [String]) { + UserDefaults.standard.set(preferredLanguages, forKey: "AppleLanguages") + UserDefaults.standard.synchronize() + } } } diff --git a/Source/Core/Extensions/L10n+deprecated.swift b/Source/Core/Extensions/L10n+deprecated.swift index 51b36d8..4c3e54e 100644 --- a/Source/Core/Extensions/L10n+deprecated.swift +++ b/Source/Core/Extensions/L10n+deprecated.swift @@ -18,7 +18,7 @@ extension L10n { - returns: A localized plural version of the string designated by `key`. This method returns `key` when `key` not found or `arg` is not a number . */ @available(*, deprecated, renamed: "plural(for:resource:fittingWidth:_:)") - open func plural(for key: String, resource: String? = nil, fittingWidth: Int? = nil, arg: Number, converting: @escaping (_ number: Number) -> CVarArg = { $0 }) -> String { + public func plural(for key: String, resource: String? = nil, fittingWidth: Int? = nil, arg: Number, converting: @escaping (_ number: Number) -> CVarArg = { $0 }) -> String { guard let arg = NumericPluralArg(arg: arg, converting: converting) else { self.logger?.info("L10n - Argument \(key.debugDescription) is not a number.") return key diff --git a/Tests/DateExtensionTests.swift b/Tests/DateExtensionTests.swift index f48418b..7cbffa8 100644 --- a/Tests/DateExtensionTests.swift +++ b/Tests/DateExtensionTests.swift @@ -26,7 +26,7 @@ final class DateExtensionTests: L10nBaseTest { self.l10nInstance.language = "pl_PL" XCTAssertEqual("", self.date.l10n(self.l10nInstance, dateStyle: .none)) - XCTAssertEqual("07.12.1993", self.date.l10n(self.l10nInstance, dateStyle: .short)) + XCTAssertEqual("7.12.1993", self.date.l10n(self.l10nInstance, dateStyle: .short)) XCTAssertEqual("07.12.1993", self.date.l10n(self.l10nInstance, dateStyle: .medium)) XCTAssertEqual("7 grudnia 1993", self.date.l10n(self.l10nInstance, dateStyle: .long)) XCTAssertEqual("wtorek, 7 grudnia 1993", self.date.l10n(self.l10nInstance, dateStyle: .full)) @@ -44,7 +44,7 @@ final class DateExtensionTests: L10nBaseTest { self.l10nInstance.language = "pl_PL" XCTAssertEqual("", self.date.l10n(self.l10nInstance, dateStyle: .none, timeStyle: .none)) - XCTAssertEqual("07.12.1993, 08:25", self.date.l10n(self.l10nInstance, dateStyle: .short, timeStyle: .short)) + XCTAssertEqual("7.12.1993, 08:25", self.date.l10n(self.l10nInstance, dateStyle: .short, timeStyle: .short)) } func testDateWithFormat() {