/// 阿里机器翻译盖不住的语种:繁体会被收成简体,乌克兰语和克罗地亚语直接被拒。 bool microsoftMtRequired(String from, String to) { bool hit(String raw) { switch (raw.trim().toLowerCase()) { case 'zh-hant': case 'zh-hant-hk': case 'zh-tw': case 'zh-hk': case 'uk': case 'uk-ua': case 'hr': case 'hr-hr': return true; default: return false; } } return hit(from) || hit(to); } /// 收成微软翻译认的码。空串留给自动检测,请求里不带 from。 String microsoftMtCode(String raw) { final code = raw.trim(); if (code.isEmpty) return ''; switch (code.toLowerCase()) { case 'zh-hant': case 'zh-hant-hk': case 'zh-tw': case 'zh-hk': return 'zh-Hant'; case 'zh': case 'zh-cn': case 'zh-hans': return 'zh-Hans'; case 'uk': case 'uk-ua': return 'uk'; case 'hr': case 'hr-hr': return 'hr'; default: final dash = code.indexOf('-'); if (dash > 0) return code.substring(0, dash).toLowerCase(); return code.toLowerCase(); } } /// 解析微软翻译 3.0 的响应。失败或空译文返回 null。 String? microsoftTranslationText(dynamic data) { if (data is! List || data.isEmpty) return null; final first = data.first; if (first is! Map) return null; final translations = first['translations']; if (translations is! List || translations.isEmpty) return null; final item = translations.first; if (item is! Map) return null; final text = item['text']; if (text is! String) return null; final out = text.trim(); return out.isEmpty ? null : out; }