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

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

선택 시 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

@@ -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
}
}