From 6dc4109e0d536bbbae0c39aaf9cb91127d7800a7 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Wed, 17 Apr 2024 00:00:20 +0400 Subject: [PATCH 1/2] feat: Add country names to installation process - Resolve: https://git.selfprivacy.org/SelfPrivacy/selfprivacy.org.app/issues/494 --- .../json/digital_ocean_server_info.dart | 44 ++++++++++++++++++- .../models/json/hetzner_server_info.dart | 18 ++++++++ .../models/server_provider_location.dart | 2 + .../server_providers/digital_ocean.dart | 1 + .../providers/server_providers/hetzner.dart | 2 + .../initializing/server_type_picker.dart | 8 ++++ 6 files changed, 74 insertions(+), 1 deletion(-) diff --git a/lib/logic/models/json/digital_ocean_server_info.dart b/lib/logic/models/json/digital_ocean_server_info.dart index 811536e4..1cba29d1 100644 --- a/lib/logic/models/json/digital_ocean_server_info.dart +++ b/lib/logic/models/json/digital_ocean_server_info.dart @@ -65,14 +65,56 @@ class DigitalOceanLocation { emoji = '🇮🇳'; break; + case 'syd': + emoji = '🇦🇺'; + break; + case 'nyc': case 'sfo': emoji = '🇺🇸'; break; } - return emoji; } + + String get countryDisplayName { + String displayName = slug; + switch (slug.substring(0, 3)) { + case 'fra': + displayName = 'Germany'; + break; + + case 'ams': + displayName = 'Netherlands'; + break; + + case 'sgp': + displayName = 'Singapore'; + break; + + case 'lon': + displayName = 'United Kingdom'; + break; + + case 'tor': + displayName = 'Canada'; + break; + + case 'blr': + displayName = 'India'; + break; + + case 'syd': + displayName = 'Australia'; + break; + + case 'nyc': + case 'sfo': + displayName = 'United States'; + break; + } + return displayName; + } } @JsonSerializable() diff --git a/lib/logic/models/json/hetzner_server_info.dart b/lib/logic/models/json/hetzner_server_info.dart index 122d0288..7bdb1161 100644 --- a/lib/logic/models/json/hetzner_server_info.dart +++ b/lib/logic/models/json/hetzner_server_info.dart @@ -155,6 +155,24 @@ class HetznerLocation { } return emoji; } + + String get countryDisplayName { + String displayName = country; + switch (country.substring(0, 2)) { + case 'DE': + displayName = 'Germany'; + break; + + case 'FI': + displayName = 'Finland'; + break; + + case 'US': + displayName = 'United States'; + break; + } + return displayName; + } } /// A Volume is a highly-available, scalable, and SSD-based block storage for Servers. diff --git a/lib/logic/models/server_provider_location.dart b/lib/logic/models/server_provider_location.dart index 688eb972..498567d4 100644 --- a/lib/logic/models/server_provider_location.dart +++ b/lib/logic/models/server_provider_location.dart @@ -2,12 +2,14 @@ class ServerProviderLocation { ServerProviderLocation({ required this.title, required this.identifier, + required this.country, this.description, this.flag = '', }); final String title; final String identifier; + final String country; final String? description; final String flag; } diff --git a/lib/logic/providers/server_providers/digital_ocean.dart b/lib/logic/providers/server_providers/digital_ocean.dart index c69dfa8c..b83587d1 100644 --- a/lib/logic/providers/server_providers/digital_ocean.dart +++ b/lib/logic/providers/server_providers/digital_ocean.dart @@ -438,6 +438,7 @@ class DigitalOceanServerProvider extends ServerProvider { description: rawLocation.name, flag: rawLocation.flag, identifier: rawLocation.slug, + country: rawLocation.countryDisplayName, ); } catch (e) { continue; diff --git a/lib/logic/providers/server_providers/hetzner.dart b/lib/logic/providers/server_providers/hetzner.dart index d6e4f1ba..1a199328 100644 --- a/lib/logic/providers/server_providers/hetzner.dart +++ b/lib/logic/providers/server_providers/hetzner.dart @@ -156,6 +156,7 @@ class HetznerServerProvider extends ServerProvider { description: server.location.description, flag: server.location.flag, identifier: server.location.name, + country: server.location.countryDisplayName, ), ), ); @@ -456,6 +457,7 @@ class HetznerServerProvider extends ServerProvider { description: rawLocation.description, flag: rawLocation.flag, identifier: rawLocation.name, + country: rawLocation.countryDisplayName, ); } catch (e) { continue; diff --git a/lib/ui/pages/setup/initializing/server_type_picker.dart b/lib/ui/pages/setup/initializing/server_type_picker.dart index 6fb09f4b..2db0cdf5 100644 --- a/lib/ui/pages/setup/initializing/server_type_picker.dart +++ b/lib/ui/pages/setup/initializing/server_type_picker.dart @@ -120,6 +120,14 @@ class SelectLocationPage extends StatelessWidget { .titleMedium, ), const SizedBox(height: 8), + Text( + location.country, + style: Theme.of(context) + .textTheme + .bodyMedium, + ), + if (location.description != null) + const SizedBox(height: 4), if (location.description != null) Text( location.description!, -- 2.42.0 From 9fa3e4902561d41f7083af0241a9efbf13e6301e Mon Sep 17 00:00:00 2001 From: NaiJi Date: Wed, 17 Apr 2024 20:23:19 +0400 Subject: [PATCH 2/2] refactor: Move country strings to assets - Resolve: https://git.selfprivacy.org/SelfPrivacy/selfprivacy.org.app/issues/494 --- assets/translations/en.json | 13 +++++++++- .../json/digital_ocean_server_info.dart | 25 +++++++++++-------- .../models/json/hetzner_server_info.dart | 15 ++++++----- .../models/server_provider_location.dart | 4 +-- .../server_providers/digital_ocean.dart | 2 +- .../providers/server_providers/hetzner.dart | 4 +-- .../initializing/server_type_picker.dart | 2 +- 7 files changed, 41 insertions(+), 24 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index b862cba6..f5194cdd 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -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" } -} +} \ No newline at end of file diff --git a/lib/logic/models/json/digital_ocean_server_info.dart b/lib/logic/models/json/digital_ocean_server_info.dart index 1cba29d1..dbe41f66 100644 --- a/lib/logic/models/json/digital_ocean_server_info.dart +++ b/lib/logic/models/json/digital_ocean_server_info.dart @@ -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; } } diff --git a/lib/logic/models/json/hetzner_server_info.dart b/lib/logic/models/json/hetzner_server_info.dart index 7bdb1161..a0559de6 100644 --- a/lib/logic/models/json/hetzner_server_info.dart +++ b/lib/logic/models/json/hetzner_server_info.dart @@ -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; } } diff --git a/lib/logic/models/server_provider_location.dart b/lib/logic/models/server_provider_location.dart index 498567d4..09188651 100644 --- a/lib/logic/models/server_provider_location.dart +++ b/lib/logic/models/server_provider_location.dart @@ -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; } diff --git a/lib/logic/providers/server_providers/digital_ocean.dart b/lib/logic/providers/server_providers/digital_ocean.dart index b83587d1..bd61c4e1 100644 --- a/lib/logic/providers/server_providers/digital_ocean.dart +++ b/lib/logic/providers/server_providers/digital_ocean.dart @@ -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; diff --git a/lib/logic/providers/server_providers/hetzner.dart b/lib/logic/providers/server_providers/hetzner.dart index 1a199328..36d0ed6d 100644 --- a/lib/logic/providers/server_providers/hetzner.dart +++ b/lib/logic/providers/server_providers/hetzner.dart @@ -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; diff --git a/lib/ui/pages/setup/initializing/server_type_picker.dart b/lib/ui/pages/setup/initializing/server_type_picker.dart index 2db0cdf5..bdcabe92 100644 --- a/lib/ui/pages/setup/initializing/server_type_picker.dart +++ b/lib/ui/pages/setup/initializing/server_type_picker.dart @@ -121,7 +121,7 @@ class SelectLocationPage extends StatelessWidget { ), const SizedBox(height: 8), Text( - location.country, + location.countryDisplayKey.tr(), style: Theme.of(context) .textTheme .bodyMedium, -- 2.42.0