mycode/myApp/HaruDanim/Shared/Formatters.swift
songyc macbook a6c040cd6a feat(i18n): 전체 UI 다국어 지원 (한국어·영어·일본어)
- 언어 설정 실적용: 변경 시 AppleLanguages 오버라이드 저장, 재시작 안내 footer
- 자동 추출되지 않던 일반 문자열(탭 이름, 픽커 라벨, 상태 뱃지, 포매터,
  삼항 문구, 심볼 카테고리 등)을 String(localized:)로 전환
- 위젯·워치 앱·컴플리케이션 타깃에 Localizable.xcstrings 신설
  (중복 리소스 방지 pbxproj 예외 추가), xcstringstool sync로 키 추출
- 4개 카탈로그 전체 키(고유 430개)에 en/ja 번역 주입
- 영어의 긴 횟수 단위("times")가 잘리지 않도록 모음 탭 셀 축소 허용
- 검증: -AppleLanguages "(en)"/"(ja)"로 모음 탭·설정 화면 확인

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013yKDMhuF39GVYy3FMcGHh7
2026-07-10 15:03:24 +09:00

63 lines
2.1 KiB
Swift

//
// Formatters.swift
// Haru_Danim
//
import Foundation
enum Format {
/// 1:23:45 23:45 ( )
static func timer(_ interval: TimeInterval) -> String {
let total = Int(interval.rounded(.down))
let h = total / 3600
let m = (total % 3600) / 60
let s = total % 60
if h > 0 { return String(format: "%d:%02d:%02d", h, m, s) }
return String(format: "%d:%02d", m, s)
}
/// "2 30" / "45" / "30"
static func durationShort(_ interval: TimeInterval) -> String {
let total = Int(interval.rounded())
let h = total / 3600
let m = (total % 3600) / 60
if h > 0 {
return m > 0
? String(localized: "\(h)시간 \(m)")
: String(localized: "\(h)시간")
}
if m > 0 { return String(localized: "\(m)") }
return String(localized: "\(total)")
}
static func weekdayShort(_ weekday: Int) -> String {
let names = [
String(localized: "", comment: "요일 축약(일요일)"),
String(localized: "", comment: "요일 축약(월요일)"),
String(localized: "", comment: "요일 축약(화요일)"),
String(localized: "", comment: "요일 축약(수요일)"),
String(localized: "", comment: "요일 축약(목요일)"),
String(localized: "", comment: "요일 축약(금요일)"),
String(localized: "", comment: "요일 축약(토요일)"),
]
let index = (weekday - 1) % 7
return names[max(0, index)]
}
static func shortDate(_ date: Date) -> String {
date.formatted(.dateTime.month(.defaultDigits).day())
}
static func fullDate(_ date: Date) -> String {
date.formatted(.dateTime.year().month().day().weekday(.short))
}
static func time(_ date: Date) -> String {
date.formatted(.dateTime.hour().minute())
}
static func percent(_ ratio: Double) -> String {
"\(Int((ratio * 100).rounded()))%"
}
}