From 4ac50d01bb93a7fe973f763ba4ad3124d911b744 Mon Sep 17 00:00:00 2001 From: Torsten Grote <t@grobox.de> Date: Fri, 12 May 2023 10:28:10 -0300 Subject: [PATCH] Add getCountryDisplayName() method to LocationUtils --- .../onionwrapper/LocationUtils.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/onionwrapper-core/src/main/java/org/briarproject/onionwrapper/LocationUtils.java b/onionwrapper-core/src/main/java/org/briarproject/onionwrapper/LocationUtils.java index 0e27df4..637f515 100644 --- a/onionwrapper-core/src/main/java/org/briarproject/onionwrapper/LocationUtils.java +++ b/onionwrapper-core/src/main/java/org/briarproject/onionwrapper/LocationUtils.java @@ -2,6 +2,8 @@ package org.briarproject.onionwrapper; import org.briarproject.nullsafety.NotNullByDefault; +import java.util.Locale; + @NotNullByDefault public interface LocationUtils { @@ -13,4 +15,20 @@ public interface LocationUtils { * https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166-1 alpha 2</a>. */ String getCurrentCountry(); + + /** + * Returns the name of the country for display in the UI + * or the isoCode if none could be found. + * + * @param isoCode The result from {@link #getCurrentCountry()}. + */ + static String getCountryDisplayName(String isoCode) { + for (Locale locale : Locale.getAvailableLocales()) { + if (locale.getCountry().equalsIgnoreCase(isoCode)) { + return locale.getDisplayCountry(); + } + } + // Name is unknown + return isoCode; + } } -- GitLab