From 844039e0f2f97959ddab7534a2dea11d51f1e77a Mon Sep 17 00:00:00 2001 From: Aliaksei Tratseuski Date: Wed, 1 May 2024 02:59:47 +0400 Subject: [PATCH] feat: simplified digital ocean town name to country mapper. --- .../json/digital_ocean_server_info.dart | 53 +++++-------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/lib/logic/models/json/digital_ocean_server_info.dart b/lib/logic/models/json/digital_ocean_server_info.dart index dbe41f66..5e92de29 100644 --- a/lib/logic/models/json/digital_ocean_server_info.dart +++ b/lib/logic/models/json/digital_ocean_server_info.dart @@ -77,46 +77,21 @@ class DigitalOceanLocation { return emoji; } + static const _townPrefixToCountryMap = { + 'fra': 'germany', + 'ams': 'netherlands', + 'sgp': 'singapore', + 'lon': 'united_kingdom', + 'tor': 'canada', + 'blr': 'india', + 'syd': 'australia', + 'nyc': 'united_states', + 'sfo': 'united_states', + }; + String get countryDisplayKey { - String displayKey = 'countries.'; - switch (slug.substring(0, 3)) { - case 'fra': - displayKey += 'germany'; - break; - - case 'ams': - displayKey += 'netherlands'; - break; - - case 'sgp': - displayKey += 'singapore'; - break; - - case 'lon': - displayKey += 'united_kingdom'; - break; - - case 'tor': - displayKey += 'canada'; - break; - - case 'blr': - displayKey += 'india'; - break; - - case 'syd': - displayKey += 'australia'; - break; - - case 'nyc': - case 'sfo': - displayKey += 'united_states'; - break; - - default: - displayKey = slug; - } - return displayKey; + final countryName = _townPrefixToCountryMap[slug.substring(0, 3)] ?? slug; + return 'countries.$countryName'; } }