Added script again

removing duplicate code by improving the interface
This commit is contained in:
Sander Deryckere 2012-08-15 11:01:02 +02:00
parent 9919a98023
commit 2aa87f74cc
3 changed files with 62 additions and 21 deletions

37
OsmAnd/scripts/generate.sh Executable file
View file

@ -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/automatedJavaGenarationFile2.txt > /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

View file

@ -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);

View file

@ -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<String,String>();
// 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();
}
}