From 2b040693202c8e5d4bf6557318518e55346645ec Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 20 Jun 2010 11:41:55 +0000 Subject: [PATCH] externalize strings git-svn-id: https://osmand.googlecode.com/svn/trunk@185 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- DataExtractionOSM/src/com/osmand/Messages.java | 3 ++- .../src/com/osmand/osm/MapUtils.java | 9 +++++---- .../src/com/osmand/osm/io/OsmBaseStorage.java | 2 +- DataExtractionOSM/src/messages.properties | 12 ++++++++++++ DataExtractionOSM/src/messages_ru.properties | 12 ++++++++++++ OsmAnd/res/values-ru-rRU/strings.xml | 1 + OsmAnd/res/values/strings.xml | 15 +++++++++++++++ OsmAnd/src/com/osmand/PoiFilter.java | 4 ++-- .../com/osmand/ProgressDialogImplementation.java | 5 ++++- OsmAnd/src/com/osmand/ResourceManager.java | 9 +++++---- .../com/osmand/activities/MainMenuActivity.java | 9 +++++---- OsmAnd/src/com/osmand/activities/MapActivity.java | 2 +- .../osmand/activities/NavigatePointActivity.java | 4 ++-- .../src/com/osmand/activities/RoutingHelper.java | 11 ++++++----- .../com/osmand/activities/SavingTrackHelper.java | 5 +++-- .../com/osmand/activities/SettingsActivity.java | 2 +- .../osmand/activities/search/SearchActivity.java | 6 +++--- 17 files changed, 80 insertions(+), 31 deletions(-) diff --git a/DataExtractionOSM/src/com/osmand/Messages.java b/DataExtractionOSM/src/com/osmand/Messages.java index 940f777dc1..7bd4128a03 100644 --- a/DataExtractionOSM/src/com/osmand/Messages.java +++ b/DataExtractionOSM/src/com/osmand/Messages.java @@ -5,7 +5,8 @@ import java.util.ResourceBundle; public class Messages { private static ResourceBundle bundle = ResourceBundle.getBundle("messages"); //$NON-NLS-1$ - + public static final String KEY_M = "m"; //$NON-NLS-1$ + public static final String KEY_KM = "km"; //$NON-NLS-1$ public static String getMessage(String key){ return bundle.getString(key); diff --git a/DataExtractionOSM/src/com/osmand/osm/MapUtils.java b/DataExtractionOSM/src/com/osmand/osm/MapUtils.java index 8c27a7ddbb..a2920390f8 100644 --- a/DataExtractionOSM/src/com/osmand/osm/MapUtils.java +++ b/DataExtractionOSM/src/com/osmand/osm/MapUtils.java @@ -7,6 +7,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import com.osmand.Messages; import com.osmand.data.MapObject; /** @@ -208,13 +209,13 @@ public class MapUtils { public static String getFormattedDistance(int meters){ if(meters >= 100000){ - return meters / 1000 + " km"; + return meters / 1000 + " " + Messages.getMessage(Messages.KEY_KM); //$NON-NLS-1$ } else if(meters >= 10000){ - return MessageFormat.format("{0, number, #.#}"+" km", ((float) meters) / 1000); //$NON-NLS-1$ + return MessageFormat.format("{0, number, #.#} "+Messages.getMessage(Messages.KEY_KM), ((float) meters) / 1000); //$NON-NLS-1$ } else if(meters > 1500){ - return MessageFormat.format("{0, number, #.##}"+" km", ((float) meters) / 1000); //$NON-NLS-1$ + return MessageFormat.format("{0, number, #.##}"+Messages.getMessage(Messages.KEY_KM), ((float) meters) / 1000); //$NON-NLS-1$ } else { - return meters + " m"; + return meters + " "+Messages.getMessage(Messages.KEY_M); //$NON-NLS-1$ } } } diff --git a/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java b/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java index 9b385e6584..d5658c2973 100644 --- a/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java +++ b/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java @@ -236,7 +236,7 @@ public class OsmBaseStorage extends DefaultHandler { entityInfo.put(currentParsedEntity.getId(), currentParsedEntityInfo); } if(!supressWarnings && oldEntity!= null){ - throw new UnsupportedOperationException("Entity with id=" + oldEntity.getId() +" is duplicated in osm map"); + throw new UnsupportedOperationException("Entity with id=" + oldEntity.getId() +" is duplicated in osm map"); //$NON-NLS-1$ //$NON-NLS-2$ } } else { // System.gc(); diff --git a/DataExtractionOSM/src/messages.properties b/DataExtractionOSM/src/messages.properties index f028aa45af..347f4ae326 100644 --- a/DataExtractionOSM/src/messages.properties +++ b/DataExtractionOSM/src/messages.properties @@ -23,6 +23,16 @@ amenity_type_tourism = Tourism amenity_type_transportation = Transportation +indexing_address = Indexing address + +indexing_poi = Indexing POI + +km = km + +km_h = km/h + +m = m + poi_filter_car_aid = Car aid poi_filter_closest_poi = Closest poi @@ -34,3 +44,5 @@ poi_filter_food_shop = Food shop poi_filter_for_tourists = For tourists poi_filter_fuel = Fuel + +version_index_is_not_supported = The version of index ''{0}'' is not supported diff --git a/DataExtractionOSM/src/messages_ru.properties b/DataExtractionOSM/src/messages_ru.properties index 5f4fc780ba..06fa2dac66 100644 --- a/DataExtractionOSM/src/messages_ru.properties +++ b/DataExtractionOSM/src/messages_ru.properties @@ -23,6 +23,16 @@ amenity_type_tourism = \u0422\u0443\u0440\u0438\u0437\u043C amenity_type_transportation = \u0422\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442 +indexing_address = \u0418\u043D\u0434\u0435\u043A\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044F \u0430\u0434\u0440\u0435\u0441 + +indexing_poi = \u0418\u043D\u0434\u0435\u043A\u0441\u0438\u0440\u0443\u044E\u0442\u0441\u044F POI + +km = \u043A\u043C + +km_h = \u043A\u043C/\u0447 + +m = \u043C + poi_filter_car_aid = \u0410\u0432\u0442\u043E\u043F\u043E\u043C\u043E\u0449\u044C poi_filter_closest_poi = \u0411\u043B\u0438\u0436\u0430\u0439\u0448\u0438\u0435 poi @@ -34,3 +44,5 @@ poi_filter_food_shop = \u041F\u0440\u043E\u0434\u0443\u043A\u0442\u043E\u0432\u0 poi_filter_for_tourists = \u0414\u043B\u044F \u0442\u0443\u0440\u0438\u0441\u0442\u043E\u0432 poi_filter_fuel = \u0417\u0430\u043F\u0440\u0430\u0432\u043A\u0438 + +version_index_is_not_supported = \u0412\u0435\u0440\u0441\u0438\u044F \u0438\u043D\u0434\u0435\u043A\u0441\u0430 ''{0}'' \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044F diff --git a/OsmAnd/res/values-ru-rRU/strings.xml b/OsmAnd/res/values-ru-rRU/strings.xml index 4d76cd34bb..d261aa2b56 100644 --- a/OsmAnd/res/values-ru-rRU/strings.xml +++ b/OsmAnd/res/values-ru-rRU/strings.xml @@ -1,5 +1,6 @@ + Окончен : Перезагрузить индексы с SD Обновить индексы Использовать интернет для расчета маршрута diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 69ae81f0e8..8de618ec2b 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,20 @@ + POI + Error occurred while saving gpx + Error calculating route : + Error occurred while calculating route + Empty route is calculated + New route is calculated, distance : + You arrived at destination point + Locations are invalid + Go back to OsmAnd map + Close + Loading data + Reading indices... + Previous application run was crashed. Log file is at {0}. Please raise the issue and attach log file. + Saving gpx tracks to SD... + Finished : Reload data indexes from SD Reload indexes Use internet to calculate route diff --git a/OsmAnd/src/com/osmand/PoiFilter.java b/OsmAnd/src/com/osmand/PoiFilter.java index 156bdb6e29..269a258b50 100644 --- a/OsmAnd/src/com/osmand/PoiFilter.java +++ b/OsmAnd/src/com/osmand/PoiFilter.java @@ -78,9 +78,9 @@ public class PoiFilter { public String getSearchArea(){ if(zoom <= 14){ int d = (int) (1 * (1 << (14 - zoom))); - return " < " + d + " km"; + return " < " + d + " " + Messages.getMessage(Messages.KEY_KM); //$NON-NLS-1$//$NON-NLS-2$ } else { - return " < 500 m"; + return " < 500 " + Messages.getMessage(Messages.KEY_M); //$NON-NLS-1$ } } diff --git a/OsmAnd/src/com/osmand/ProgressDialogImplementation.java b/OsmAnd/src/com/osmand/ProgressDialogImplementation.java index 5a06d91636..28f8572aeb 100644 --- a/OsmAnd/src/com/osmand/ProgressDialogImplementation.java +++ b/OsmAnd/src/com/osmand/ProgressDialogImplementation.java @@ -1,6 +1,7 @@ package com.osmand; import android.app.ProgressDialog; +import android.content.Context; import android.os.Handler; import android.os.Message; @@ -15,8 +16,10 @@ public class ProgressDialogImplementation implements IProgress { private Handler mViewUpdateHandler; private Thread run; + private Context context; public ProgressDialogImplementation(final ProgressDialog dlg){ + context = dlg.getContext(); mViewUpdateHandler = new Handler(){ @Override public void handleMessage(Message msg) { @@ -87,7 +90,7 @@ public class ProgressDialogImplementation implements IProgress { @Override public void finishTask() { if (taskName != null) { - message = "Finished : " + taskName; + message = context.getResources().getString(R.string.finished_task) + taskName; mViewUpdateHandler.sendEmptyMessage(0); } work = -1; diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index 07486db235..a240d86f40 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -192,12 +192,13 @@ public class ResourceManager { for (File f : file.listFiles()) { if (f.getName().endsWith(IndexConstants.POI_INDEX_EXT)) { AmenityIndexRepository repository = new AmenityIndexRepository(); - progress.startTask("Indexing poi " + f.getName(), -1); + + progress.startTask(Messages.getMessage("indexing_poi") + f.getName(), -1); //$NON-NLS-1$ boolean initialized = repository.initialize(progress, f); if (initialized) { amenityRepositories.add(repository); }else { - warnings.add(MessageFormat.format("The version of index ''{0}''is not supported", f.getName())); + warnings.add(MessageFormat.format(Messages.getMessage("version_index_is_not_supported"), f.getName())); //$NON-NLS-1$ } } } @@ -214,12 +215,12 @@ public class ResourceManager { for (File f : file.listFiles()) { if (f.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT)) { RegionAddressRepository repository = new RegionAddressRepository(); - progress.startTask("Indexing address" + f.getName(), -1); + progress.startTask(Messages.getMessage("indexing_address") + f.getName(), -1); //$NON-NLS-1$ boolean initialized = repository.initialize(progress, f); if (initialized) { addressMap.put(repository.getName(), repository); } else { - warnings.add(MessageFormat.format("The version of index ''{0}''is not supported", f.getName())); + warnings.add(MessageFormat.format(Messages.getMessage("version_index_is_not_supported"), f.getName())); //$NON-NLS-1$ } } } diff --git a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java index dbe585ea06..261689e162 100644 --- a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java +++ b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java @@ -49,7 +49,8 @@ public class MainMenuActivity extends Activity { public void startApplication(){ if(!applicationAlreadyStarted){ - final ProgressDialog dlg = ProgressDialog.show(this, "Loading data", "Reading indices...", true); + + final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.loading_data), getString(R.string.reading_indexes), true); final ProgressDialogImplementation impl = new ProgressDialogImplementation(dlg); impl.setRunnable("Initializing app", new Runnable(){ //$NON-NLS-1$ @Override @@ -58,7 +59,7 @@ public class MainMenuActivity extends Activity { List warnings = ResourceManager.getResourceManager().reloadIndexes(impl); SavingTrackHelper helper = new SavingTrackHelper(MainMenuActivity.this); if (helper.hasDataToSave()) { - impl.startTask("Saving gpx tracks to SD...", -1); + impl.startTask(getString(R.string.saving_gpx_tracks), -1); helper.saveDataToGpx(); } helper.close(); @@ -77,10 +78,10 @@ public class MainMenuActivity extends Activity { File file = new File(Environment.getExternalStorageDirectory(), EXCEPTION_PATH); if(file.exists() && file.length() > 0){ if(size != file.length()){ - String msg = MessageFormat.format("Previous application run was crashed. Log file is at {0}. Please raise the issue and attach log file.", + String msg = MessageFormat.format(getString(R.string.previous_run_crashed), EXCEPTION_PATH); Builder builder = new AlertDialog.Builder(MainMenuActivity.this); - builder.setMessage(msg).setNeutralButton("Close", null).show(); + builder.setMessage(msg).setNeutralButton(getString(R.string.close), null).show(); getPreferences(MODE_WORLD_READABLE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit(); } diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index e67320f05d..7f9ce963fa 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -97,7 +97,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat Notification notification = new Notification(R.drawable.icon, "", //$NON-NLS-1$ System.currentTimeMillis()); notification.setLatestEventInfo(this, Version.APP_NAME, - "Go back to OsmAnd map", PendingIntent.getActivity( + getString(R.string.go_back_to_osmand), PendingIntent.getActivity( this.getBaseContext(), 0, notificationIndent, PendingIntent.FLAG_UPDATE_CURRENT)); return notification; diff --git a/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java b/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java index d66bd0d79b..68c253dee5 100644 --- a/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java +++ b/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java @@ -92,7 +92,7 @@ public class NavigatePointActivity extends Activity { ((TextView)findViewById(R.id.LatitudeEdit)).setText(convert(lat, newFormat)); ((TextView)findViewById(R.id.LongitudeEdit)).setText(convert(lon, newFormat)); } catch (RuntimeException e) { - ((TextView) findViewById(R.id.ValidateTextView)).setText("Locations are invalid"); + ((TextView) findViewById(R.id.ValidateTextView)).setText(R.string.invalid_locations); Log.w(LogUtil.TAG, "Convertion failed", e); //$NON-NLS-1$ } } @@ -132,7 +132,7 @@ public class NavigatePointActivity extends Activity { } close(); } catch (RuntimeException e) { - ((TextView) findViewById(R.id.ValidateTextView)).setText("Locations are invalid"); + ((TextView) findViewById(R.id.ValidateTextView)).setText(R.string.invalid_locations); Log.w(LogUtil.TAG, "Convertion failed", e); //$NON-NLS-1$ } } diff --git a/OsmAnd/src/com/osmand/activities/RoutingHelper.java b/OsmAnd/src/com/osmand/activities/RoutingHelper.java index 035e13161b..cb6251ddc7 100644 --- a/OsmAnd/src/com/osmand/activities/RoutingHelper.java +++ b/OsmAnd/src/com/osmand/activities/RoutingHelper.java @@ -22,6 +22,7 @@ import android.util.FloatMath; import android.widget.Toast; import com.osmand.LogUtil; +import com.osmand.R; import com.osmand.OsmandSettings.ApplicationMode; import com.osmand.osm.LatLon; import com.osmand.osm.MapUtils; @@ -94,7 +95,7 @@ public class RoutingHelper { if(currentRoute > routeNodes.size() - 3 && currentLocation.distanceTo(lastPoint) < 60){ if(lastFixedLocation != null && lastFixedLocation.distanceTo(lastPoint) < 60){ // TODO mark as finished - showMessage("You arrived at destination point"); + showMessage(activity.getString(R.string.arrived_at_destination)); currentRoute = routeNodes.size() - 1; } lastFixedLocation = currentLocation; @@ -241,16 +242,16 @@ public class RoutingHelper { currentRunningJob = null; } if(res.isCalculated()){ - showMessage("New route is calculated distance : " + MapUtils.getFormattedDistance(sumDistance(res.list))); + showMessage(activity.getString(R.string.new_route_calculated_dist) + MapUtils.getFormattedDistance(sumDistance(res.list))); // be aware that is non ui thread activity.getMapView().refreshMap(); } else { if(res.errorMessage != null){ - showMessage("Error calculating route : " + res.errorMessage); + showMessage(activity.getString(R.string.error_calculating_route)+ res.errorMessage); } else if(res.list == null){ - showMessage("Error occurred while calculating route"); + showMessage(activity.getString(R.string.error_calculating_route_occured)); } else { - showMessage("Empty route is calculated"); + showMessage(activity.getString(R.string.empty_route_calculated)); } } lastTimeEvaluatedRoute = System.currentTimeMillis(); diff --git a/OsmAnd/src/com/osmand/activities/SavingTrackHelper.java b/OsmAnd/src/com/osmand/activities/SavingTrackHelper.java index c35ee49e51..9aaea2f91b 100644 --- a/OsmAnd/src/com/osmand/activities/SavingTrackHelper.java +++ b/OsmAnd/src/com/osmand/activities/SavingTrackHelper.java @@ -24,6 +24,7 @@ import android.widget.Toast; import com.osmand.LogUtil; import com.osmand.OsmandSettings; +import com.osmand.R; import com.osmand.Version; public class SavingTrackHelper extends SQLiteOpenHelper { @@ -126,10 +127,10 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } } catch (RuntimeException e) { log.error("Error saving gpx", e); //$NON-NLS-1$ - Toast.makeText(ctx, "Exception occurred while saving gpx", Toast.LENGTH_LONG); + Toast.makeText(ctx, ctx.getString(R.string.error_occurred_saving_gpx), Toast.LENGTH_LONG); } catch (IOException e) { log.error("Error saving gpx", e); //$NON-NLS-1$ - Toast.makeText(ctx, "Exception occurred while saving gpx", Toast.LENGTH_LONG); + Toast.makeText(ctx, ctx.getString(R.string.error_occurred_saving_gpx), Toast.LENGTH_LONG); } } diff --git a/OsmAnd/src/com/osmand/activities/SettingsActivity.java b/OsmAnd/src/com/osmand/activities/SettingsActivity.java index 6d842ecf9a..b290e1b41f 100644 --- a/OsmAnd/src/com/osmand/activities/SettingsActivity.java +++ b/OsmAnd/src/com/osmand/activities/SettingsActivity.java @@ -224,7 +224,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } public void reloadIndexes(){ - final ProgressDialog dlg = ProgressDialog.show(this, "Loading data", "Reading indices...", true); + final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.loading_data), getString(R.string.reading_indexes), true); final ProgressDialogImplementation impl = new ProgressDialogImplementation(dlg); impl.setRunnable("Initializing app", new Runnable(){ //$NON-NLS-1$ @Override diff --git a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java index 5a5b04f18c..6054a9f6e5 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java @@ -24,9 +24,9 @@ public class SearchActivity extends TabActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TabHost host = getTabHost(); - host.addTab(host.newTabSpec("Search_POI").setIndicator("POI").setContent(new Intent(this, SearchPoiFilterActivity.class))); //$NON-NLS-1$ - host.addTab(host.newTabSpec("Search_Address").setIndicator(this.getResources().getString(R.string.search_tabs_address)).setContent(new Intent(this, SearchAddressActivity.class))); //$NON-NLS-1$ - host.addTab(host.newTabSpec("Search_Location").setIndicator(this.getResources().getString(R.string.search_tabs_location)).setContent(new Intent(this, NavigatePointActivity.class))); //$NON-NLS-1$ + host.addTab(host.newTabSpec("Search_POI").setIndicator(getString(R.string.poi)).setContent(new Intent(this, SearchPoiFilterActivity.class))); //$NON-NLS-1$ + host.addTab(host.newTabSpec("Search_Address").setIndicator(getString(R.string.search_tabs_address)).setContent(new Intent(this, SearchAddressActivity.class))); //$NON-NLS-1$ + host.addTab(host.newTabSpec("Search_Location").setIndicator(getString(R.string.search_tabs_location)).setContent(new Intent(this, NavigatePointActivity.class))); //$NON-NLS-1$ } }