Skip to content
Snippets Groups Projects

Add getCountryDisplayName() method to LocationUtils

Merged Torsten Grote requested to merge 9-locale-name into master
All threads resolved!
1 file
+ 18
0
Compare changes
  • Side-by-side
  • Inline
@@ -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()}.
*/
+6
static String getCountryDisplayName(String isoCode) {
for (Locale locale : Locale.getAvailableLocales()) {
if (locale.getCountry().equalsIgnoreCase(isoCode)) {
return locale.getDisplayCountry();
}
}
// Name is unknown
return isoCode;
}
}
Loading