feat: 다국어 지원 및 다중 통화 환율 변환 기능 확대

- ExchangeRateService에 JPY, CNY 환율 지원 추가
- 구독 서비스별 다국어 표시 이름 지원
- 분석 화면 차트 및 UI/UX 개선
- 설정 화면 전면 리팩토링
- SMS 스캔 기능 사용성 개선
- 전체 앱 다국어 번역 확대

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
JiWoong Sul
2025-07-16 17:34:32 +09:00
parent 4d1c0f5dab
commit 0f0b02bf08
55 changed files with 4100 additions and 1197 deletions

View File

@@ -6,67 +6,166 @@ import 'exchange_rate_service.dart';
class CurrencyUtil {
static final ExchangeRateService _exchangeRateService = ExchangeRateService();
/// 구독 목록의 총 월 비용을 계산 (원화로 환산, 이벤트 가격 반영)
static Future<double> calculateTotalMonthlyExpense(
List<SubscriptionModel> subscriptions) async {
/// 언어에 따른 기본 통화 반환
static String getDefaultCurrency(String locale) {
switch (locale) {
case 'ko':
return 'KRW';
case 'ja':
return 'JPY';
case 'zh':
return 'CNY';
case 'en':
default:
return 'USD';
}
}
/// 언어에 따른 서브 통화 반환 (영어 제외 모두 USD)
static String? getSecondaryCurrency(String locale, String? selectedCurrency) {
if (locale == 'en' && selectedCurrency == 'KRW') {
return 'KRW';
}
return locale != 'en' ? 'USD' : null;
}
/// 통화 기호 반환
static String getCurrencySymbol(String currency) {
switch (currency) {
case 'KRW':
return '';
case 'USD':
return '\$';
case 'JPY':
return '¥';
case 'CNY':
return '¥';
default:
return currency;
}
}
/// 통화별 locale 반환
static String _getLocaleForCurrency(String currency) {
switch (currency) {
case 'KRW':
return 'ko_KR';
case 'USD':
return 'en_US';
case 'JPY':
return 'ja_JP';
case 'CNY':
return 'zh_CN';
default:
return 'en_US';
}
}
/// 단일 통화 포맷팅
static String _formatSingleCurrency(double amount, String currency) {
final locale = _getLocaleForCurrency(currency);
final symbol = getCurrencySymbol(currency);
final decimals = (currency == 'KRW' || currency == 'JPY') ? 0 : 2;
return NumberFormat.currency(
locale: locale,
symbol: symbol,
decimalDigits: decimals,
).format(amount);
}
/// 금액 포맷팅 (기본 통화 + 서브 통화)
static Future<String> formatAmountWithLocale(
double amount,
String currency,
String locale,
) async {
final defaultCurrency = getDefaultCurrency(locale);
// 입력 통화가 기본 통화인 경우
if (currency == defaultCurrency) {
return _formatSingleCurrency(amount, currency);
}
// USD 입력인 경우 - 기본 통화로 변환하여 표시
if (currency == 'USD' && defaultCurrency != 'USD') {
final convertedAmount = await _exchangeRateService.convertUsdToTarget(amount, defaultCurrency);
if (convertedAmount != null) {
final primaryFormatted = _formatSingleCurrency(convertedAmount, defaultCurrency);
final usdFormatted = _formatSingleCurrency(amount, 'USD');
return '$primaryFormatted ($usdFormatted)';
}
}
// 영어 사용자가 KRW 선택한 경우
if (locale == 'en' && currency == 'KRW') {
return _formatSingleCurrency(amount, currency);
}
// 기타 통화 입력인 경우
return _formatSingleCurrency(amount, currency);
}
/// 구독 목록의 총 월 비용을 계산 (언어별 기본 통화로)
static Future<double> calculateTotalMonthlyExpenseInDefaultCurrency(
List<SubscriptionModel> subscriptions,
String locale,
) async {
final defaultCurrency = getDefaultCurrency(locale);
double total = 0.0;
for (var subscription in subscriptions) {
// 이벤트 가격이 있으면 currentPrice 사용
final price = subscription.currentPrice;
if (subscription.currency == 'USD') {
// USD인 경우 KRW로 변환
final krwAmount = await _exchangeRateService
.convertUsdToKrw(price);
if (krwAmount != null) {
total += krwAmount;
}
} else {
// KRW인 경우 그대로 합산
if (subscription.currency == defaultCurrency) {
// 기본 통화면 그대로 합산
total += price;
} else if (subscription.currency == 'USD') {
// USD면 기본 통화로 변환
final converted = await _exchangeRateService.convertUsdToTarget(price, defaultCurrency);
if (converted != null) {
total += converted;
}
} else if (defaultCurrency == 'USD') {
// 기본 통화가 USD인 경우 다른 통화를 USD로 변환
final converted = await _exchangeRateService.convertTargetToUsd(price, subscription.currency);
if (converted != null) {
total += converted;
}
}
}
return total;
}
/// 구독 월 비용을 표시 형식에 맞게 변환 (원화 변환 포함, 이벤트 가격 반영)
static Future<String> formatSubscriptionAmount(
SubscriptionModel subscription) async {
// 이벤트 가격이 있으면 currentPrice 사용
final price = subscription.currentPrice;
if (subscription.currency == 'USD') {
// USD 표시 + 원화 환산 금액
final usdFormatted = NumberFormat.currency(
locale: 'en_US',
symbol: '\$',
decimalDigits: 2,
).format(price);
// 원화 환산 금액
final krwAmount = await _exchangeRateService
.getFormattedKrwAmount(price);
return '$usdFormatted $krwAmount';
} else {
// 원화 표시
return NumberFormat.currency(
locale: 'ko_KR',
symbol: '',
decimalDigits: 0,
).format(price);
}
/// 구독 목록의 총 월 비용을 계산 (원화로 환산, 이벤트 가격 반영) - 기존 호환성 유지
static Future<double> calculateTotalMonthlyExpense(
List<SubscriptionModel> subscriptions) async {
return calculateTotalMonthlyExpenseInDefaultCurrency(subscriptions, 'ko');
}
/// 총액을 원화로 표시
/// 구독의 월 비용을 표시 형식에 맞게 변환 (언어별 통화)
static Future<String> formatSubscriptionAmountWithLocale(
SubscriptionModel subscription, String locale) async {
final price = subscription.currentPrice;
return formatAmountWithLocale(price, subscription.currency, locale);
}
/// 구독의 월 비용을 표시 형식에 맞게 변환 (원화 변환 포함, 이벤트 가격 반영) - 기존 호환성 유지
static Future<String> formatSubscriptionAmount(
SubscriptionModel subscription) async {
return formatSubscriptionAmountWithLocale(subscription, 'ko');
}
/// 총액을 언어별 기본 통화로 표시
static String formatTotalAmountWithLocale(double amount, String locale) {
final defaultCurrency = getDefaultCurrency(locale);
return _formatSingleCurrency(amount, defaultCurrency);
}
/// 총액을 원화로 표시 - 기존 호환성 유지
static String formatTotalAmount(double amount) {
return NumberFormat.currency(
locale: 'ko_KR',
symbol: '',
decimalDigits: 0,
).format(amount);
return formatTotalAmountWithLocale(amount, 'ko');
}
/// 환율 정보 텍스트 가져오기
@@ -74,25 +173,34 @@ class CurrencyUtil {
return _exchangeRateService.getFormattedExchangeRateInfo();
}
/// 이벤트로 인한 총 절약액 계산 (원화로 환산)
static Future<double> calculateTotalEventSavings(
List<SubscriptionModel> subscriptions) async {
/// 언어별 환율 정보 텍스트 가져오기
static Future<String> getExchangeRateInfoForLocale(String locale) {
return _exchangeRateService.getFormattedExchangeRateInfoForLocale(locale);
}
/// 이벤트로 인한 총 절약액 계산 (언어별 기본 통화로)
static Future<double> calculateTotalEventSavingsInDefaultCurrency(
List<SubscriptionModel> subscriptions, String locale) async {
final defaultCurrency = getDefaultCurrency(locale);
double total = 0.0;
for (var subscription in subscriptions) {
if (subscription.isCurrentlyInEvent) {
final savings = subscription.eventSavings;
if (subscription.currency == 'USD') {
// USD인 경우 KRW로 변환
final krwAmount = await _exchangeRateService
.convertUsdToKrw(savings);
if (krwAmount != null) {
total += krwAmount;
}
} else {
// KRW인 경우 그대로 합산
if (subscription.currency == defaultCurrency) {
total += savings;
} else if (subscription.currency == 'USD') {
final converted = await _exchangeRateService.convertUsdToTarget(savings, defaultCurrency);
if (converted != null) {
total += converted;
}
} else if (defaultCurrency == 'USD') {
// 기본 통화가 USD인 경우 다른 통화를 USD로 변환
final converted = await _exchangeRateService.convertTargetToUsd(savings, subscription.currency);
if (converted != null) {
total += converted;
}
}
}
}
@@ -100,60 +208,37 @@ class CurrencyUtil {
return total;
}
/// 이벤트 절약액을 표시 형식에 맞게 변환
static Future<String> formatEventSavings(
SubscriptionModel subscription) async {
/// 이벤트로 인한 총 절약액 계산 (원화로 환산) - 기존 호환성 유지
static Future<double> calculateTotalEventSavings(
List<SubscriptionModel> subscriptions) async {
return calculateTotalEventSavingsInDefaultCurrency(subscriptions, 'ko');
}
/// 이벤트 절약액을 표시 형식에 맞게 변환 (언어별)
static Future<String> formatEventSavingsWithLocale(
SubscriptionModel subscription, String locale) async {
if (!subscription.isCurrentlyInEvent) {
return '';
}
final savings = subscription.eventSavings;
if (subscription.currency == 'USD') {
// USD 표시 + 원화 환산 금액
final usdFormatted = NumberFormat.currency(
locale: 'en_US',
symbol: '\$',
decimalDigits: 2,
).format(savings);
// 원화 환산 금액
final krwAmount = await _exchangeRateService
.getFormattedKrwAmount(savings);
return '$usdFormatted $krwAmount';
} else {
// 원화 표시
return NumberFormat.currency(
locale: 'ko_KR',
symbol: '',
decimalDigits: 0,
).format(savings);
}
return formatAmountWithLocale(savings, subscription.currency, locale);
}
/// 금액과 통화를 받아 포맷팅하여 반환
/// 이벤트 절약액을 표시 형식에 맞게 변환 - 기존 호환성 유지
static Future<String> formatEventSavings(
SubscriptionModel subscription) async {
return formatEventSavingsWithLocale(subscription, 'ko');
}
/// 금액과 통화를 받아 포맷팅하여 반환 (언어별)
static Future<String> formatAmountWithCurrencyAndLocale(
double amount, String currency, String locale) async {
return formatAmountWithLocale(amount, currency, locale);
}
/// 금액과 통화를 받아 포맷팅하여 반환 - 기존 호환성 유지
static Future<String> formatAmount(double amount, String currency) async {
if (currency == 'USD') {
// USD 표시 + 원화 환산 금액
final usdFormatted = NumberFormat.currency(
locale: 'en_US',
symbol: '\$',
decimalDigits: 2,
).format(amount);
// 원화 환산 금액
final krwAmount = await _exchangeRateService
.getFormattedKrwAmount(amount);
return '$usdFormatted $krwAmount';
} else {
// 원화 표시
return NumberFormat.currency(
locale: 'ko_KR',
symbol: '',
decimalDigits: 0,
).format(amount);
}
return formatAmountWithCurrencyAndLocale(amount, currency, 'ko');
}
}
}

View File

@@ -17,6 +17,8 @@ class ExchangeRateService {
// 캐싱된 환율 정보
double? _usdToKrwRate;
double? _usdToJpyRate;
double? _usdToCnyRate;
DateTime? _lastUpdated;
// API 요청 URL (ExchangeRate-API 사용)
@@ -24,18 +26,20 @@ class ExchangeRateService {
// 기본 환율 상수
static const double DEFAULT_USD_TO_KRW_RATE = 1350.0;
static const double DEFAULT_USD_TO_JPY_RATE = 150.0;
static const double DEFAULT_USD_TO_CNY_RATE = 7.2;
// 캐싱된 환율 반환 (동기적)
double? get cachedUsdToKrwRate => _usdToKrwRate;
/// 현재 USD to KRW 환율 정보를 가져옵니다.
/// 최근 6시간 이내 조회했던 정보가 있다면 캐싱된 정보를 반환합니다.
Future<double?> getUsdToKrwRate() async {
// 캐싱된 데이터 있고 6시간 이내면 캐싱된 데이터 반환
if (_usdToKrwRate != null && _lastUpdated != null) {
/// 모든 환율 정보를 한 번에 가져옵니다.
/// 최근 6시간 이내 조회했던 정보가 있다면 캐싱된 정보를 사용합니다.
Future<void> _fetchAllRatesIfNeeded() async {
// 캐싱된 데이터 있고 6시간 이내면 스킵
if (_lastUpdated != null) {
final difference = DateTime.now().difference(_lastUpdated!);
if (difference.inHours < 6) {
return _usdToKrwRate;
return;
}
}
@@ -45,19 +49,22 @@ class ExchangeRateService {
if (response.statusCode == 200) {
final data = json.decode(response.body);
_usdToKrwRate = data['rates']['KRW'].toDouble();
_usdToKrwRate = data['rates']['KRW']?.toDouble();
_usdToJpyRate = data['rates']['JPY']?.toDouble();
_usdToCnyRate = data['rates']['CNY']?.toDouble();
_lastUpdated = DateTime.now();
return _usdToKrwRate;
} else {
// 실패 시 캐싱된 값이라도 반환
return _usdToKrwRate;
}
} catch (e) {
// 오류 발생 시 캐싱된 값이라도 반환
return _usdToKrwRate;
// 오류 발생 시 기본값 사용
}
}
/// 현재 USD to KRW 환율 정보를 가져옵니다.
Future<double?> getUsdToKrwRate() async {
await _fetchAllRatesIfNeeded();
return _usdToKrwRate;
}
/// USD 금액을 KRW로 변환합니다.
Future<double?> convertUsdToKrw(double usdAmount) async {
final rate = await getUsdToKrwRate();
@@ -67,6 +74,48 @@ class ExchangeRateService {
return null;
}
/// USD 금액을 지정된 통화로 변환합니다.
Future<double?> convertUsdToTarget(double usdAmount, String targetCurrency) async {
await _fetchAllRatesIfNeeded();
switch (targetCurrency) {
case 'KRW':
final rate = _usdToKrwRate ?? DEFAULT_USD_TO_KRW_RATE;
return usdAmount * rate;
case 'JPY':
final rate = _usdToJpyRate ?? DEFAULT_USD_TO_JPY_RATE;
return usdAmount * rate;
case 'CNY':
final rate = _usdToCnyRate ?? DEFAULT_USD_TO_CNY_RATE;
return usdAmount * rate;
case 'USD':
return usdAmount;
default:
return null;
}
}
/// 지정된 통화를 USD로 변환합니다.
Future<double?> convertTargetToUsd(double amount, String sourceCurrency) async {
await _fetchAllRatesIfNeeded();
switch (sourceCurrency) {
case 'KRW':
final rate = _usdToKrwRate ?? DEFAULT_USD_TO_KRW_RATE;
return amount / rate;
case 'JPY':
final rate = _usdToJpyRate ?? DEFAULT_USD_TO_JPY_RATE;
return amount / rate;
case 'CNY':
final rate = _usdToCnyRate ?? DEFAULT_USD_TO_CNY_RATE;
return amount / rate;
case 'USD':
return amount;
default:
return null;
}
}
/// 현재 환율 정보를 포맷팅하여 텍스트로 반환합니다.
Future<String> getFormattedExchangeRateInfo() async {
final rate = await getUsdToKrwRate();
@@ -76,11 +125,42 @@ class ExchangeRateService {
symbol: '',
decimalDigits: 0,
).format(rate);
return '오늘 기준 환율 : $formattedRate';
return formattedRate;
}
return '';
}
/// 언어별 환율 정보를 포맷팅하여 반환합니다.
Future<String> getFormattedExchangeRateInfoForLocale(String locale) async {
await _fetchAllRatesIfNeeded();
switch (locale) {
case 'ko':
final rate = _usdToKrwRate ?? DEFAULT_USD_TO_KRW_RATE;
return NumberFormat.currency(
locale: 'ko_KR',
symbol: '',
decimalDigits: 0,
).format(rate);
case 'ja':
final rate = _usdToJpyRate ?? DEFAULT_USD_TO_JPY_RATE;
return NumberFormat.currency(
locale: 'ja_JP',
symbol: '¥',
decimalDigits: 0,
).format(rate);
case 'zh':
final rate = _usdToCnyRate ?? DEFAULT_USD_TO_CNY_RATE;
return NumberFormat.currency(
locale: 'zh_CN',
symbol: '¥',
decimalDigits: 2,
).format(rate);
default:
return '';
}
}
/// USD 금액을 KRW로 변환하여 포맷팅된 문자열로 반환합니다.
Future<String> getFormattedKrwAmount(double usdAmount) async {
final krwAmount = await convertUsdToKrw(usdAmount);
@@ -94,4 +174,46 @@ class ExchangeRateService {
}
return '';
}
/// USD 금액을 지정된 언어의 기본 통화로 변환하여 포맷팅된 문자열로 반환합니다.
Future<String> getFormattedAmountForLocale(double usdAmount, String locale) async {
String targetCurrency;
String localeCode;
String symbol;
int decimalDigits;
switch (locale) {
case 'ko':
targetCurrency = 'KRW';
localeCode = 'ko_KR';
symbol = '';
decimalDigits = 0;
break;
case 'ja':
targetCurrency = 'JPY';
localeCode = 'ja_JP';
symbol = '¥';
decimalDigits = 0;
break;
case 'zh':
targetCurrency = 'CNY';
localeCode = 'zh_CN';
symbol = '¥';
decimalDigits = 2;
break;
default:
return '\$$usdAmount';
}
final convertedAmount = await convertUsdToTarget(usdAmount, targetCurrency);
if (convertedAmount != null) {
final formattedAmount = NumberFormat.currency(
locale: localeCode,
symbol: symbol,
decimalDigits: decimalDigits,
).format(convertedAmount);
return '($formattedAmount)';
}
return '';
}
}

View File

@@ -76,7 +76,7 @@ class SmsScanner {
try {
final serviceName = sms['serviceName'] as String? ?? '알 수 없는 서비스';
final monthlyCost = (sms['monthlyCost'] as num?)?.toDouble() ?? 0.0;
final billingCycle = sms['billingCycle'] as String? ?? '월간';
final billingCycle = SubscriptionModel.normalizeBillingCycle(sms['billingCycle'] as String? ?? 'monthly');
final nextBillingDateStr = sms['nextBillingDate'] as String?;
// 실제 반복 횟수 사용 (테스트 데이터에서는 이미 제공됨)
final actualRepeatCount = repeatCount > 0 ? repeatCount : 1;
@@ -142,7 +142,7 @@ class SmsScanner {
}
// 결제 주기별 다음 결제일 계산
if (billingCycle == '월간') {
if (billingCycle == 'monthly') {
int month = now.month;
int year = now.year;
@@ -156,7 +156,7 @@ class SmsScanner {
}
return DateTime(year, month, billingDate.day);
} else if (billingCycle == '연간') {
} else if (billingCycle == 'yearly') {
// 올해의 결제일이 지났는지 확인
final thisYearBilling =
DateTime(now.year, billingDate.month, billingDate.day);
@@ -165,7 +165,7 @@ class SmsScanner {
} else {
return thisYearBilling;
}
} else if (billingCycle == '주간') {
} else if (billingCycle == 'weekly') {
// 가장 가까운 다음 주 같은 요일 계산
final dayDifference = billingDate.weekday - now.weekday;
final daysToAdd = dayDifference > 0 ? dayDifference : 7 + dayDifference;

View File

@@ -747,6 +747,60 @@ class SubscriptionUrlMatcher {
return _getCategoryForLegacyService(serviceName);
}
/// 현재 로케일에 따라 서비스 표시명 가져오기
static Future<String> getServiceDisplayName({
required String serviceName,
required String locale,
}) async {
await initialize();
if (_servicesData == null) {
return serviceName;
}
final lowerName = serviceName.toLowerCase().trim();
final categories = _servicesData!['categories'] as Map<String, dynamic>;
// JSON에서 서비스 찾기
for (final categoryData in categories.values) {
final services = (categoryData as Map<String, dynamic>)['services'] as Map<String, dynamic>;
for (final serviceData in services.values) {
final data = serviceData as Map<String, dynamic>;
final names = List<String>.from(data['names'] ?? []);
// names 배열에 있는지 확인
for (final name in names) {
if (lowerName == name.toLowerCase() ||
lowerName.contains(name.toLowerCase()) ||
name.toLowerCase().contains(lowerName)) {
// 로케일에 따라 적절한 이름 반환
if (locale == 'ko' || locale == 'kr') {
return data['nameKr'] ?? serviceName;
} else {
return data['nameEn'] ?? serviceName;
}
}
}
// nameKr/nameEn에 직접 매칭 확인
final nameKr = (data['nameKr'] ?? '').toString().toLowerCase();
final nameEn = (data['nameEn'] ?? '').toString().toLowerCase();
if (lowerName == nameKr || lowerName == nameEn) {
if (locale == 'ko' || locale == 'kr') {
return data['nameKr'] ?? serviceName;
} else {
return data['nameEn'] ?? serviceName;
}
}
}
}
// 찾지 못한 경우 원래 이름 반환
return serviceName;
}
/// 카테고리 키를 실제 카테고리 ID로 매핑
static String _getCategoryIdByKey(String key) {
// 여기에 실제 앱의 카테고리 ID 매핑을 추가