Skip to content

Commit 3e8af13

Browse files
bdonwipfli
andauthored
Initial list of allowed name:* tags [#112,#270] (#284)
* Initial list of allowed name:* tags [#112,#270] We want to limit the names to only those the style will support for localization. * Tiles 4.0.0-alpha.0 [#112,#270] --------- Co-authored-by: Oliver Wipfli <[email protected]>
1 parent 217103c commit 3e8af13

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

tiles/src/main/java/com/protomaps/basemap/Basemap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public String description() {
101101

102102
@Override
103103
public String version() {
104-
return "3.7.1";
104+
return "4.0.0-alpha.0";
105105
}
106106

107107
@Override

tiles/src/main/java/com/protomaps/basemap/names/OsmNames.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,67 @@
66
import com.protomaps.basemap.text.TextEngine;
77
import java.text.NumberFormat;
88
import java.text.ParsePosition;
9+
import java.util.HashSet;
910
import java.util.Map;
11+
import java.util.Set;
12+
import java.util.stream.Stream;
1013

1114
public class OsmNames {
1215

1316
private OsmNames() {}
1417

18+
private static final String[] ALLOWED_LANGS = new String[]{
19+
"ar", // Arabic
20+
"cs", // Czech
21+
"bg", // Bulgarian
22+
"da", // Danish
23+
"de", // German
24+
"el", // Greek
25+
"en", // English
26+
"es", // Spanish
27+
"et", // Estonian
28+
"fa", // Persian
29+
"fi", // Finnish
30+
"fr", // French
31+
"ga", // Irish
32+
"he", // Hebrew
33+
"hi", // Hindi
34+
"hr", // Croatian
35+
"hu", // Hungarian
36+
"id", // Indonesian
37+
"it", // Italian
38+
"ja", // Japanese
39+
"ko", // Korean
40+
"lt", // Lithuanian
41+
"lv", // Latvian
42+
"ne", // Nepali
43+
"nl", // Dutch
44+
"no", // Norwegian
45+
"mr", // Marathi
46+
"mt", // Maltese
47+
"pl", // Polish
48+
"pt", // Portuguese
49+
"ro", // Romanian
50+
"ru", // Russian
51+
"sk", // Slovak
52+
"sl", // Slovenian
53+
"sv", // Swedish
54+
"tr", // Turkish
55+
"uk", // Ukrainian
56+
"ur", // Urdu
57+
"vi", // Vietnamese
58+
"zh", // Chinese (General)
59+
"zh-Hans", // Chinese (Simplified)
60+
"zh-Hant" // Chinese (Traditional)
61+
};
62+
63+
private static final Set<String> ALLOWED_LANG_SET =
64+
new HashSet<>(Stream.of(ALLOWED_LANGS).map(s -> "name:" + s).toList());
65+
66+
public static boolean isAllowed(String osmKey) {
67+
return ALLOWED_LANG_SET.contains(osmKey);
68+
}
69+
1570
public static FeatureCollector.Feature setOsmNames(FeatureCollector.Feature feature, SourceFeature sf,
1671
int minZoom) {
1772
FontRegistry fontRegistry = FontRegistry.getInstance();
@@ -31,7 +86,7 @@ public static FeatureCollector.Feature setOsmNames(FeatureCollector.Feature feat
3186
feature.setAttrWithMinzoom("pmap:pgf:name", encodedValue, minZoom);
3287
}
3388

34-
if (key.startsWith("name:")) {
89+
if (isAllowed(key)) {
3590
feature.setAttrWithMinzoom(key, value, minZoom);
3691

3792
if (fontRegistry.getScripts().contains(script)) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.protomaps.basemap.names;
2+
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
class OsmNamesTest {
9+
@Test
10+
void checkNames() {
11+
assertTrue(OsmNames.isAllowed("name:en"));
12+
assertTrue(OsmNames.isAllowed("name:nl"));
13+
assertTrue(OsmNames.isAllowed("name:zh"));
14+
assertTrue(OsmNames.isAllowed("name:zh-Hans"));
15+
assertTrue(OsmNames.isAllowed("name:zh-Hant"));
16+
assertFalse(OsmNames.isAllowed("name:dk"));
17+
}
18+
}

0 commit comments

Comments
 (0)