언어 설정 화면 추가 및 언어 헤더 적용

설정에서 시스템/한국어/영어/일본어 선택을 지원한다.

선택 시 Accept-Language 헤더와 UI locale을 즉시 반영한다.

언어 변경 후 스플래시를 거쳐 메인으로 소프트 재시작한다.
This commit is contained in:
Yu Sung
2025-12-16 22:56:37 +09:00
parent b2c94a44d9
commit 0285f62ecb
22 changed files with 512 additions and 61 deletions

View File

@@ -753,6 +753,22 @@
}
}
},
"%@ 님의 시리즈 전체보기" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "View all series by %@"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "%@ さんのシリーズをすべて見る"
}
}
}
},
"%@ 연재" : {
"localizations" : {
"en" : {
@@ -4049,22 +4065,6 @@
}
}
},
"모집완료" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Recruitment closed"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "募集終了"
}
}
}
},
"모집중" : {
"localizations" : {
"en" : {
@@ -4097,7 +4097,24 @@
}
}
},
"모집완료" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Recruitment closed"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "募集終了"
}
}
}
},
"목소리로 만나는 새로운 세계" : {
"extractionState" : "stale",
"localizations" : {
"en" : {
"stringUnit" : {
@@ -5138,6 +5155,7 @@
}
},
"소다라이브" : {
"extractionState" : "stale",
"localizations" : {
"en" : {
"stringUnit" : {
@@ -5425,6 +5443,38 @@
}
}
},
"시리즈 전체보기" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "View all series"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "シリーズをすべて見る"
}
}
}
},
"시스템 기본" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "System default"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "システムのデフォルト"
}
}
}
},
"시작 시간" : {
"localizations" : {
"en" : {
@@ -5649,6 +5699,22 @@
}
}
},
"언어 설정" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Language settings"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "言語設定"
}
}
}
},
"여성향" : {
"localizations" : {
"en" : {
@@ -7425,6 +7491,22 @@
}
}
},
"적용" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Apply"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "適用"
}
}
}
},
"전체" : {
"localizations" : {
"en" : {
@@ -9600,38 +9682,6 @@
}
}
}
},
"시리즈 전체보기" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "View all series"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "シリーズをすべて見る"
}
}
}
},
"%@ 님의 시리즈 전체보기" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "View all series by %@"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "%@ さんのシリーズをすべて見る"
}
}
}
}
},
"version" : "1.1"

View File

@@ -43,7 +43,7 @@ class AppState: ObservableObject {
@Published var purchasedContentId = 0
@Published var purchasedContentOrderType = OrderType.KEEP
@Published var isChangeAdultContentVisible = false
@Published var isRestartApp = false
@Published var startTab: HomeViewModel.CurrentTab = .home
@Published var marketingUtmSource = ""
@@ -74,4 +74,13 @@ class AppState: ObservableObject {
self.appStep = .main
}
}
// ( -> ) UI
func softRestart() {
isRestartApp = true
setAppStep(step: .splash)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.setAppStep(step: .main)
}
}
}

View File

@@ -26,6 +26,8 @@ enum AppStep {
case settings
case languageSettings
case notices
case noticeDetail(notice: NoticeItem)

View File

@@ -19,9 +19,12 @@ struct SodaLiveApp: App {
@ObservedObject var viewModel = AppViewModel()
@StateObject var canPgPaymentViewModel = CanPgPaymentViewModel()
@StateObject private var languageEnvironment = LanguageContainer.environment
init() {
configureImageCache()
// ,
LanguageHeaderProvider.initialize()
}
private func configureImageCache() {
@@ -40,6 +43,10 @@ struct SodaLiveApp: App {
var body: some Scene {
WindowGroup {
ContentView(canPgPaymentViewModel: canPgPaymentViewModel)
.environment(\.locale, languageEnvironment.locale)
.task {
await LanguageContainer.service.bootstrap()
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in
CreatorCommunityMediaPlayerManager.shared.pauseContent()
//

View File

@@ -18,7 +18,7 @@ struct ContentView: View {
ZStack {
Color.black.ignoresSafeArea()
if appState.isChangeAdultContentVisible {
if appState.isRestartApp {
EmptyView()
} else {
HomeView()
@@ -49,6 +49,9 @@ struct ContentView: View {
case .settings:
SettingsView()
case .languageSettings:
LanguageSettingsView()
case .notices:
NoticeListView()

View File

@@ -0,0 +1,19 @@
//
// AcceptLanguageDebugLogger.swift
// SodaLive
//
// Created by Junie (AI) on 2025/12/16.
//
#if DEBUG
import Foundation
import Moya
/// : Accept-Language .
struct AcceptLanguageDebugLogger: PluginType {
func willSend(_ request: RequestType, target: TargetType) {
let header = request.request?.allHTTPHeaderFields?["Accept-Language"] ?? "<nil>"
DEBUG_LOG("[Network] Accept-Language: \(header)")
}
}
#endif

View File

@@ -10,7 +10,15 @@ import Foundation
extension MoyaProvider {
convenience init() {
self.init(plugins: [AuthPlugin()])
var plugins: [PluginType] = [
AuthPlugin(),
AcceptLanguagePlugin()
]
#if DEBUG
plugins.append(NetworkLoggerPlugin(configuration: .init(logOptions: [.requestHeaders])))
plugins.append(AcceptLanguageDebugLogger())
#endif
self.init(plugins: plugins)
}
}

View File

@@ -102,7 +102,7 @@ final class MyPageViewModel: ObservableObject {
} else {
UserDefaults.set(ContentType.MALE.rawValue, forKey: .contentPreference)
}
AppState.shared.isChangeAdultContentVisible = true
AppState.shared.isRestartApp = true
AppState.shared.setAppStep(step: .splash)
} else {
if let message = decoded.message {

View File

@@ -17,7 +17,7 @@ struct ContentSettingsView: View {
VStack(spacing: 0) {
DetailNavigationBar(title: "콘텐츠 보기 설정") {
if AppState.shared.isChangeAdultContentVisible {
if AppState.shared.isRestartApp {
AppState.shared.setAppStep(step: .splash)
} else {
AppState.shared.back()

View File

@@ -12,7 +12,7 @@ final class ContentSettingsViewModel: ObservableObject {
didSet {
if oldValue != isAdultContentVisible {
UserDefaults.set(isAdultContentVisible, forKey: .isAdultContentVisible)
AppState.shared.isChangeAdultContentVisible = true
AppState.shared.isRestartApp = true
if !isAdultContentVisible {
adultContentPreference = .ALL
@@ -26,7 +26,7 @@ final class ContentSettingsViewModel: ObservableObject {
didSet {
if oldValue != adultContentPreference {
UserDefaults.set(adultContentPreference.rawValue, forKey: .contentPreference)
AppState.shared.isChangeAdultContentVisible = true
AppState.shared.isRestartApp = true
}
}
}

View File

@@ -0,0 +1,26 @@
//
// LanguageOption.swift
// SodaLive
//
// Created by Junie (AI) on 2025/12/16.
//
import Foundation
enum LanguageOption: String, CaseIterable, Equatable {
case system
case ko
case en
case ja
var displayName: String {
switch self {
case .system: return String(localized: "시스템 기본")
case .ko: return "한국어"
case .en: return "English"
case .ja: return "日本語"
}
}
var headerCode: String? { self == .system ? nil : self.rawValue }
}

View File

@@ -0,0 +1,33 @@
//
// LanguageRepository.swift
// SodaLive
//
// Created by Junie (AI) on 2025/12/16.
//
import Foundation
protocol LanguageRepository {
func load() async throws -> LanguageOption?
func save(_ option: LanguageOption) async throws
}
final class UserDefaultsLanguageRepository: LanguageRepository {
private let key = "app.language"
func load() async throws -> LanguageOption? {
try Task.checkCancellation()
return await withCheckedContinuation { cont in
let value = UserDefaults.standard.string(forKey: key)
cont.resume(returning: value.flatMap { LanguageOption(rawValue: $0) })
}
}
func save(_ option: LanguageOption) async throws {
try Task.checkCancellation()
return await withCheckedContinuation { cont in
UserDefaults.standard.set(option.rawValue, forKey: key)
cont.resume()
}
}
}

View File

@@ -0,0 +1,18 @@
//
// AcceptLanguagePlugin.swift
// SodaLive
//
// Created by Junie (AI) on 2025/12/16.
//
import Foundation
import Moya
struct AcceptLanguagePlugin: PluginType {
func prepare(_ request: URLRequest, target: TargetType) -> URLRequest {
var req = request
let code = LanguageHeaderProvider.current
req.setValue(code, forHTTPHeaderField: "Accept-Language")
return req
}
}

View File

@@ -0,0 +1,12 @@
//
// LanguageEnvironment.swift
// SodaLive
//
// Created by Junie (AI) on 2025/12/16.
//
import Foundation
final class LanguageEnvironment: ObservableObject {
@Published var locale: Locale = .current
}

View File

@@ -0,0 +1,108 @@
//
// LanguageService.swift
// SodaLive
//
// Created by Junie (AI) on 2025/12/16.
//
import Foundation
enum LanguageHeaderProvider {
private static let defaultsKey = "app.language"
// (ko|en|ja). initialize() .
static var current: String = {
// OS
return mapPreferredToSupported(Locale.preferredLanguages.first)
}()
/// : , OS .
static func initialize() {
if let raw = UserDefaults.standard.string(forKey: defaultsKey),
let option = LanguageOption(rawValue: raw),
option != .system {
//
current = option.rawValue
return
}
// OS
current = mapPreferredToSupported(Locale.preferredLanguages.first)
}
private static func mapPreferredToSupported(_ tag: String?) -> String {
guard let tag = tag else { return "en" }
if tag.hasPrefix("ko") { return "ko" }
if tag.hasPrefix("ja") { return "ja" }
return "en"
}
}
actor LanguageService {
private let repository: LanguageRepository
private let environment: LanguageEnvironment
init(repository: LanguageRepository, environment: LanguageEnvironment) {
self.repository = repository
self.environment = environment
}
func bootstrap() async {
let saved = (try? await repository.load()) ?? .system
await applyLanguage(saved)
}
func applyLanguage(_ option: LanguageOption) async {
do { try await repository.save(option) } catch { DEBUG_LOG("[Language] save failed: \(error)") }
let locale = resolveLocale(option)
let header = resolveHeader(option, locale: locale)
LanguageHeaderProvider.current = header
await MainActor.run { [weak environment] in
environment?.locale = locale
}
DEBUG_LOG("[Language] changed to option=\(option.rawValue) locale=\(locale.identifier) header=\(header)")
}
func currentLocale() async -> Locale {
await MainActor.run { environment.locale }
}
func currentLanguageCodeForHeader() async -> String { LanguageHeaderProvider.current }
// MARK: - Private
private func resolveLocale(_ option: LanguageOption) -> Locale {
switch option {
case .system:
guard let first = Locale.preferredLanguages.first else { return Locale(identifier: "en_US") }
return mapToSupported(first)
case .ko: return Locale(identifier: "ko_KR")
case .en: return Locale(identifier: "en_US")
case .ja: return Locale(identifier: "ja_JP")
}
}
private func resolveHeader(_ option: LanguageOption, locale: Locale) -> String {
switch option {
case .system:
let id = locale.identifier
if id.hasPrefix("ko") { return "ko" }
if id.hasPrefix("ja") { return "ja" }
return "en"
case .ko: return "ko"
case .en: return "en"
case .ja: return "ja"
}
}
private func mapToSupported(_ tag: String) -> Locale {
if tag.hasPrefix("ko") { return .init(identifier: "ko_KR") }
if tag.hasPrefix("ja") { return .init(identifier: "ja_JP") }
return .init(identifier: "en_US")
}
}
// Composition root for language feature
enum LanguageContainer {
static let environment = LanguageEnvironment()
static let repository: LanguageRepository = UserDefaultsLanguageRepository()
static let service = LanguageService(repository: repository, environment: environment)
}

View File

@@ -0,0 +1,58 @@
//
// LanguageSettingsViewModel.swift
// SodaLive
//
// Created by Junie (AI) on 2025/12/16.
//
import Foundation
final class LanguageSettingsViewModel: ObservableObject {
// ( )
@Published var selected: LanguageOption = .system
// ( )
@Published var pending: LanguageOption = .system
private let service: LanguageService
init(service: LanguageService = LanguageContainer.service) {
self.service = service
}
func onAppear() {
Task { await loadCurrent() }
}
private func loadCurrent() async {
let locale = await service.currentLocale()
let option = map(locale: locale)
await MainActor.run {
self.selected = option
self.pending = option
}
}
func select(_ option: LanguageOption) {
// / , ''
self.pending = option
}
/// /,
func applyAndRestart() async {
let toApply = pending
await service.applyLanguage(toApply)
await MainActor.run {
self.selected = toApply
// ( -> )
AppState.shared.softRestart()
}
}
private func map(locale: Locale) -> LanguageOption {
let id = locale.identifier
if id.hasPrefix("ko") { return .ko }
if id.hasPrefix("ja") { return .ja }
if id.hasPrefix("en") { return .en }
return .system
}
}

View File

@@ -0,0 +1,76 @@
//
// LanguageSettingsView.swift
// SodaLive
//
// Created by Junie (AI) on 2025/12/16.
//
import SwiftUI
struct LanguageSettingsView: View {
@StateObject private var viewModel = LanguageSettingsViewModel()
var body: some View {
let cardWidth = screenSize().width - 26.7
ZStack {
Color.black.ignoresSafeArea()
VStack(spacing: 0) {
DetailNavigationBar(title: String(localized: "언어 설정"))
ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 0) {
// List ScrollView
// (SF Symbols) UI .
VStack(spacing: 0) {
ForEach(Array(LanguageOption.allCases.enumerated()), id: \.offset) { idx, option in
HStack(spacing: 0) {
Text(option.displayName)
.font(.custom(Font.preRegular.rawValue, size: 16))
.foregroundColor(Color.grayee)
Spacer()
if viewModel.pending == option {
Image(systemName: "checkmark")
.font(.system(size: 16, weight: .semibold))
.foregroundColor(Color.white)
}
}
.padding(.horizontal, 16.7)
.frame(height: 50)
.contentShape(Rectangle())
.onTapGesture { viewModel.select(option) }
if idx < LanguageOption.allCases.count - 1 {
Rectangle()
.frame(height: 0.3)
.foregroundColor(Color.gray90)
.padding(.leading, 16.7)
}
}
}
.frame(width: cardWidth)
.background(Color.gray22)
.cornerRadius(6.7)
.padding(.top, 26.7)
//
Button(action: {
Task { await viewModel.applyAndRestart() }
}) {
Text(String(localized: "적용"))
.font(.custom(Font.preBold.rawValue, size: 16))
.frame(width: cardWidth, height: 50)
.background(Color.button)
.cornerRadius(6.7)
.foregroundColor(.white)
}
.padding(.top, 20)
.padding(.bottom, 26.7)
}
}
}
.task { viewModel.onAppear() }
}
}
}

View File

@@ -43,6 +43,28 @@ struct SettingsView: View {
AppState.shared.setAppStep(step: .notificationSettings)
}
Rectangle()
.frame(width: cardWidth - 26.7, height: 0.3)
.foregroundColor(Color.gray90)
HStack(spacing: 0) {
Text("언어 설정")
.font(.custom(Font.bold.rawValue, size: 14.7))
.foregroundColor(Color.grayee)
Spacer()
Image("ic_forward")
.resizable()
.frame(width: 20, height: 20)
}
.padding(.horizontal, 3.3)
.frame(width: cardWidth - 26.7, height: 50)
.contentShape(Rectangle())
.onTapGesture {
AppState.shared.setAppStep(step: .languageSettings)
}
if UserDefaults.bool(forKey: .auth) {
Rectangle()
.frame(width: cardWidth - 26.7, height: 0.3)
@@ -205,7 +227,7 @@ struct SettingsView: View {
UserDefaults.reset()
recentContentViewModel.truncate()
AppState.shared.isChangeAdultContentVisible = true
AppState.shared.isRestartApp = true
AppState.shared.setAppStep(step: .splash)
}
},
@@ -227,7 +249,7 @@ struct SettingsView: View {
viewModel.logoutAllDevice {
self.isShowLogoutAllDeviceDialog = false
UserDefaults.reset()
AppState.shared.isChangeAdultContentVisible = true
AppState.shared.isRestartApp = true
AppState.shared.setAppStep(step: .splash)
}
},

View File

@@ -56,7 +56,7 @@ final class SignOutViewModel: ObservableObject {
if decoded.success {
UserDefaults.reset()
AppState.shared.isChangeAdultContentVisible = true
AppState.shared.isRestartApp = true
AppState.shared.setAppStep(step: .splash)
} else {
if let message = decoded.message {

View File

@@ -64,7 +64,7 @@ struct SplashView: View {
}
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
AppState.shared.isChangeAdultContentVisible = false
AppState.shared.isRestartApp = false
}
fetchLastestVersion()
}

View File

@@ -57,7 +57,7 @@ final class LoginViewModel: ObservableObject {
UserDefaults.set(data.email, forKey: .email)
UserDefaults.set(data.token, forKey: .token)
self.appViewModel.fetchAndUpdateIdfa()
AppState.shared.isChangeAdultContentVisible = true
AppState.shared.isRestartApp = true
AppState.shared.setAppStep(step: .splash)
} else {
if let message = decoded.message {

View File

@@ -61,7 +61,7 @@ final class SignUpViewModel: ObservableObject {
UserDefaults.set(data.email, forKey: .email)
UserDefaults.set(data.token, forKey: .token)
self.appViewModel.fetchAndUpdateIdfa()
AppState.shared.isChangeAdultContentVisible = true
AppState.shared.isRestartApp = true
AppState.shared.setAppStep(step: .splash)
} else {
if let message = decoded.message {