updated translation functionality for downloaded maps, tts etc.

This commit is contained in:
unknown 2014-07-07 19:58:22 +03:00
parent 1b8caefb6b
commit 5b04bf969d
5 changed files with 207 additions and 71 deletions

View file

@ -1746,23 +1746,6 @@ public class OsmandSettings {
return false;
}
public static String getVoiceName(Context ctx, String basename) {
try {
String nm = basename.replace('-', '_').replace(' ', '_');
if (nm.endsWith("_tts") || nm.endsWith("-tts")) {
nm = nm.substring(0, nm.length() - 4);
}
Field f = R.string.class.getField("lang_"+nm);
if (f != null) {
Integer in = (Integer) f.get(null);
return ctx.getString(in);
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
return basename;
}
public enum DayNightMode {
AUTO(R.string.daynight_mode_auto),
DAY(R.string.daynight_mode_day),

View file

@ -18,6 +18,7 @@ import net.osmand.plus.*;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.util.Algorithms;
import android.app.Activity;
import android.app.AlertDialog;
@ -72,7 +73,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
private ContextMenuAdapter optionsMenuAdapter;
private ActionMode actionMode;
private OsmandRegions osmandRegions;
@SuppressWarnings("unchecked")
@Override
@ -87,7 +88,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
descriptionLoader = new LoadLocalIndexDescriptionTask();
listAdapter = new LocalIndexesAdapter(this);
osmandRegions = ((OsmandApplication) getApplication()).getResourceManager().getOsmandRegions();
getExpandableListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
@ -881,7 +882,8 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
}
TextView viewName = ((TextView) v.findViewById(R.id.local_index_name));
String mapDescr = getMapDescription(child.getFileName());
String mapName = getMapName(child.getFileName());
String mapName = FileNameTranslationHelper.getFileName(ctx, ((OsmandApplication) getApplication()).getResourceManager().getOsmandRegions(), child.getFileName());
if (mapDescr.length() > 0){
viewName.setText(mapDescr + " - " + mapName);
} else {
@ -1017,37 +1019,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
return true;
}
private String getMapName(String fileName){
String mapname = getBasename(fileName);
String lc = mapname.toLowerCase();
String std = getStandardMapName(ctx,lc);
if (std != null){
return std;
}
return osmandRegions.getLocaleName(mapname);
}
private String getBasename(String fileName) {
if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) {
return fileName.substring(0, fileName.length() - IndexConstants.EXTRA_ZIP_EXT.length());
}
if (fileName.endsWith(IndexConstants.SQLITE_EXT)) {
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()).replace('_', ' ');
}
int ls = fileName.lastIndexOf('-');
if (ls >= 0) {
return fileName.substring(0, ls);
} else {
ls = fileName.lastIndexOf(".");
if (ls >= 0){
return fileName.substring(0,ls);
}
}
return fileName;
}
private String getMapDescription(String fileName){
int ls = fileName.lastIndexOf(".");
@ -1062,21 +1034,5 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
return "";
}
private String getStandardMapName(Context ctx, String basename) {
if(basename.equals("world-ski")) {
return ctx.getString(R.string.index_item_world_ski);
} else if(basename.equals("world_altitude_correction_ww15mgh")) {
return ctx.getString(R.string.index_item_world_altitude_correction);
} else if(basename.equals("world_basemap")) {
return ctx.getString(R.string.index_item_world_basemap);
} else if(basename.equals("world_bitcoin_payments")) {
return ctx.getString(R.string.index_item_world_bitcoin_payments);
} else if(basename.equals("world_seamarks")) {
return ctx.getString(R.string.index_item_world_seamarks);
}
return null;
}
}
}

View file

@ -23,6 +23,7 @@ import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.base.SuggestExternalDirectoryDialog;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.plus.voice.CommandPlayer;
import net.osmand.render.RenderingRulesStorage;
@ -563,8 +564,8 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE;
entries[k++] = getString(R.string.voice_not_use);
for (String s : voiceFiles) {
entries[k] = (s.contains("tts") ? getString(R.string.ttsvoice) +" ":"") +
OsmandSettings.getVoiceName(this, s);
entries[k] = (s.contains("tts") ? getString(R.string.ttsvoice) +" ":"") +
FileNameTranslationHelper.getVoiceName(this, s);
entrieValues[k] = s;
k++;
}

View file

@ -18,6 +18,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.util.Algorithms;
import org.xmlpull.v1.XmlPullParser;
@ -194,10 +195,10 @@ public class DownloadActivityType {
if (this == VOICE_FILE) {
if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
return ctx.getString(R.string.voice) + "\n" +
OsmandSettings.getVoiceName(ctx, getBasename(indexItem));
FileNameTranslationHelper.getVoiceName(ctx, getBasename(indexItem));
} else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
return ctx.getString(R.string.ttsvoice) + "\n" +
OsmandSettings.getVoiceName(ctx, getBasename(indexItem));
return ctx.getString(R.string.ttsvoice) + "\n" +
FileNameTranslationHelper.getVoiceName(ctx, getBasename(indexItem));
}
return getBasename(indexItem);
}

View file

@ -0,0 +1,195 @@
package net.osmand.plus.helpers;
import android.content.Context;
import net.osmand.IndexConstants;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import java.lang.reflect.Field;
/**
* Created by Barsik on 07.07.2014.
*/
public class FileNameTranslationHelper {
public static String getFileName(Context ctx, OsmandRegions regions, String fileName) {
String basename = getBasename(fileName);
if (basename.endsWith("_wiki")) { //wiki files
String wikiName = getStandardLangName(ctx, basename.substring(0, basename.indexOf("_wiki")));
String wikiWord = ctx.getString(R.string.amenity_type_osmwiki);
int index = wikiWord.indexOf("(");
if (index >= 0) {
//removing word in "()" from recourse file
return wikiWord.substring(0, index) + wikiName;
}
return ctx.getString(R.string.amenity_type_osmwiki) + " " + wikiName;
} else if (fileName.endsWith("tts")) { //tts files
return getVoiceName(ctx, fileName);
} else if (fileName.length() == 2) { //voice recorded files
try {
Field f = R.string.class.getField("lang_"+fileName);
if (f != null) {
Integer in = (Integer) f.get(null);
return ctx.getString(in);
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
//if nothing else
String lc = basename.toLowerCase();
String std = getStandardMapName(ctx, lc);
if (std != null) {
return std;
}
if (regions != null) {
return regions.getLocaleName(basename);
}
return null;
}
public static String getVoiceName(Context ctx, String basename) {
try {
String nm = basename.replace('-', '_').replace(' ', '_');
if (nm.endsWith("_tts") || nm.endsWith("-tts")) {
nm = nm.substring(0, nm.length() - 4);
}
Field f = R.string.class.getField("lang_"+nm);
if (f != null) {
Integer in = (Integer) f.get(null);
return ctx.getString(in);
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
return basename;
}
private static String getBasename(String fileName) {
if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) {
return fileName.substring(0, fileName.length() - IndexConstants.EXTRA_ZIP_EXT.length());
}
if (fileName.endsWith(IndexConstants.SQLITE_EXT)) {
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()).replace('_', ' ');
}
int ls = fileName.lastIndexOf('-');
if (ls >= 0) {
return fileName.substring(0, ls);
} else {
ls = fileName.lastIndexOf(".");
if (ls >= 0) {
return fileName.substring(0, ls);
}
}
return fileName;
}
private static String getStandardLangName(Context ctx, String filename) {
if (filename.equals("Croatian")) {
return ctx.getString(R.string.lang_hr);
} else if (filename.equals("Chinese")) {
return ctx.getString(R.string.lang_zh);
} else if (filename.equals("Portuguese")) {
return ctx.getString(R.string.lang_pt_br);
} else if (filename.equals("English")) {
return ctx.getString(R.string.lang_en);
} else if (filename.equals("Afrikaans") || filename.equals("Africaans")) {
return ctx.getString(R.string.lang_af);
} else if (filename.equals("Armenian")) {
return ctx.getString(R.string.lang_hy);
} else if (filename.equals("Basque")) {
return ctx.getString(R.string.lang_eu);
} else if (filename.equals("Belarusian")) {
return ctx.getString(R.string.lang_be);
} else if (filename.equals("Bosnian")) {
return ctx.getString(R.string.lang_bs);
} else if (filename.equals("Bulgarian")) {
return ctx.getString(R.string.lang_bg);
} else if (filename.equals("Catalan")) {
return ctx.getString(R.string.lang_ca);
} else if (filename.equals("Czech")) {
return ctx.getString(R.string.lang_cs);
} else if (filename.equals("Danish")) {
return ctx.getString(R.string.lang_da);
} else if (filename.equals("Dutch")) {
return ctx.getString(R.string.lang_nl);
} else if (filename.equals("Finnish")) {
return ctx.getString(R.string.lang_fi);
} else if (filename.equals("French")) {
return ctx.getString(R.string.lang_fr);
} else if (filename.equals("Georgian")) {
return ctx.getString(R.string.lang_ka);
} else if (filename.equals("German")) {
return ctx.getString(R.string.lang_de);
} else if (filename.equals("Greek")) {
return ctx.getString(R.string.lang_el);
} else if (filename.equals("Hebrew")) {
return ctx.getString(R.string.lang_iw);
} else if (filename.equals("Hindi")) {
return ctx.getString(R.string.lang_hi);
} else if (filename.equals("Hungarian")) {
return ctx.getString(R.string.lang_hu);
} else if (filename.equals("Indonesian")) {
return ctx.getString(R.string.lang_id);
} else if (filename.equals("Italian")) {
return ctx.getString(R.string.lang_it);
} else if (filename.equals("Japanese")) {
return ctx.getString(R.string.lang_ja);
} else if (filename.equals("Korean")) {
return ctx.getString(R.string.lang_ko);
} else if (filename.equals("Latvian")) {
return ctx.getString(R.string.lang_lv);
} else if (filename.equals("Lithuanian")) {
return ctx.getString(R.string.lang_lt);
} else if (filename.equals("Marathi")) {
return ctx.getString(R.string.lang_mr);
} else if (filename.equals("Norwegian")) {
return ctx.getString(R.string.lang_no);
} else if (filename.equals("Polish")) {
return ctx.getString(R.string.lang_pl);
} else if (filename.equals("Portuguese")) {
return ctx.getString(R.string.lang_pt);
} else if (filename.equals("Romanian")) {
return ctx.getString(R.string.lang_ro);
} else if (filename.equals("Russian")) {
return ctx.getString(R.string.lang_ru);
} else if (filename.equals("Slovak")) {
return ctx.getString(R.string.lang_sk);
} else if (filename.equals("Slovenian")) {
return ctx.getString(R.string.lang_sl);
} else if (filename.equals("Spanish")) {
return ctx.getString(R.string.lang_es);
} else if (filename.equals("Swedish")) {
return ctx.getString(R.string.lang_sv);
} else if (filename.equals("Turkish")) {
return ctx.getString(R.string.lang_tr);
} else if (filename.equals("Ukrainian")) {
return ctx.getString(R.string.lang_uk);
} else if (filename.equals("Vietnamese")) {
return ctx.getString(R.string.lang_vi);
} else if (filename.equals("Welsh")) {
return ctx.getString(R.string.lang_cy);
}
return null;
}
private static String getStandardMapName(Context ctx, String basename) {
if (basename.equals("world-ski")) {
return ctx.getString(R.string.index_item_world_ski);
} else if (basename.equals("world_altitude_correction_ww15mgh")) {
return ctx.getString(R.string.index_item_world_altitude_correction);
} else if (basename.equals("world_basemap")) {
return ctx.getString(R.string.index_item_world_basemap);
} else if (basename.equals("world_bitcoin_payments")) {
return ctx.getString(R.string.index_item_world_bitcoin_payments);
} else if (basename.equals("world_seamarks")) {
return ctx.getString(R.string.index_item_world_seamarks);
}
return null;
}
}