Skip to content

Commit

Permalink
Initial list of allowed name:* tags [#112,#270] (#284)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
bdon and wipfli authored Aug 17, 2024
1 parent 217103c commit 3e8af13
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tiles/src/main/java/com/protomaps/basemap/Basemap.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public String description() {

@Override
public String version() {
return "3.7.1";
return "4.0.0-alpha.0";
}

@Override
Expand Down
57 changes: 56 additions & 1 deletion tiles/src/main/java/com/protomaps/basemap/names/OsmNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,67 @@
import com.protomaps.basemap.text.TextEngine;
import java.text.NumberFormat;
import java.text.ParsePosition;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

public class OsmNames {

private OsmNames() {}

private static final String[] ALLOWED_LANGS = new String[]{
"ar", // Arabic
"cs", // Czech
"bg", // Bulgarian
"da", // Danish
"de", // German
"el", // Greek
"en", // English
"es", // Spanish
"et", // Estonian
"fa", // Persian
"fi", // Finnish
"fr", // French
"ga", // Irish
"he", // Hebrew
"hi", // Hindi
"hr", // Croatian
"hu", // Hungarian
"id", // Indonesian
"it", // Italian
"ja", // Japanese
"ko", // Korean
"lt", // Lithuanian
"lv", // Latvian
"ne", // Nepali
"nl", // Dutch
"no", // Norwegian
"mr", // Marathi
"mt", // Maltese
"pl", // Polish
"pt", // Portuguese
"ro", // Romanian
"ru", // Russian
"sk", // Slovak
"sl", // Slovenian
"sv", // Swedish
"tr", // Turkish
"uk", // Ukrainian
"ur", // Urdu
"vi", // Vietnamese
"zh", // Chinese (General)
"zh-Hans", // Chinese (Simplified)
"zh-Hant" // Chinese (Traditional)
};

private static final Set<String> ALLOWED_LANG_SET =
new HashSet<>(Stream.of(ALLOWED_LANGS).map(s -> "name:" + s).toList());

public static boolean isAllowed(String osmKey) {
return ALLOWED_LANG_SET.contains(osmKey);
}

public static FeatureCollector.Feature setOsmNames(FeatureCollector.Feature feature, SourceFeature sf,
int minZoom) {
FontRegistry fontRegistry = FontRegistry.getInstance();
Expand All @@ -31,7 +86,7 @@ public static FeatureCollector.Feature setOsmNames(FeatureCollector.Feature feat
feature.setAttrWithMinzoom("pmap:pgf:name", encodedValue, minZoom);
}

if (key.startsWith("name:")) {
if (isAllowed(key)) {
feature.setAttrWithMinzoom(key, value, minZoom);

if (fontRegistry.getScripts().contains(script)) {
Expand Down
18 changes: 18 additions & 0 deletions tiles/src/test/java/com/protomaps/basemap/names/OsmNamesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.protomaps.basemap.names;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

class OsmNamesTest {
@Test
void checkNames() {
assertTrue(OsmNames.isAllowed("name:en"));
assertTrue(OsmNames.isAllowed("name:nl"));
assertTrue(OsmNames.isAllowed("name:zh"));
assertTrue(OsmNames.isAllowed("name:zh-Hans"));
assertTrue(OsmNames.isAllowed("name:zh-Hant"));
assertFalse(OsmNames.isAllowed("name:dk"));
}
}

0 comments on commit 3e8af13

Please sign in to comment.