externalize strings

git-svn-id: https://osmand.googlecode.com/svn/trunk@185 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-06-20 11:41:55 +00:00
parent a47753e2d7
commit 2b04069320
17 changed files with 80 additions and 31 deletions

View file

@ -5,7 +5,8 @@ import java.util.ResourceBundle;
public class Messages { public class Messages {
private static ResourceBundle bundle = ResourceBundle.getBundle("messages"); //$NON-NLS-1$ 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){ public static String getMessage(String key){
return bundle.getString(key); return bundle.getString(key);

View file

@ -7,6 +7,7 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import com.osmand.Messages;
import com.osmand.data.MapObject; import com.osmand.data.MapObject;
/** /**
@ -208,13 +209,13 @@ public class MapUtils {
public static String getFormattedDistance(int meters){ public static String getFormattedDistance(int meters){
if(meters >= 100000){ if(meters >= 100000){
return meters / 1000 + " km"; return meters / 1000 + " " + Messages.getMessage(Messages.KEY_KM); //$NON-NLS-1$
} else if(meters >= 10000){ } 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){ } 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 { } else {
return meters + " m"; return meters + " "+Messages.getMessage(Messages.KEY_M); //$NON-NLS-1$
} }
} }
} }

View file

@ -236,7 +236,7 @@ public class OsmBaseStorage extends DefaultHandler {
entityInfo.put(currentParsedEntity.getId(), currentParsedEntityInfo); entityInfo.put(currentParsedEntity.getId(), currentParsedEntityInfo);
} }
if(!supressWarnings && oldEntity!= null){ 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 { } else {
// System.gc(); // System.gc();

View file

@ -23,6 +23,16 @@ amenity_type_tourism = Tourism
amenity_type_transportation = Transportation 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_car_aid = Car aid
poi_filter_closest_poi = Closest poi poi_filter_closest_poi = Closest poi
@ -34,3 +44,5 @@ poi_filter_food_shop = Food shop
poi_filter_for_tourists = For tourists poi_filter_for_tourists = For tourists
poi_filter_fuel = Fuel poi_filter_fuel = Fuel
version_index_is_not_supported = The version of index ''{0}'' is not supported

View file

@ -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 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_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 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_for_tourists = \u0414\u043B\u044F \u0442\u0443\u0440\u0438\u0441\u0442\u043E\u0432
poi_filter_fuel = \u0417\u0430\u043F\u0440\u0430\u0432\u043A\u0438 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

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="finished_task">Окончен : </string>
<string name="reload_indexes_descr">Перезагрузить индексы с SD</string> <string name="reload_indexes_descr">Перезагрузить индексы с SD</string>
<string name="reload_indexes">Обновить индексы</string> <string name="reload_indexes">Обновить индексы</string>
<string name="use_online_routing_descr">Использовать интернет для расчета маршрута</string> <string name="use_online_routing_descr">Использовать интернет для расчета маршрута</string>

View file

@ -1,5 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="poi">POI</string>
<string name="error_occurred_saving_gpx">Error occurred while saving gpx</string>
<string name="error_calculating_route">Error calculating route : </string>
<string name="error_calculating_route_occured">Error occurred while calculating route</string>
<string name="empty_route_calculated">Empty route is calculated</string>
<string name="new_route_calculated_dist">New route is calculated, distance :</string>
<string name="arrived_at_destination">You arrived at destination point</string>
<string name="invalid_locations">Locations are invalid</string>
<string name="go_back_to_osmand">Go back to OsmAnd map</string>
<string name="close">Close</string>
<string name="loading_data">Loading data</string>
<string name="reading_indexes">Reading indices...</string>
<string name="previous_run_crashed">Previous application run was crashed. Log file is at {0}. Please raise the issue and attach log file.</string>
<string name="saving_gpx_tracks">Saving gpx tracks to SD...</string>
<string name="finished_task">Finished : </string>
<string name="reload_indexes_descr">Reload data indexes from SD</string> <string name="reload_indexes_descr">Reload data indexes from SD</string>
<string name="reload_indexes">Reload indexes</string> <string name="reload_indexes">Reload indexes</string>
<string name="use_online_routing_descr">Use internet to calculate route</string> <string name="use_online_routing_descr">Use internet to calculate route</string>

View file

@ -78,9 +78,9 @@ public class PoiFilter {
public String getSearchArea(){ public String getSearchArea(){
if(zoom <= 14){ if(zoom <= 14){
int d = (int) (1 * (1 << (14 - zoom))); int d = (int) (1 * (1 << (14 - zoom)));
return " < " + d + " km"; return " < " + d + " " + Messages.getMessage(Messages.KEY_KM); //$NON-NLS-1$//$NON-NLS-2$
} else { } else {
return " < 500 m"; return " < 500 " + Messages.getMessage(Messages.KEY_M); //$NON-NLS-1$
} }
} }

View file

@ -1,6 +1,7 @@
package com.osmand; package com.osmand;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
@ -15,8 +16,10 @@ public class ProgressDialogImplementation implements IProgress {
private Handler mViewUpdateHandler; private Handler mViewUpdateHandler;
private Thread run; private Thread run;
private Context context;
public ProgressDialogImplementation(final ProgressDialog dlg){ public ProgressDialogImplementation(final ProgressDialog dlg){
context = dlg.getContext();
mViewUpdateHandler = new Handler(){ mViewUpdateHandler = new Handler(){
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
@ -87,7 +90,7 @@ public class ProgressDialogImplementation implements IProgress {
@Override @Override
public void finishTask() { public void finishTask() {
if (taskName != null) { if (taskName != null) {
message = "Finished : " + taskName; message = context.getResources().getString(R.string.finished_task) + taskName;
mViewUpdateHandler.sendEmptyMessage(0); mViewUpdateHandler.sendEmptyMessage(0);
} }
work = -1; work = -1;

View file

@ -192,12 +192,13 @@ public class ResourceManager {
for (File f : file.listFiles()) { for (File f : file.listFiles()) {
if (f.getName().endsWith(IndexConstants.POI_INDEX_EXT)) { if (f.getName().endsWith(IndexConstants.POI_INDEX_EXT)) {
AmenityIndexRepository repository = new AmenityIndexRepository(); 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); boolean initialized = repository.initialize(progress, f);
if (initialized) { if (initialized) {
amenityRepositories.add(repository); amenityRepositories.add(repository);
}else { }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()) { for (File f : file.listFiles()) {
if (f.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT)) { if (f.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT)) {
RegionAddressRepository repository = new RegionAddressRepository(); 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); boolean initialized = repository.initialize(progress, f);
if (initialized) { if (initialized) {
addressMap.put(repository.getName(), repository); addressMap.put(repository.getName(), repository);
} else { } 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$
} }
} }
} }

View file

@ -49,7 +49,8 @@ public class MainMenuActivity extends Activity {
public void startApplication(){ public void startApplication(){
if(!applicationAlreadyStarted){ 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); final ProgressDialogImplementation impl = new ProgressDialogImplementation(dlg);
impl.setRunnable("Initializing app", new Runnable(){ //$NON-NLS-1$ impl.setRunnable("Initializing app", new Runnable(){ //$NON-NLS-1$
@Override @Override
@ -58,7 +59,7 @@ public class MainMenuActivity extends Activity {
List<String> warnings = ResourceManager.getResourceManager().reloadIndexes(impl); List<String> warnings = ResourceManager.getResourceManager().reloadIndexes(impl);
SavingTrackHelper helper = new SavingTrackHelper(MainMenuActivity.this); SavingTrackHelper helper = new SavingTrackHelper(MainMenuActivity.this);
if (helper.hasDataToSave()) { if (helper.hasDataToSave()) {
impl.startTask("Saving gpx tracks to SD...", -1); impl.startTask(getString(R.string.saving_gpx_tracks), -1);
helper.saveDataToGpx(); helper.saveDataToGpx();
} }
helper.close(); helper.close();
@ -77,10 +78,10 @@ public class MainMenuActivity extends Activity {
File file = new File(Environment.getExternalStorageDirectory(), EXCEPTION_PATH); File file = new File(Environment.getExternalStorageDirectory(), EXCEPTION_PATH);
if(file.exists() && file.length() > 0){ if(file.exists() && file.length() > 0){
if(size != file.length()){ 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); EXCEPTION_PATH);
Builder builder = new AlertDialog.Builder(MainMenuActivity.this); 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(); getPreferences(MODE_WORLD_READABLE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit();
} }

View file

@ -97,7 +97,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
Notification notification = new Notification(R.drawable.icon, "", //$NON-NLS-1$ Notification notification = new Notification(R.drawable.icon, "", //$NON-NLS-1$
System.currentTimeMillis()); System.currentTimeMillis());
notification.setLatestEventInfo(this, Version.APP_NAME, 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, this.getBaseContext(), 0, notificationIndent,
PendingIntent.FLAG_UPDATE_CURRENT)); PendingIntent.FLAG_UPDATE_CURRENT));
return notification; return notification;

View file

@ -92,7 +92,7 @@ public class NavigatePointActivity extends Activity {
((TextView)findViewById(R.id.LatitudeEdit)).setText(convert(lat, newFormat)); ((TextView)findViewById(R.id.LatitudeEdit)).setText(convert(lat, newFormat));
((TextView)findViewById(R.id.LongitudeEdit)).setText(convert(lon, newFormat)); ((TextView)findViewById(R.id.LongitudeEdit)).setText(convert(lon, newFormat));
} catch (RuntimeException e) { } 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$ Log.w(LogUtil.TAG, "Convertion failed", e); //$NON-NLS-1$
} }
} }
@ -132,7 +132,7 @@ public class NavigatePointActivity extends Activity {
} }
close(); close();
} catch (RuntimeException e) { } 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$ Log.w(LogUtil.TAG, "Convertion failed", e); //$NON-NLS-1$
} }
} }

View file

@ -22,6 +22,7 @@ import android.util.FloatMath;
import android.widget.Toast; import android.widget.Toast;
import com.osmand.LogUtil; import com.osmand.LogUtil;
import com.osmand.R;
import com.osmand.OsmandSettings.ApplicationMode; import com.osmand.OsmandSettings.ApplicationMode;
import com.osmand.osm.LatLon; import com.osmand.osm.LatLon;
import com.osmand.osm.MapUtils; import com.osmand.osm.MapUtils;
@ -94,7 +95,7 @@ public class RoutingHelper {
if(currentRoute > routeNodes.size() - 3 && currentLocation.distanceTo(lastPoint) < 60){ if(currentRoute > routeNodes.size() - 3 && currentLocation.distanceTo(lastPoint) < 60){
if(lastFixedLocation != null && lastFixedLocation.distanceTo(lastPoint) < 60){ if(lastFixedLocation != null && lastFixedLocation.distanceTo(lastPoint) < 60){
// TODO mark as finished // TODO mark as finished
showMessage("You arrived at destination point"); showMessage(activity.getString(R.string.arrived_at_destination));
currentRoute = routeNodes.size() - 1; currentRoute = routeNodes.size() - 1;
} }
lastFixedLocation = currentLocation; lastFixedLocation = currentLocation;
@ -241,16 +242,16 @@ public class RoutingHelper {
currentRunningJob = null; currentRunningJob = null;
} }
if(res.isCalculated()){ 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 // be aware that is non ui thread
activity.getMapView().refreshMap(); activity.getMapView().refreshMap();
} else { } else {
if(res.errorMessage != null){ 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){ } else if(res.list == null){
showMessage("Error occurred while calculating route"); showMessage(activity.getString(R.string.error_calculating_route_occured));
} else { } else {
showMessage("Empty route is calculated"); showMessage(activity.getString(R.string.empty_route_calculated));
} }
} }
lastTimeEvaluatedRoute = System.currentTimeMillis(); lastTimeEvaluatedRoute = System.currentTimeMillis();

View file

@ -24,6 +24,7 @@ import android.widget.Toast;
import com.osmand.LogUtil; import com.osmand.LogUtil;
import com.osmand.OsmandSettings; import com.osmand.OsmandSettings;
import com.osmand.R;
import com.osmand.Version; import com.osmand.Version;
public class SavingTrackHelper extends SQLiteOpenHelper { public class SavingTrackHelper extends SQLiteOpenHelper {
@ -126,10 +127,10 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
log.error("Error saving gpx", e); //$NON-NLS-1$ 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) { } catch (IOException e) {
log.error("Error saving gpx", e); //$NON-NLS-1$ 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);
} }
} }

View file

@ -224,7 +224,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
} }
public void reloadIndexes(){ 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); final ProgressDialogImplementation impl = new ProgressDialogImplementation(dlg);
impl.setRunnable("Initializing app", new Runnable(){ //$NON-NLS-1$ impl.setRunnable("Initializing app", new Runnable(){ //$NON-NLS-1$
@Override @Override

View file

@ -24,9 +24,9 @@ public class SearchActivity extends TabActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
TabHost host = getTabHost(); 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_POI").setIndicator(getString(R.string.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_Address").setIndicator(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_Location").setIndicator(getString(R.string.search_tabs_location)).setContent(new Intent(this, NavigatePointActivity.class))); //$NON-NLS-1$
} }
} }