Skip to content

Commit 4bec9ef

Browse files
committed
use toLanguageTag
1 parent 107facd commit 4bec9ef

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

library/src/main/java/de/westnordost/osmfeatures/IDLocalizedFeatureCollection.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,14 @@ private List<LocalizedFeature> loadLocalizedFeaturesList(Locale locale)
112112

113113
private static String getLocalizationFilename(Locale locale)
114114
{
115-
/* not simply locale.toLanguageTag() because Locale may contain other stuff (variants etc)
116-
that are not supported */
117-
String lang = locale.getLanguage();
118-
String country = locale.getCountry();
119-
String script = locale.getScript();
120-
121-
StringBuilder builder = new StringBuilder(lang);
122-
if (!script.isEmpty()) builder.append("-").append(script);
123-
if (!country.isEmpty()) builder.append("-").append(country);
124-
builder.append(".json");
125-
return builder.toString();
115+
/* we only want language+country+script of the locale, not anything else. So we construct
116+
it anew here */
117+
return new Locale.Builder()
118+
.setLanguage(locale.getLanguage())
119+
.setRegion(locale.getCountry())
120+
.setScript(locale.getScript())
121+
.build()
122+
.toLanguageTag() + ".json";
126123
}
127124

128125
private static List<Locale> getLocaleComponents(Locale locale)

0 commit comments

Comments
 (0)