import 'package:easy_localization/easy_localization.dart';

final _koreanPattern = RegExp(r'[가-힣]');

String tr(String key, {String? fallback, Map<String, String>? params}) {
  try {
    if (fallback != null && _koreanPattern.hasMatch(fallback)) {
      fallback = null;
    }
    final translated = key.tr(namedArgs: params);
    if (translated == key && fallback != null && fallback.isNotEmpty) {
      return fallback;
    }
    return translated;
  } catch (_) {
    return fallback ?? key;
  }
}
