Skip to content
Snippets Groups Projects
Commit 3dce2d22 authored by akwizgran's avatar akwizgran
Browse files

Merge branch '9-locale-name' into 'master'

Add getCountryDisplayName() method to LocationUtils

Closes #9

See merge request !6
parents 487af945 4ac50d01
No related branches found
No related tags found
1 merge request!6Add getCountryDisplayName() method to LocationUtils
Pipeline #14563 passed
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment