Skip to content

Commit 5d6992f

Browse files
committed
setLanguage method not working in SwiftUI issue fixed
1 parent 95546bd commit 5d6992f

21 files changed

+74
-40
lines changed

AKLanguageManager.podspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
Pod::Spec.new do |s|
22

3-
s.ios.deployment_target = '13.0'
4-
s.tvos.deployment_target = '13.0'
53
s.name = "AKLanguageManager"
64
s.summary = "AKLanguageManager is a language manager for iOS and tvOS applications."
75
s.requires_arc = true
86

9-
s.version = "1.0.1"
7+
s.version = "1.0.2"
108
s.license = { :type => "MIT", :file => "LICENSE" }
119
s.author = { "Amr Koritem" => "amr.koritem92@gmail.com" }
1210
s.homepage = "https://github.com/AmrKoritem/AKLanguageManager"
1311
s.source = { :git => "https://github.com/AmrKoritem/AKLanguageManager.git",
14-
:tag => "#{s.version}" }
12+
:tag => "v#{s.version}" }
1513

1614
s.framework = "SwiftUI"
1715
s.source_files = "Sources/AKLanguageManager/**/*.{swift}"
1816
s.swift_version = "5.0"
17+
s.ios.deployment_target = '13.0'
18+
s.tvos.deployment_target = '13.0'
1919

2020
end

AKLanguageManager.xcodeproj/project.pbxproj

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,44 @@
196196
path = Helpers;
197197
sourceTree = "<group>";
198198
};
199+
1D7D4CFE29059D8D00085878 /* UIKit */ = {
200+
isa = PBXGroup;
201+
children = (
202+
1D4074F928D01699000A1DF0 /* UIView+Localizable.swift */,
203+
1D4074FF28D01B07000A1DF0 /* UILabel+Localizable.swift */,
204+
1D40750128D01B63000A1DF0 /* UITextView+Localizable.swift */,
205+
1D40750328D01BA9000A1DF0 /* UITextField+Localizable.swift */,
206+
1D40750528D01BEF000A1DF0 /* UITabBar+Localizable.swift */,
207+
1D40750728D01C53000A1DF0 /* UIButton+Localizable.swift */,
208+
1D40750928D01D08000A1DF0 /* UISegmentedControl+Localizable.swift */,
209+
1D2CC63028D0D5640000DFEF /* UIImageView+Localizable.swift */,
210+
1D98A9B428E8C4D2007AFCD1 /* UIImage+Localized.swift */,
211+
1D98A9B828E8C543007AFCD1 /* NSAttributedString+Localized.swift */,
212+
1D98A9B628E8C50C007AFCD1 /* NSTextAlignment+Localized.swift */,
213+
);
214+
path = UIKit;
215+
sourceTree = "<group>";
216+
};
217+
1D7D4CFF29059DC600085878 /* SwiftUI */ = {
218+
isa = PBXGroup;
219+
children = (
220+
1D2A6C8528F0FD34000EE30D /* View+Localized.swift */,
221+
1D2A6C8728F0FD6E000EE30D /* Image+Localized.swift */,
222+
);
223+
path = SwiftUI;
224+
sourceTree = "<group>";
225+
};
226+
1D7D4D0129064E1600085878 /* DataTypes */ = {
227+
isa = PBXGroup;
228+
children = (
229+
1D4074FB28D0181B000A1DF0 /* String+Localized.swift */,
230+
1D98A9BA28E8C65C007AFCD1 /* Int+Localized.swift */,
231+
1D98A9BC28E8CA43007AFCD1 /* Double+Localized.swift */,
232+
1D98A9BE28E8CB29007AFCD1 /* NSNumber+Localized.swift */,
233+
);
234+
path = DataTypes;
235+
sourceTree = "<group>";
236+
};
199237
1D87DACA28C40C7D00838580 = {
200238
isa = PBXGroup;
201239
children = (
@@ -262,23 +300,9 @@
262300
children = (
263301
1D4074FD28D01A6C000A1DF0 /* Bundle+Swizzle.swift */,
264302
1DD5803428CAF0CB00DCD270 /* UIView+Swizzle.swift */,
265-
1D4074F928D01699000A1DF0 /* UIView+Localizable.swift */,
266-
1D4074FF28D01B07000A1DF0 /* UILabel+Localizable.swift */,
267-
1D40750128D01B63000A1DF0 /* UITextView+Localizable.swift */,
268-
1D40750328D01BA9000A1DF0 /* UITextField+Localizable.swift */,
269-
1D40750528D01BEF000A1DF0 /* UITabBar+Localizable.swift */,
270-
1D40750728D01C53000A1DF0 /* UIButton+Localizable.swift */,
271-
1D40750928D01D08000A1DF0 /* UISegmentedControl+Localizable.swift */,
272-
1D2CC63028D0D5640000DFEF /* UIImageView+Localizable.swift */,
273-
1D4074FB28D0181B000A1DF0 /* String+Localized.swift */,
274-
1D98A9BA28E8C65C007AFCD1 /* Int+Localized.swift */,
275-
1D98A9BC28E8CA43007AFCD1 /* Double+Localized.swift */,
276-
1D98A9B828E8C543007AFCD1 /* NSAttributedString+Localized.swift */,
277-
1D98A9BE28E8CB29007AFCD1 /* NSNumber+Localized.swift */,
278-
1D98A9B428E8C4D2007AFCD1 /* UIImage+Localized.swift */,
279-
1D98A9B628E8C50C007AFCD1 /* NSTextAlignment+Localized.swift */,
280-
1D2A6C8528F0FD34000EE30D /* View+Localized.swift */,
281-
1D2A6C8728F0FD6E000EE30D /* Image+Localized.swift */,
303+
1D7D4D0129064E1600085878 /* DataTypes */,
304+
1D7D4CFF29059DC600085878 /* SwiftUI */,
305+
1D7D4CFE29059D8D00085878 /* UIKit */,
282306
);
283307
path = Extensions;
284308
sourceTree = "<group>";

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,16 @@ struct LangaugeView: View {
155155
// prints 01.10 مفتاح
156156
```
157157

158-
Please check the example project in this repo to see how it works. You can check a full set of examples [here](https://github.com/AmrKoritem/AKLibrariesExamples) as well.
158+
## Examples
159159

160-
## Contribution
160+
You can check the example project here to see AKLanguageManager in action 🥳.<br>
161+
You can check a full set of examples [here](https://github.com/AmrKoritem/AKLibrariesExamples) as well.
161162

162-
All contributions are welcome. Please check the [Known issues](https://github.com/AmrKoritem/AKLanguageManager#known-issues) and [Future plans](https://github.com/AmrKoritem/AKLanguageManager#future-plans) sections if you don't know where to start. And of course feel free to raise your own issues and create PRs for them!
163+
## Contribution 🎉
163164

164-
## Known issues
165+
All contributions are welcome.Feel free to check the [Known issues](https://github.com/AmrKoritem/AKLanguageManager#known-issues) and [Future plans](https://github.com/AmrKoritem/AKLanguageManager#future-plans) sections if you don't know where to start. And of course feel free to raise your own issues and create PRs for them 💪
166+
167+
## Known issues 🫣
165168

166169
1 - Strings shown in launch screen are not localized. [#6](https://github.com/AmrKoritem/AKLanguageManager/issues/6)<br>
167170
Unfortunately, this is intended by apple as stated [here](https://developer.apple.com/design/human-interface-guidelines/patterns/launching/#:~:text=Avoid%20including%20text%20on%20your%20launch%20screen.).
@@ -171,18 +174,18 @@ All contributions are welcome. Please check the [Known issues](https://github.co
171174

172175
3 - SF Symbol images size is reduced when their direction change. [#8](https://github.com/AmrKoritem/AKLanguageManager/issues/8)<br>
173176

174-
## Future plans
177+
## Future plans 🧐
175178

176179
1 - Get localized strings with comments. [#9](https://github.com/AmrKoritem/AKLanguageManager/issues/9)<br>
177180
2 - Localizing plurals. [#10](https://github.com/AmrKoritem/AKLanguageManager/issues/10)<br>
178181
3 - Carthage support. [#11](https://github.com/AmrKoritem/AKLanguageManager/issues/11)<br>
179182
4 - Check text language. [#12](https://github.com/AmrKoritem/AKLanguageManager/issues/12)<br>
180183

181-
## Credit
184+
## Credit 😇
182185

183186
This library was inspired by [Abedalkareem's LanguageManager-iOS](https://github.com/Abedalkareem/LanguageManager-iOS) library. Please check his work and give him the credit he deserves 🚀
184187

185-
## Find me
188+
## Find me 🥰
186189

187190
[LinkedIn](https://www.linkedin.com/in/amr-koritem-976bb0125/)
188191

Sources/AKLanguageManager/AKLanguageManager.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ public final class AKLanguageManager: AKLanguageManagerProtocol {
7979
return Language(rawValue: selectedLanguage) ?? defaultLanguage
8080
}
8181
set {
82-
storage.set(newValue.rawValue, forKey: Language.Keys.selectedLanguage)
83-
guard observedLocalizer?.selectedLanguage != newValue else { return }
84-
observedLocalizer?.selectedLanguage = newValue
82+
defer {
83+
storage.set(newValue.rawValue, forKey: Language.Keys.selectedLanguage)
84+
}
85+
guard let observedLocalizer = observedLocalizer,
86+
selectedLanguage != newValue else { return }
87+
observedLocalizer.objectWillChange.send()
8588
}
8689
}
8790

Sources/AKLanguageManager/Extensions/Double+Localized.swift renamed to Sources/AKLanguageManager/Extensions/DataTypes/Double+Localized.swift

File renamed without changes.

Sources/AKLanguageManager/Extensions/Int+Localized.swift renamed to Sources/AKLanguageManager/Extensions/DataTypes/Int+Localized.swift

File renamed without changes.

Sources/AKLanguageManager/Extensions/NSNumber+Localized.swift renamed to Sources/AKLanguageManager/Extensions/DataTypes/NSNumber+Localized.swift

File renamed without changes.

Sources/AKLanguageManager/Extensions/String+Localized.swift renamed to Sources/AKLanguageManager/Extensions/DataTypes/String+Localized.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,22 @@ public extension String {
7777
/// - Returns:
7878
/// - The string with all its numbers localized in the designated language.
7979
func numbersLocalized(in language: Language, style numberStyle: NumberFormatter.Style = .decimal) -> String {
80-
let allLanguagesDoubleRegex = Set<String>(Language.all.enumerated().compactMap { index, language in
81-
guard let numberRegex = language.numberRegex() else { return "" }
82-
return "\(numberRegex)|"
83-
}).joined().dropLast() // Remove the last `|`.
80+
let allLanguagesDoubleRegex = Language.all.enumerated()
81+
.compactMap { index, language in
82+
guard let numberRegex = language.numberRegex() else { return "" }
83+
return "\(numberRegex)|"
84+
}
85+
.uniqued() // Remove duplicates
86+
.joined() // Create a string
87+
.dropLast() // Remove the last `|`
8488
var localizedString = doublesPreparedForLocalization(in: language)
85-
let formatter = NumberFormatter()
86-
formatter.numberStyle = numberStyle
87-
formatter.locale = language.locale
89+
let numFormatter = NumberFormatter()
90+
numFormatter.numberStyle = numberStyle
91+
numFormatter.locale = language.locale
8892
let matches = matchesForRegex(String(allLanguagesDoubleRegex)).uniqued()
8993
matches.forEach { match in
90-
guard let nsNumberMatch = formatter.number(from: match),
91-
let localizedMatch = formatter.string(from: nsNumberMatch) else { return }
94+
guard let nsNumberMatch = numFormatter.number(from: match),
95+
let localizedMatch = numFormatter.string(from: nsNumberMatch) else { return }
9296
localizedString = localizedString.replacingOccurrences(of: match, with: localizedMatch)
9397
}
9498
return localizedString

Sources/AKLanguageManager/Extensions/Image+Localized.swift renamed to Sources/AKLanguageManager/Extensions/SwiftUI/Image+Localized.swift

File renamed without changes.

Sources/AKLanguageManager/Extensions/View+Localized.swift renamed to Sources/AKLanguageManager/Extensions/SwiftUI/View+Localized.swift

File renamed without changes.

0 commit comments

Comments
 (0)