Skip to content

Commit bb9e9dd

Browse files
committed
Added localization for iOS [#131]
1 parent 3adc878 commit bb9e9dd

8 files changed

Lines changed: 245 additions & 123 deletions

File tree

iosVariant/Variant.xcodeproj/project.pbxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@
256256
knownRegions = (
257257
en,
258258
Base,
259+
es,
260+
fr,
261+
"pt-BR",
259262
);
260263
mainGroup = 7555FF72242A565900829871;
261264
packageReferences = (

iosVariant/iosVariant/HomeView.swift

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,96 @@ struct HomeView: View {
5959
}
6060
},
6161
onDeleteComics: {
62-
Log().info(tag: TAG, message: "Deleting \(variantViewModel.selectionList.count) comic book(s)")
62+
Log().info(
63+
tag: TAG,
64+
message:
65+
"Deleting \(variantViewModel.selectionList.count) comic book(s)"
66+
)
6367
Task {
6468
try await variantViewModel.deleteSelections()
6569
}
6670
}
6771
)
6872
.tag(AppDestination.comics)
69-
.tabItem { Label("Comics", systemImage: "book.fill") }
73+
.tabItem {
74+
Label(
75+
String(
76+
localized: "destination.comics.label",
77+
defaultValue: "Comics"
78+
),
79+
systemImage: "book.fill"
80+
)
81+
}
7082

71-
ServerView()
72-
.tag(AppDestination.browseServer)
73-
.tabItem {
74-
Label("Browse", systemImage: "person.crop.circle.fill")
83+
ServerView(
84+
comicBookList: self.variantViewModel.comicBookList,
85+
currentPath: self.variantViewModel.browsingState.currentPath,
86+
title: self.variantViewModel.browsingState.title,
87+
parentPath: self.variantViewModel.browsingState.parentPath,
88+
directoryContents: self.variantViewModel.browsingState.contents,
89+
downloadingState: self.variantViewModel.browsingState
90+
.downloadingState,
91+
loading: self.variantViewModel.loading,
92+
onLoadDirectory: { path, reload in
93+
Log().debug(
94+
tag: TAG,
95+
message: "Loading path: \(path) reload=\(reload)"
96+
)
97+
self.variantViewModel.loadDirectory(
98+
path: path,
99+
reload: reload
100+
)
101+
},
102+
onDownloadFile: { path, filename in
103+
Task {
104+
Log().debug(
105+
tag: TAG,
106+
message: "Downloading file: \(filename)"
107+
)
108+
109+
self.variantViewModel.downloadFile(
110+
path: path,
111+
filename: filename
112+
)
113+
}
75114
}
115+
)
116+
.tag(AppDestination.browseServer)
117+
.tabItem {
118+
Label(
119+
String(
120+
localized: "destination.browse-server.label",
121+
defaultValue: "Browse"
122+
),
123+
systemImage: "person.crop.circle.fill"
124+
)
125+
}
76126

77-
SettingsView()
78-
.tag(AppDestination.settings)
79-
.tabItem { Label("Settings", systemImage: "gearshape.fill") }
127+
SettingsView(
128+
address: variantViewModel.address,
129+
username: variantViewModel.username,
130+
password: variantViewModel.password,
131+
onSaveChanges: { address, username, password in
132+
Log().debug(
133+
tag: TAG,
134+
message:
135+
"Saving server settings: \(address), \(username), \(password)"
136+
)
137+
variantViewModel.address = address
138+
variantViewModel.username = username
139+
variantViewModel.password = password
140+
}
141+
)
142+
.tag(AppDestination.settings)
143+
.tabItem {
144+
Label(
145+
String(
146+
localized: "destination.settings.label",
147+
defaultValue: "Settings"
148+
),
149+
systemImage: "gearshape.fill"
150+
)
151+
}
80152
}
81153
.edgesIgnoringSafeArea(.bottom)
82154
.onChange(of: currentDestination) { tab in

iosVariant/iosVariant/Views/Comics/ComicBookListView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ struct ComicBookListView: View {
4646
}
4747
.padding(.horizontal)
4848
}
49-
.navigationTitle("Comic List")
49+
.navigationTitle(
50+
String(
51+
localized: "comic-book-list.title",
52+
defaultValue: "Comic List"
53+
)
54+
)
5055
}
5156
}
5257
}

iosVariant/iosVariant/Views/Servers/BrowseServerView.swift

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import shared
2323
private let TAG = "BrowseServerView"
2424

2525
struct BrowseServerView: View {
26-
@EnvironmentViewModel var variantViewModel: VariantViewModel
27-
26+
let comicBookList: [ComicBook]
2827
let path: String
2928
let title: String
3029
let parentPath: String
@@ -44,8 +43,8 @@ struct BrowseServerView: View {
4443
}
4544

4645
var body: some View {
47-
ZStack {
48-
NavigationStack {
46+
NavigationStack {
47+
ZStack {
4948
List(directoryContents, id: \.id, selection: $selected) {
5049
entry in
5150
if entry.isDirectory {
@@ -62,56 +61,75 @@ struct BrowseServerView: View {
6261
} else {
6362
FileItemView(
6463
entry: entry,
65-
comicBookFiles: variantViewModel.comicBookList.map {
64+
comicBookFiles: comicBookList.map {
6665
$0.filename
6766
},
6867
downloadingState: downloadingState,
6968
onDownloadFile: onDownloadFile
7069
)
7170
}
7271
}
73-
.refreshable {
74-
if !loading {
75-
Log().info(
76-
tag: TAG,
77-
message:
78-
"Reloading path: \(variantViewModel.browsingState.currentPath)"
79-
)
80-
onLoadDirectory(
81-
variantViewModel.browsingState.currentPath,
82-
true
83-
)
84-
}
72+
.grayscale(loading ? 1 : 0)
73+
74+
if loading {
75+
ProgressView()
8576
}
86-
.navigationTitle(displayableTitle)
87-
.toolbar {
88-
if parentPath != "" {
89-
ToolbarItem(placement: .topBarLeading) {
90-
Button("Back") {
91-
Log().info(
92-
tag: TAG,
93-
message: "Loading parent: \(parentPath)"
94-
)
95-
onLoadDirectory(parentPath, false)
96-
}
77+
}
78+
79+
.refreshable {
80+
if !loading {
81+
Log().info(
82+
tag: TAG,
83+
message:
84+
"Reloading path: \(path)"
85+
)
86+
onLoadDirectory(
87+
path,
88+
true
89+
)
90+
}
91+
}
92+
.navigationTitle(displayableTitle)
93+
.toolbar {
94+
if parentPath != "" {
95+
ToolbarItem(placement: .topBarLeading) {
96+
Button {
97+
Log().info(
98+
tag: TAG,
99+
message: "Loading parent: \(parentPath)"
100+
)
101+
onLoadDirectory(parentPath, false)
102+
} label: {
103+
Image(systemName: "arrow.backward")
97104
}
98105
}
99106
}
100107
}
101-
102-
if loading {
103-
ProgressView()
104-
}
105108
}
106109
}
107110
}
108111

109-
#Preview("normal") {
112+
#Preview("directories") {
113+
BrowseServerView(
114+
comicBookList: COMIC_BOOK_LIST,
115+
path: "/reader/v1",
116+
title: "",
117+
parentPath: "",
118+
directoryContents: DIRECTORY_LIST.filter { $0.isDirectory },
119+
downloadingState: [],
120+
loading: false,
121+
onLoadDirectory: { _, _ in },
122+
onDownloadFile: { _, _ in }
123+
)
124+
}
125+
126+
#Preview("files") {
110127
BrowseServerView(
128+
comicBookList: COMIC_BOOK_LIST,
111129
path: "/reader/v1",
112130
title: "",
113131
parentPath: "",
114-
directoryContents: DIRECTORY_LIST,
132+
directoryContents: DIRECTORY_LIST.filter { $0.isDirectory == false },
115133
downloadingState: [],
116134
loading: false,
117135
onLoadDirectory: { _, _ in },
@@ -121,10 +139,11 @@ struct BrowseServerView: View {
121139

122140
#Preview("loading") {
123141
BrowseServerView(
142+
comicBookList: COMIC_BOOK_LIST,
124143
path: "/reader/v1",
125144
title: "",
126145
parentPath: "",
127-
directoryContents: DIRECTORY_LIST,
146+
directoryContents: DIRECTORY_LIST.filter { $0.isDirectory },
128147
downloadingState: [],
129148
loading: true,
130149
onLoadDirectory: { _, _ in },

iosVariant/iosVariant/Views/Servers/FileItemView.swift

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,21 @@ struct FileItemView: View {
5353
var body: some View {
5454
HStack {
5555
if isDownloaded {
56-
Button(
57-
"",
58-
systemImage: "checkmark.circle.fill",
59-
action: {}
60-
)
56+
Button {
57+
58+
} label: {
59+
Image(systemName: "checkmark.circle.fill")
60+
}
6161
} else {
62-
Button(
63-
"",
64-
systemImage: "plus.circle.fill",
65-
action: {
66-
Log().info(
67-
tag: TAG,
68-
message: "Downloading file: \(entry.path)"
69-
)
70-
onDownloadFile(entry.path, entry.filename)
71-
}
72-
)
62+
Button {
63+
Log().info(
64+
tag: TAG,
65+
message: "Downloading file: \(entry.path)"
66+
)
67+
onDownloadFile(entry.path, entry.filename)
68+
} label: {
69+
Image(systemName: "plus.circle.fill")
70+
}
7371
}
7472

7573
VStack(alignment: .leading) {

iosVariant/iosVariant/Views/Servers/ServerView.swift

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,42 @@ import shared
2323
private let TAG = "ServerView"
2424

2525
struct ServerView: View {
26-
@EnvironmentViewModel var variantViewModel: VariantViewModel
26+
let comicBookList: [ComicBook]
27+
let currentPath: String
28+
let title: String
29+
let parentPath: String
30+
let directoryContents: [DirectoryEntry]
31+
let downloadingState: [DownloadingState]
32+
let loading: Bool
33+
34+
let onLoadDirectory: (String, Bool) -> Void
35+
let onDownloadFile: (String, String) -> Void
2736

2837
var body: some View {
2938
BrowseServerView(
30-
path: self.variantViewModel.browsingState.currentPath,
31-
title: self.variantViewModel.browsingState.title,
32-
parentPath: self.variantViewModel.browsingState.parentPath,
33-
directoryContents: self.variantViewModel.browsingState.contents,
34-
downloadingState: self.variantViewModel.browsingState
35-
.downloadingState,
36-
loading: self.variantViewModel.loading,
37-
onLoadDirectory: { path, reload in
38-
Log().debug(
39-
tag: TAG,
40-
message: "Loading path: \(path) reload=\(reload)"
41-
)
42-
self.variantViewModel.loadDirectory(
43-
path: path,
44-
reload: reload
45-
)
46-
},
47-
onDownloadFile: { path, filename in
48-
Task {
49-
Log().debug(
50-
tag: TAG,
51-
message: "Downloading file: \(filename)"
52-
)
53-
54-
self.variantViewModel.downloadFile(
55-
path: path,
56-
filename: filename
57-
)
58-
}
59-
}
39+
comicBookList: comicBookList,
40+
path: currentPath,
41+
title: title,
42+
parentPath: parentPath,
43+
directoryContents: directoryContents,
44+
downloadingState: downloadingState,
45+
loading: loading,
46+
onLoadDirectory: onLoadDirectory,
47+
onDownloadFile: onDownloadFile
6048
)
6149
}
6250
}
6351

6452
#Preview {
65-
ServerView()
53+
ServerView(
54+
comicBookList: COMIC_BOOK_LIST,
55+
currentPath: "The current path",
56+
title: "The Title",
57+
parentPath: "The parent path",
58+
directoryContents: DIRECTORY_LIST,
59+
downloadingState: [],
60+
loading: false,
61+
onLoadDirectory: { _, _ in },
62+
onDownloadFile: { _, _ in }
63+
)
6664
}

0 commit comments

Comments
 (0)