add translations for styles

This commit is contained in:
Chumva 2018-06-08 14:03:48 +03:00
parent 173a04ad3c
commit 186faca972
5 changed files with 59 additions and 13 deletions

View file

@ -62,7 +62,7 @@ public abstract class SwitchableAction<T> extends QuickAction {
final QuickActionItemTouchHelperCallback touchHelperCallback = new QuickActionItemTouchHelperCallback(); final QuickActionItemTouchHelperCallback touchHelperCallback = new QuickActionItemTouchHelperCallback();
final ItemTouchHelper touchHelper = new ItemTouchHelper(touchHelperCallback); final ItemTouchHelper touchHelper = new ItemTouchHelper(touchHelperCallback);
final Adapter adapter = new Adapter(new QuickActionListFragment.OnStartDragListener() { final Adapter adapter = new Adapter(activity, new QuickActionListFragment.OnStartDragListener() {
@Override @Override
public void onStartDrag(RecyclerView.ViewHolder viewHolder) { public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
touchHelper.startDrag(viewHolder); touchHelper.startDrag(viewHolder);
@ -107,6 +107,8 @@ public abstract class SwitchableAction<T> extends QuickAction {
public abstract void executeWithParams(MapActivity activity, String params); public abstract void executeWithParams(MapActivity activity, String params);
public abstract String getTranslatedItemName(Context context, String item);
protected void showChooseDialog(FragmentManager fm) { protected void showChooseDialog(FragmentManager fm) {
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet(); SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet();
Bundle args = new Bundle(); Bundle args = new Bundle();
@ -119,8 +121,10 @@ public abstract class SwitchableAction<T> extends QuickAction {
private List<T> itemsList = new ArrayList<>(); private List<T> itemsList = new ArrayList<>();
private final QuickActionListFragment.OnStartDragListener onStartDragListener; private final QuickActionListFragment.OnStartDragListener onStartDragListener;
private Context context;
public Adapter(QuickActionListFragment.OnStartDragListener onStartDragListener) { public Adapter(Context context, QuickActionListFragment.OnStartDragListener onStartDragListener) {
this.context = context;
this.onStartDragListener = onStartDragListener; this.onStartDragListener = onStartDragListener;
this.itemsList = new ArrayList<>(); this.itemsList = new ArrayList<>();
} }
@ -135,7 +139,7 @@ public abstract class SwitchableAction<T> extends QuickAction {
public void onBindViewHolder(final Adapter.ItemHolder holder, final int position) { public void onBindViewHolder(final Adapter.ItemHolder holder, final int position) {
final T item = itemsList.get(position); final T item = itemsList.get(position);
holder.title.setText(getItemName(item)); holder.title.setText(getItemName(item, context));
holder.handleView.setOnTouchListener(new View.OnTouchListener() { holder.handleView.setOnTouchListener(new View.OnTouchListener() {
@Override @Override
@ -274,7 +278,7 @@ public abstract class SwitchableAction<T> extends QuickAction {
protected abstract void saveListToParams(List<T> list); protected abstract void saveListToParams(List<T> list);
protected abstract String getItemName(T item); protected abstract String getItemName(T item, Context context);
protected abstract protected abstract
@StringRes @StringRes

View file

@ -1,5 +1,6 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.quickaction.actions;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
@ -69,7 +70,7 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
} }
@Override @Override
protected String getItemName(Pair<String, String> item) { protected String getItemName(Pair<String, String> item, Context context) {
return item.second; return item.second;
} }
@ -121,6 +122,15 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
} }
} }
@Override
public String getTranslatedItemName(Context context, String item) {
if (item.equals(KEY_NO_OVERLAY)) {
return context.getString(R.string.no_overlay);
} else {
return item;
}
}
@Override @Override
protected int getAddBtnText() { protected int getAddBtnText() {
return R.string.quick_action_map_overlay_action; return R.string.quick_action_map_overlay_action;

View file

@ -1,5 +1,6 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.quickaction.actions;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
@ -108,7 +109,16 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
settings.MAP_ONLINE_DATA.set(true); settings.MAP_ONLINE_DATA.set(true);
activity.getMapLayers().updateMapSource(activity.getMapView(), settings.MAP_TILE_SOURCES); activity.getMapLayers().updateMapSource(activity.getMapView(), settings.MAP_TILE_SOURCES);
} }
Toast.makeText(activity, activity.getString(R.string.quick_action_map_source_switch, params), Toast.LENGTH_SHORT).show(); Toast.makeText(activity, activity.getString(R.string.quick_action_map_source_switch, getTranslatedItemName(activity, params)), Toast.LENGTH_SHORT).show();
}
@Override
public String getTranslatedItemName(Context context, String item) {
if (item.equals(LAYER_OSM_VECTOR)) {
return context.getString(R.string.vector_data);
} else {
return item;
}
} }
@Override @Override
@ -178,7 +188,7 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
} }
@Override @Override
protected String getItemName(Pair<String, String> item) { protected String getItemName(Pair<String, String> item, Context context) {
return item.second; return item.second;
} }

View file

@ -1,5 +1,6 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.quickaction.actions;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
@ -69,12 +70,19 @@ public class MapStyleAction extends SwitchableAction<String> {
app.getRendererRegistry().setCurrentSelectedRender(loaded); app.getRendererRegistry().setCurrentSelectedRender(loaded);
ConfigureMapMenu.refreshMapComplete(activity); ConfigureMapMenu.refreshMapComplete(activity);
Toast.makeText(activity, activity.getString(R.string.quick_action_map_style_switch, params), Toast.LENGTH_SHORT).show(); Toast.makeText(activity, activity.getString(R.string.quick_action_map_style_switch, getTranslatedItemName(activity,params)), Toast.LENGTH_SHORT).show();
} else { } else {
Toast.makeText(activity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show(); Toast.makeText(activity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
} }
} }
@Override
public String getTranslatedItemName(Context context, String item) {
String translation = RendererRegistry.getTranslatedRendererName(context, item);
return translation != null ? translation
: item.replace('_', ' ').replace('-', ' ');
}
public List<String> getFilteredStyles() { public List<String> getFilteredStyles() {
List<String> filtered = new ArrayList<>(); List<String> filtered = new ArrayList<>();
@ -192,9 +200,13 @@ public class MapStyleAction extends SwitchableAction<String> {
} }
@Override @Override
protected String getItemName(String item) { protected String getItemName(String item, Context context) {
if (context != null) {
return getTranslatedItemName(context, item);
} else {
return item; return item;
} }
}
@Override @Override
protected String getTitle(List<String> filters) { protected String getTitle(List<String> filters) {

View file

@ -1,5 +1,6 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.quickaction.actions;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
@ -69,7 +70,7 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
} }
@Override @Override
protected String getItemName(Pair<String, String> item) { protected String getItemName(Pair<String, String> item, Context context) {
return item.second; return item.second;
} }
@ -124,6 +125,15 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
} }
} }
@Override
public String getTranslatedItemName(Context context, String item) {
if (item.equals(KEY_NO_UNDERLAY)) {
return context.getString(R.string.no_underlay);
} else {
return item;
}
}
@Override @Override
protected int getAddBtnText() { protected int getAddBtnText() {
return R.string.quick_action_map_underlay_action; return R.string.quick_action_map_underlay_action;