added check for language

This commit is contained in:
Chumva 2018-03-20 11:48:16 +02:00
parent 41f4c72733
commit 08b77c1898
4 changed files with 62 additions and 6 deletions

View file

@ -83,6 +83,14 @@ public abstract class AbstractPoiType {
}
return synonyms;
}
public String getEnSynonyms() {
if(synonyms == null) {
synonyms = registry.getEnSynonyms(this);
}
return synonyms;
}
public String getEnTranslation() {
if(enTranslation == null) {

View file

@ -59,6 +59,8 @@ public class MapPoiTypes {
String getSynonyms(AbstractPoiType type);
String getSynonyms(String keyName);
String getEnSynonyms(AbstractPoiType type);
String getEnSynonyms(String keyName);
}
public static MapPoiTypes getDefaultNoInit() {
@ -710,6 +712,15 @@ public class MapPoiTypes {
}
return "";
}
public String getEnSynonyms(AbstractPoiType abstractPoiType) {
if (poiTranslator != null) {
String translation = poiTranslator.getEnSynonyms(abstractPoiType);
if (!Algorithms.isEmpty(translation)) {
return translation;
}
}
return "";
}
public String getEnTranslation(AbstractPoiType abstractPoiType) {
if (poiTranslator != null) {
String translation = poiTranslator.getEnTranslation(abstractPoiType);

View file

@ -365,6 +365,14 @@ public class AppInitializer implements IProgress {
return getSynonyms(type.getIconKeyName());
}
@Override
public String getEnSynonyms(AbstractPoiType type) {
if(type.getBaseLangType() != null) {
return getSynonyms(type.getBaseLangType());
}
return getEnSynonyms(type.getIconKeyName());
}
@Override
public String getSynonyms(String keyName) {
@ -380,6 +388,24 @@ public class AppInitializer implements IProgress {
return "";
}
@Override
public String getEnSynonyms(String keyName) {
if (en == null) {
return Algorithms.capitalizeFirstLetter(
keyName.replace('_', ' '));
}
try {
Field f = R.string.class.getField("synonyms_poi_" + keyName);
if (f != null) {
Integer in = (Integer) f.get(null);
return en.getString(in);
}
} catch (Exception e) {
LOG.debug("No translation for " + keyName + " " + e.getMessage());
}
return "";
}
@Override
public String getEnTranslation(AbstractPoiType type) {
if(type.getBaseLangType() != null) {

View file

@ -41,6 +41,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
@ -369,15 +370,25 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
String desc = listItem.getTypeName();
if (listItem.getSearchResult().object instanceof AbstractPoiType) {
AbstractPoiType abstractPoiType = (AbstractPoiType) listItem.getSearchResult().object;
String synonyms[] = abstractPoiType.getSynonyms().split(";");
String synonyms = abstractPoiType.getSynonyms();
String enSynonyms = abstractPoiType.getEnSynonyms();
QuickSearchHelper searchHelper = app.getSearchUICore();
SearchUICore searchUICore = searchHelper.getCore();
String searchPhrase = searchUICore.getPhrase().getText(true);
SearchPhrase.NameStringMatcher nm = new SearchPhrase.NameStringMatcher(searchPhrase,
CollatorStringMatcher.StringMatcherMode.CHECK_EQUALS_FROM_SPACE);
for (int i = 0; i < synonyms.length; i++) {
if (nm.matches(synonyms[i])) {
desc = listItem.getTypeName() + " (" + synonyms[i] + ")";
if (!searchPhrase.isEmpty()) {
SearchPhrase.NameStringMatcher nm = new SearchPhrase.NameStringMatcher(searchPhrase,
CollatorStringMatcher.StringMatcherMode.CHECK_STARTS_FROM_SPACE);
String[] syn=new String[0];
if (app.getLanguage().equals("en")) {
syn = enSynonyms.split(";");
} else if (!synonyms.equals(enSynonyms)) {
syn = synonyms.split(";");
}
for (String aSyn : syn) {
if (nm.matches(aSyn)) {
desc = listItem.getTypeName() + " (" + aSyn + ")";
}
}
}
}