refactor: Move country strings to assets

- Resolve: #494
pull/501/head
NaiJi ✨ 2024-04-17 20:23:19 +04:00
parent 6dc4109e0d
commit 9fa3e49025
7 changed files with 41 additions and 24 deletions

View File

@ -606,5 +606,16 @@
"reset_onboarding": "Reset onboarding switch",
"reset_onboarding_description": "Reset onboarding switch to show onboarding screen again",
"cubit_statuses": "Cubit loading statuses"
},
"countries": {
"germany": "Germany",
"netherlands": "Netherlands",
"singapore": "Singapore",
"united_kingdom": "United Kingdom",
"canada": "Canada",
"india": "India",
"australia": "Australia",
"united_states": "United States",
"finland": "Finland"
}
}
}

View File

@ -77,43 +77,46 @@ class DigitalOceanLocation {
return emoji;
}
String get countryDisplayName {
String displayName = slug;
String get countryDisplayKey {
String displayKey = 'countries.';
switch (slug.substring(0, 3)) {
case 'fra':
displayName = 'Germany';
displayKey += 'germany';
break;
case 'ams':
displayName = 'Netherlands';
displayKey += 'netherlands';
break;
case 'sgp':
displayName = 'Singapore';
displayKey += 'singapore';
break;
case 'lon':
displayName = 'United Kingdom';
displayKey += 'united_kingdom';
break;
case 'tor':
displayName = 'Canada';
displayKey += 'canada';
break;
case 'blr':
displayName = 'India';
displayKey += 'india';
break;
case 'syd':
displayName = 'Australia';
displayKey += 'australia';
break;
case 'nyc':
case 'sfo':
displayName = 'United States';
displayKey += 'united_states';
break;
default:
displayKey = slug;
}
return displayName;
return displayKey;
}
}

View File

@ -156,22 +156,25 @@ class HetznerLocation {
return emoji;
}
String get countryDisplayName {
String displayName = country;
String get countryDisplayKey {
String displayKey = 'countries.';
switch (country.substring(0, 2)) {
case 'DE':
displayName = 'Germany';
displayKey += 'germany';
break;
case 'FI':
displayName = 'Finland';
displayKey += 'finland';
break;
case 'US':
displayName = 'United States';
displayKey += 'united_states';
break;
default:
displayKey = country;
}
return displayName;
return displayKey;
}
}

View File

@ -2,14 +2,14 @@ class ServerProviderLocation {
ServerProviderLocation({
required this.title,
required this.identifier,
required this.country,
required this.countryDisplayKey,
this.description,
this.flag = '',
});
final String title;
final String identifier;
final String country;
final String countryDisplayKey;
final String? description;
final String flag;
}

View File

@ -438,7 +438,7 @@ class DigitalOceanServerProvider extends ServerProvider {
description: rawLocation.name,
flag: rawLocation.flag,
identifier: rawLocation.slug,
country: rawLocation.countryDisplayName,
countryDisplayKey: rawLocation.countryDisplayKey,
);
} catch (e) {
continue;

View File

@ -156,7 +156,7 @@ class HetznerServerProvider extends ServerProvider {
description: server.location.description,
flag: server.location.flag,
identifier: server.location.name,
country: server.location.countryDisplayName,
countryDisplayKey: server.location.countryDisplayKey,
),
),
);
@ -457,7 +457,7 @@ class HetznerServerProvider extends ServerProvider {
description: rawLocation.description,
flag: rawLocation.flag,
identifier: rawLocation.name,
country: rawLocation.countryDisplayName,
countryDisplayKey: rawLocation.countryDisplayKey,
);
} catch (e) {
continue;

View File

@ -121,7 +121,7 @@ class SelectLocationPage extends StatelessWidget {
),
const SizedBox(height: 8),
Text(
location.country,
location.countryDisplayKey.tr(),
style: Theme.of(context)
.textTheme
.bodyMedium,