Skip to content

Commit

Permalink
[#38] Bugfix - AppleLanguages isn't updated in some conditions, leadi…
Browse files Browse the repository at this point in the history
…ng to Apple UI Stock elements to show in the wrong language
  • Loading branch information
Decybel07 committed Jul 13, 2024
1 parent 813aa72 commit db322c0
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions L10n-swift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
18 changes: 2 additions & 16 deletions L10n_swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -1613,7 +1611,6 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand Down Expand Up @@ -1665,7 +1662,6 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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 = "";
};
Expand Down Expand Up @@ -2159,7 +2148,6 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -2219,7 +2207,6 @@
SDKROOT = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand Down Expand Up @@ -2269,7 +2256,6 @@
PRODUCT_NAME = "$(PROJECT_NAME)Tests";
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1540"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1540"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1540"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
LastUpgradeVersion = "1540"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pod try L10n-swift
## ⚠️ Requirements

- iOS 9.0+ | macOS 10.10+ | tvOS 9.0+ | watchOS 2.0+
- Swift 3.0+
- Swift 4.0+

## 👥 Communication

Expand Down
14 changes: 8 additions & 6 deletions Source/Core/Extensions/Bundle+utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ internal extension Bundle {
?? "Base"
}
set {
var preferredLanguages = Bundle.main.preferredLanguages
var preferredLanguages = self.preferredLanguages
#if swift(>=4.2)
let firstIndex = preferredLanguages.firstIndex(of: newValue)
#else
let firstIndex = preferredLanguages.index(of: newValue)
#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()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Extensions/L10n+deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Number: Numeric & CVarArg>(for key: String, resource: String? = nil, fittingWidth: Int? = nil, arg: Number, converting: @escaping (_ number: Number) -> CVarArg = { $0 }) -> String {
public func plural<Number: Numeric & CVarArg>(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
Expand Down
4 changes: 2 additions & 2 deletions Tests/DateExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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() {
Expand Down

0 comments on commit db322c0

Please sign in to comment.