Skip to content
This repository has been archived by the owner on Nov 17, 2024. It is now read-only.

Commit

Permalink
feat: jump to different languages of policy and faq (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill-Haku authored May 19, 2023
1 parent 1e0240f commit 7f717a1
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 11 deletions.
30 changes: 30 additions & 0 deletions Common/AppConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ enum AppConfig {
}
}

static var appLanguage: AppLanguage {
print("App Language Localization: \(Bundle.main.preferredLocalizations.first ?? "unknown")")
switch Bundle.main.preferredLocalizations.first {
case "zh-Hans":
return .zhcn
case "zh-Hant":
return .zhtw
case "en":
return .en
case "ja":
return .ja
default:
return .en
}
}

// MARK: Private

// This is private because the use of 'appConfiguration' is preferred.
Expand All @@ -62,3 +78,17 @@ enum AppConfiguration {
case testFlight
case appStore
}

// MARK: - AppLanguage

// swiftlint:disable identifier_name
enum AppLanguage {
/// Simplified Chinese
case zhcn
/// Traditional Chinese
case zhtw
/// English
case en
/// Japanese
case ja
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
askForAppToLaunch = "Yes"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
askForAppToLaunch = "Yes"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
12 changes: 11 additions & 1 deletion HSRPizzaHelper/Initialization/UserPolicyChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ private struct UserPolicyView: View {

var body: some View {
NavigationView {
WebBrowserView(url: "https://hsr.ophelper.top/static/policy.html")
var url: String {
switch AppConfig.appLanguage {
case .en:
return "https://hsr.ophelper.top/static/policy_en"
case .zhcn, .zhtw:
return "https://hsr.ophelper.top/static/policy"
case .ja:
return "https://hsr.ophelper.top/static/policy_ja"
}
}
WebBrowserView(url: url)
.ignoresSafeArea()
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Expand Down
29 changes: 21 additions & 8 deletions HSRPizzaHelper/View/SettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ struct SettingView: View {
Image(systemSymbol: .globe)
}
}
let url: String = {
switch Bundle.main.preferredLocalizations.first {
case "zh-Hans", "zh-Hant", "zh-HK":
return "https://hsr.ophelper.top/static/faq.html"
default:
return "https://hsr.ophelper.top/static/faq_en.html"

var url: String {
switch AppConfig.appLanguage {
case .en:
return "https://hsr.ophelper.top/static/faq_en"
case .zhcn, .zhtw:
return "https://hsr.ophelper.top/static/faq"
case .ja:
return "https://hsr.ophelper.top/static/faq_ja"
}
}()
}
NavigationLink(
destination: WebBrowserView(url: url)
.navigationTitle("sys.faq.title")
Expand Down Expand Up @@ -144,7 +147,17 @@ private struct OtherSettingsView: View {

Section {
NavigationLink("app.userpolicy.title") {
WebBrowserView(url: "https://hsr.ophelper.top/static/policy")
var url: String {
switch AppConfig.appLanguage {
case .en:
return "https://hsr.ophelper.top/static/policy_en"
case .zhcn, .zhtw:
return "https://hsr.ophelper.top/static/policy"
case .ja:
return "https://hsr.ophelper.top/static/policy_ja"
}
}
WebBrowserView(url: url)
.navigationTitle("app.userpolicy.title")
.navigationBarTitleDisplayMode(.inline)
}
Expand Down

0 comments on commit 7f717a1

Please sign in to comment.