Skip to content

Commit b5b42de

Browse files
committed
-Languages and Theme Enhancement
1 parent f667610 commit b5b42de

File tree

20 files changed

+209
-144
lines changed

20 files changed

+209
-144
lines changed

Notes/NotesApp.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,25 @@ import SwiftUI
99

1010
@main
1111
struct NotesApp: App {
12-
@AppStorage("selectedCountry") private var storedCountry: String = "en"
12+
13+
@StateObject var appManager: AppManager = AppManager()
14+
15+
16+
1317
var body: some Scene {
1418
WindowGroup {
1519
ContentView()
1620
.modelContainer(for: [NotesItem.self,TodoItem.self])
17-
.environment(\.locale, Locale(identifier: storedCountry))
21+
.environment(\.locale, Locale(identifier: appManager.appLanguage))
22+
.environmentObject(appManager)
23+
.preferredColorScheme(appManager.isDark ? .dark : .light)
24+
.environment(\.locale, .init(identifier: appManager.appLanguage))
25+
.environment(\.layoutDirection, isRTL(langauge: appManager.appLanguage) ? .rightToLeft : .leftToRight)
1826
}
1927
}
28+
29+
func isRTL(langauge: String) -> Bool {
30+
let rtlLanguage = ["ar", "he", "fa", "ur"]
31+
return rtlLanguage.contains(langauge)
32+
}
2033
}

Notes/HomeScreen.swift renamed to Notes/presentation/screens/HomeScreen.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct HomeScreen: View{
4646
NavigationView {
4747
VStack{
4848
if searchResults.isEmpty {
49-
ContentUnavailableView.init("No Notes Found", systemImage: "text.page.badge.magnifyingglass", description: Text("No Notes Found in the Database. Please try to research other items."))
49+
ContentUnavailableView.init(LocalizedStringKey("No Notes Found"), systemImage: "text.page.badge.magnifyingglass", description: Text(LocalizedStringKey("No Notes Found in the Database. Please try to research other items.")))
5050

5151
}else{
5252
List{
@@ -61,7 +61,7 @@ struct HomeScreen: View{
6161
Button {
6262
togglePin(for: item)
6363
} label: {
64-
Label(item.isPinned ? "Unpin" : "Pin", systemImage: item.isPinned ? "pin.slash.fill" : "pin.fill")
64+
Label(item.isPinned ? LocalizedStringKey("Unpin") : LocalizedStringKey("Pin"), systemImage: item.isPinned ? "pin.slash.fill" : "pin.fill")
6565
}
6666
.tint(.yellow)
6767
}
@@ -78,7 +78,7 @@ struct HomeScreen: View{
7878
Button {
7979
togglePin(for: item)
8080
} label: {
81-
Label(item.isPinned ? "Unpin" : "Pin", systemImage: item.isPinned ? "pin.slash.fill" : "pin.fill")
81+
Label(item.isPinned ? LocalizedStringKey("Unpin") : LocalizedStringKey("Pin"), systemImage: item.isPinned ? "pin.slash.fill" : "pin.fill")
8282
}
8383
.tint(.yellow)
8484
}
@@ -95,7 +95,7 @@ struct HomeScreen: View{
9595
}
9696
}
9797
.preferredColorScheme(isDark ? .dark : .light)
98-
.navigationTitle("Notes")
98+
.navigationTitle(LocalizedStringKey("Notes"))
9999
.searchable(text: $searchText, isPresented: $isSearchPresented)
100100
.toolbar {
101101
ToolbarItem(placement:.topBarTrailing) {

Notes/NotesDetail.swift renamed to Notes/presentation/screens/NotesDetail.swift

File renamed without changes.

Notes/UpdateNotes.swift renamed to Notes/presentation/screens/UpdateNotes.swift

File renamed without changes.

Notes/setting/Countries.swift renamed to Notes/presentation/screens/setting/Countries.swift

File renamed without changes.

Notes/setting/FontSizeKey.swift renamed to Notes/presentation/screens/setting/FontSizeKey.swift

File renamed without changes.

Notes/setting/SettingScreen.swift renamed to Notes/presentation/screens/setting/SettingScreen.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ struct SettingScreen: View {
1616
@Environment(\.requestReview) private var requestReview
1717
@Environment(\.colorScheme) private var colorScheme
1818

19-
@AppStorage("isDarkMode") private var isDark : Bool = false
2019
@State private var themeText: String = "Light Mode"
2120

21+
@EnvironmentObject private var appManager: AppManager
22+
2223
var body: some View {
2324
NavigationView {
2425
Form {
@@ -30,17 +31,17 @@ struct SettingScreen: View {
3031
}
3132

3233
Section("Color Scheme") {
33-
Toggle(isOn: $isDark) {
34+
Toggle(isOn: $appManager.isDark) {
3435
Text(themeText)
3536
}.toggleStyle(.switch)
36-
.onChange(of: isDark) { oldValue, newValue in
37+
.onChange(of: appManager.isDark) { oldValue, newValue in
3738
print("Color Scheme Changed \(newValue)")
3839
if newValue {
3940
themeText = "Dark Mode"
4041
}else {
4142
themeText = "Light Mode"
4243
}
43-
isDark = newValue
44+
appManager.isDark = newValue
4445
}
4546
}
4647

@@ -57,14 +58,13 @@ struct SettingScreen: View {
5758
Label("Privacy Policy", systemImage: "shield.fill")
5859
}
5960
}
60-
61+
6162
}.onAppear {
62-
themeText = isDark ? "Dark Mode" : "Light Mode"
63+
themeText = appManager.isDark ? "Dark Mode" : "Light Mode"
6364
}
6465
}
65-
.preferredColorScheme(isDark ? .dark : .light)
66+
.preferredColorScheme(appManager.isDark ? .dark : .light)
6667
.navigationTitle("Setting")
67-
6868
}
6969
}
7070
}

0 commit comments

Comments
 (0)