From 2aa87f74ccee503ba29c1fe8f627a0c9ffadef4f Mon Sep 17 00:00:00 2001 From: Sander Deryckere Date: Wed, 15 Aug 2012 11:01:02 +0200 Subject: [PATCH] Added script again removing duplicate code by improving the interface --- OsmAnd/scripts/generate.sh | 37 +++++++++++++++++++ .../net/osmand/plus/OsmandApplication.java | 23 ++++-------- .../src/net/osmand/plus/SpecialPhrases.java | 23 +++++++++--- 3 files changed, 62 insertions(+), 21 deletions(-) create mode 100755 OsmAnd/scripts/generate.sh diff --git a/OsmAnd/scripts/generate.sh b/OsmAnd/scripts/generate.sh new file mode 100755 index 0000000000..da9af5e351 --- /dev/null +++ b/OsmAnd/scripts/generate.sh @@ -0,0 +1,37 @@ +#! /bin/bash + +pages=('AF' 'AR' 'BR' 'CA' 'CS' 'DE' 'EN' 'ES' 'ET' 'EU' 'FA' 'FI' 'FR' 'GL' 'HR' 'HU' 'IA' 'IS' 'IT' 'JA' 'MK' 'NL' 'NO' 'PL' 'PS' 'PT' 'RU' 'SK' 'SV' 'UK' 'VI') + +# declare -a pages=('AF' 'AR' 'BR' 'CA' 'CS' 'DE' 'EN' 'ES' 'ET' 'EU' 'FA' 'FI' 'FR' 'GL' 'HR' 'HU' 'IA' 'IS' 'IT' 'JA' 'MK' 'NL' 'NO' 'PL' 'PS' 'PT' 'RU' 'SK' 'SV' 'UK' 'VI') + + + +for lang in ${pages[@]} +do + wget http://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/${lang} -O /tmp/automatedJavaGenarationFile.txt + + cat /tmp/automatedJavaGenarationFile.txt | grep " - " | grep " N" > /tmp/automatedJavaGenarationFile2.txt + + sed -e 's/ *|/|/g' -e 's/| */|/g' /tmp/automatedJavaGenarationFile.txt + + file="../assets/specialphrases/specialphrases_${lang,,}.txt" + + echo "" > $file + + while read line; do + + IFS="||" + arr=( $line ) + + + + echo ${arr[5]}','${arr[1]} >> $file + + done < /tmp/automatedJavaGenarationFile.txt + +done + + +rm /tmp/automatedJavaGenarationFile.txt +rm /tmp/automatedJavaGenarationFile2.txt + diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 9a6213cc77..b443c8bf44 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -249,23 +249,14 @@ public class OsmandApplication extends Application { startApplication(); synchronized (OsmandApplication.this) { if (startDialog != null) { - if (osmandSettings.usingEnglishNames()) { - try { - SpecialPhrases.setLanguage(this, new Locale("en")); - } catch (IOException e) { - LOG.error("I/O exception", e); - Toast error = Toast.makeText(this, "Error while reading the special phrases. Restart OsmAnd if possible", Toast.LENGTH_LONG); - error.show(); - } - } else { - try { - SpecialPhrases.setLanguage(this, Locale.getDefault()); - } catch (IOException e) { - LOG.error("I/O exception", e); - Toast error = Toast.makeText(this, "Error while reading the special phrases. Restart OsmAnd if possible", Toast.LENGTH_LONG); - error.show(); - } + try { + SpecialPhrases.setLanguage(this, osmandSettings); + } catch (IOException e) { + LOG.error("I/O exception", e); + Toast error = Toast.makeText(this, "Error while reading the special phrases. Restart OsmAnd if possible", Toast.LENGTH_LONG); + error.show(); } + progressDialog.setTitle(getString(R.string.loading_data)); progressDialog.setMessage(getString(R.string.reading_indexes)); activity.showDialog(PROGRESS_DIALOG); diff --git a/OsmAnd/src/net/osmand/plus/SpecialPhrases.java b/OsmAnd/src/net/osmand/plus/SpecialPhrases.java index 1aa2b61832..d70d1bc5f7 100644 --- a/OsmAnd/src/net/osmand/plus/SpecialPhrases.java +++ b/OsmAnd/src/net/osmand/plus/SpecialPhrases.java @@ -27,10 +27,10 @@ public class SpecialPhrases { /** * Use this method to query a special phrase for a certain subtype * - * If the language isn't set yet, it will default to English + * If the language isn't set yet, a nullpointer exception will be thrown * * @param key the subtype to query - * @return the special phrase according to the asked key + * @return the special phrase according to the asked key, or "null" if the key isn't found */ public static String getSpecialPhrase(String key){ if (!isLanguageSet()) { @@ -46,12 +46,13 @@ public class SpecialPhrases { * @param lang the language to use * @throws IOException when reading the text file failed */ - public static void setLanguage(Context ctx, Locale lang) throws IOException { + public static void setLanguage(Context ctx, OsmandSettings settings) throws IOException { + String lang = getPreferredLanguage(settings).getLanguage(); m = new HashMap(); // The InputStream opens the resourceId and sends it to the buffer InputStream is = null; try { - is = ctx.getAssets().open("specialphrases/specialphrases_"+lang.getLanguage()+".txt"); + is = ctx.getAssets().open("specialphrases/specialphrases_"+lang+".txt"); } catch (IOException ex) { // second try: default to English, if this fails, the error is thrown outside is = ctx.getAssets().open("specialphrases/specialphrases_en.txt"); @@ -64,7 +65,6 @@ public class SpecialPhrases { String[] arr = readLine.split(","); if (arr != null && arr.length == 2) { m.put(arr[0], arr[1]); - System.out.println(arr[0]+" x "+arr[1]); } } @@ -76,6 +76,19 @@ public class SpecialPhrases { } + /** + * Returns the preferred language + * @param set the OsmandSettings used + * @return Locale("en") if English names are chosen in the settings, Locale.getDefault otherwise + */ + public static Locale getPreferredLanguage(OsmandSettings set){ + if (set.usingEnglishNames()) { + return new Locale("en"); + } + return Locale.getDefault(); + + } + }