Skip to content

Commit

Permalink
Merge branch 'i18n_support_improvements'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Jan 28, 2025
2 parents 62a5307 + 7c0c38d commit 7d93fcf
Show file tree
Hide file tree
Showing 17 changed files with 980 additions and 124 deletions.
4 changes: 3 additions & 1 deletion documentation/docs/help/en/Property editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ If alternative tagging is available for the main object, the alternative presets
* Set _Apply with optional tags_, after setting this, optional tags will be added when you apply the preset to an object, the same behaviour as pressing the ![Apply preset with optional tags](../images/tag_menu_apply_preset.png), but this will work when auto-applying the best matching preset on startup of the property editor too.
* _Remove_ remove the item from the MRU preset view. Note that the above settings are persistent and will remain in force even if the preset item is removed.

Further behaviour and menu items are similar or the same as for the _Details_ tab, the _Add language tags_ menu item will add local language variants of the name and similar keys to the preset if configured for the region (see [the GeoContext repository](https://github.com/simonpoole/geocontext)).
The _Add language variants_ menu item will add local language variants of the name and similar keys to the form if configured for the region (see [the GeoContext repository](https://github.com/simonpoole/geocontext)).

Further behaviour and menu items are similar or the same as for the _Details_ tab.

## Details Tab

Expand Down
43 changes: 43 additions & 0 deletions src/main/assets/geocontext.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@
"dm": {
"left-hand-traffic": true
},
"es-ct": {
"languages": [
"ca",
"es"
]
},
"es-ib": {
"languages": [
"ca",
"es"
]
},
"fi": {
"languages": [
"fi",
"sv"
]
},
"fj": {
"left-hand-traffic": true
},
Expand Down Expand Up @@ -143,6 +161,31 @@
"addr:postcode"
]
},
"gb-wls": {
"distance": "imperial",
"left-hand-traffic": true,
"speed-limits": [
20,
30,
40,
50,
60,
70
],
"address-keys": [
"addr:housenumber",
"addr:street",
"addr:place",
"addr:parentstreet",
"addr:suburb",
"addr:city",
"addr:postcode"
],
"languages": [
"en",
"cy"
]
},
"gi": {
"distance": "metric",
"left-hand-traffic": false
Expand Down
2 changes: 2 additions & 0 deletions src/main/assets/help/en/Privacy.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<hr />
<h2>hide: - navigation</h2>
<h1>Privacy statement</h1>
<p>Vespucci is a collaboratively developed app for editing OpenStreetMap data via its editing API. The developers do not collect, store or otherwise process any personal data related to your usage of the app, you should however be aware of the following:</p>
<ul>
Expand Down
3 changes: 2 additions & 1 deletion src/main/assets/help/en/Property editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ <h2>Properties Tab</h2>
<li>Set <em>Apply with optional tags</em>, after setting this, optional tags will be added when you apply the preset to an object, the same behaviour as pressing the <img src="../images/tag_menu_apply_preset.png" alt="Apply preset with optional tags" />, but this will work when auto-applying the best matching preset on startup of the property editor too.</li>
<li><em>Remove</em> remove the item from the MRU preset view. Note that the above settings are persistent and will remain in force even if the preset item is removed.</li>
</ul>
<p>Further behaviour and menu items are similar or the same as for the <em>Details</em> tab, the <em>Add language tags</em> menu item will add local language variants of the name and similar keys to the preset if configured for the region (see <a href="https://github.com/simonpoole/geocontext">the GeoContext repository</a>).</p>
<p>The <em>Add language variants</em> menu item will add local language variants of the name and similar keys to the form if configured for the region (see <a href="https://github.com/simonpoole/geocontext">the GeoContext repository</a>).</p>
<p>Further behaviour and menu items are similar or the same as for the <em>Details</em> tab.</p>
<h2>Details Tab</h2>
<p>Display of the key - value attributes of the edited object.</p>
<p>The following operations can be performed on selected tags</p>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/blau/android/nsi/Names.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private void readTags(@NonNull JsonReader reader, @NonNull TagMap tags) throws I
if (name != null && name.equals(brand)) {
String amenity = tags.get(Tags.KEY_AMENITY);
if (amenity != null && AMENITY_VALUES_TO_REMOVE.contains(amenity)) {
for (String nameTag : Tags.I18N_NAME_KEYS) {
for (String nameTag : Tags.I18N_KEYS) {
tags.remove(nameTag);
}
}
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/de/blau/android/osm/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,20 @@ public final class Tags {
public static final String KEY_BUILDING = "building";
public static final String KEY_ENTRANCE = "entrance";
//
public static final String KEY_NAME = "name";
public static final String KEY_OFFICIAL_NAME = "official_name";
public static final String KEY_ALT_NAME = "alt_name";
private static final String KEY_LOC_NAME = "loc_name";
public static final String KEY_OLD_NAME = "old_name";
private static final String KEY_SHORT_NAME = "short_name";
private static final String KEY_REG_NAME = "reg_name";
private static final String KEY_NAT_NAME = "nat_name";
public static final String KEY_INT_NAME = "int_name";
public static final List<String> I18N_NAME_KEYS = Collections
.unmodifiableList(Arrays.asList(KEY_NAME, KEY_OFFICIAL_NAME, KEY_ALT_NAME, KEY_LOC_NAME, KEY_SHORT_NAME, KEY_REG_NAME, KEY_NAT_NAME));
public static final String KEY_NAME = "name";
public static final String KEY_OFFICIAL_NAME = "official_name";
public static final String KEY_ALT_NAME = "alt_name";
private static final String KEY_LOC_NAME = "loc_name";
public static final String KEY_OLD_NAME = "old_name";
private static final String KEY_SHORT_NAME = "short_name";
private static final String KEY_REG_NAME = "reg_name";
private static final String KEY_NAT_NAME = "nat_name";
public static final String KEY_INT_NAME = "int_name";
public static final String KEY_BRIDGE_NAME = "bridge:name";

public static final List<String> I18N_KEYS = Collections.unmodifiableList(Arrays.asList(KEY_NAME, KEY_OFFICIAL_NAME, KEY_ALT_NAME, KEY_LOC_NAME,
KEY_SHORT_NAME, KEY_REG_NAME, KEY_NAT_NAME, KEY_BRIDGE_NAME, KEY_ADDR_STREET, KEY_ADDR_PLACE, KEY_ADDR_BLOCK, KEY_ADDR_PARENTSTREET,
KEY_ADDR_HAMLET, KEY_ADDR_SUBURB, KEY_ADDR_CITY, KEY_ADDR_SUBDISTRICT, KEY_ADDR_DISTRICT, KEY_ADDR_PROVINCE, KEY_ADDR_STATE, KEY_ADDR_COUNTRY));

/**
* Check if a key in general can be assumed to have a different value for each occurrence
Expand All @@ -119,7 +122,7 @@ public final class Tags {
* @return true if the key has name-like semantics
*/
public static boolean isLikeAName(@NonNull String key) {
List<String> nameLikeKeys = new ArrayList<>(Tags.I18N_NAME_KEYS);
List<String> nameLikeKeys = new ArrayList<>(Tags.I18N_KEYS);
nameLikeKeys.add(Tags.KEY_ADDR);
nameLikeKeys.add(Tags.KEY_ADDR_HOUSENAME);
nameLikeKeys.add(Tags.KEY_ADDR_UNIT);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/de/blau/android/presets/AutoPreset.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.blau.android.presets;

import static de.blau.android.contract.Constants.LOG_TAG_LEN;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -45,7 +47,8 @@

public class AutoPreset {

private static final String DEBUG_TAG = AutoPreset.class.getSimpleName().substring(0, Math.min(23, AutoPreset.class.getSimpleName().length()));
private static final int TAG_LEN = Math.min(LOG_TAG_LEN, AutoPreset.class.getSimpleName().length());
private static final String DEBUG_TAG = AutoPreset.class.getSimpleName().substring(0, TAG_LEN);

public static final String ICON = "auto-preset.png";
private static final String PNG = ".png";
Expand Down Expand Up @@ -186,7 +189,7 @@ public Preset fromTaginfo(@NonNull String term, int maxResults) {
field.setMatchType(MatchType.NONE);
} else {
String[] s = key.split(":", 2);
if (Tags.I18N_NAME_KEYS.contains(key) || (s.length == 2 && Tags.I18N_NAME_KEYS.contains(s[0]))) {
if (Tags.I18N_KEYS.contains(key) || (s.length == 2 && Tags.I18N_KEYS.contains(s[0]))) {
// if a name key add without value
item.addTag(false, key, PresetKeyType.TEXT, null, MatchType.NONE);
} else if (!item.hasKey(key)) {
Expand Down
33 changes: 25 additions & 8 deletions src/main/java/de/blau/android/presets/Preset.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -52,6 +54,7 @@
import de.blau.android.prefs.AdvancedPrefDatabase;
import de.blau.android.prefs.PresetEditorActivity;
import de.blau.android.search.Wrapper;
import de.blau.android.util.GeoContext.Properties;
import de.blau.android.util.Hash;
import de.blau.android.util.SavingHelper;
import de.blau.android.util.SearchIndexUtils;
Expand Down Expand Up @@ -1585,18 +1588,32 @@ public static boolean generateTaginfoJson(@NonNull Context ctx, @NonNull Preset[
outputStream.println("{\"description\":\"Automatically discarded\",\"key\":\"" + key + "\"},");
}
outputStream.println("{\"description\":\"Used for validation\",\"key\":\"check_date\"},");

Set<String> languages = new HashSet<>();
for (Properties properties : App.getGeoContext(ctx).allProperties()) {
String[] languagesArray = properties.getLanguages();
if (languagesArray != null) {
languages.addAll(Arrays.asList(languagesArray));
}
}
for (String language : languages) {
for (String key : Tags.I18N_KEYS) {
outputStream.println("{\"description\":\"Added in multi-lingual regions\",\"key\":\"" + key + ":" + language + "\"},");
}
}
int presetsCount = presets.length;
for (int i = 0; i < presetsCount; i++) {
if (presets[i] != null) {
if (i != 0) {
if (i != presetsCount - 1) {
outputStream.print(",");
}
outputStream.println();
if (presets[i] == null) {
continue;
}
if (i != 0) {
if (i != presetsCount - 1) {
outputStream.print(",");
}
String json = presets[i].toJSON();
outputStream.print(json);
outputStream.println();
}
String json = presets[i].toJSON();
outputStream.print(json);
}
outputStream.println("]}");
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/blau/android/presets/PresetTagField.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public String getHint() {
*
* @param hint the hint to set
*/
void setHint(@Nullable String hint) {
public void setHint(@Nullable String hint) {
this.hint = hint;
}

Expand Down
Loading

0 comments on commit 7d93fcf

Please sign in to comment.