when translations get out of sync with R.java values, there's often a

format exception.  Catch that, and strip out the locale's translations
so the app at least doesn't crash.  This should not happen once I have
the server side right, but it'll help now and provide a safety net
later.
This commit is contained in:
Eric House 2014-05-01 22:05:57 -07:00
parent 8d6f46fa22
commit 56a057f06c
2 changed files with 37 additions and 4 deletions

View file

@ -1821,6 +1821,19 @@ public class DBUtils {
return result;
}
public static void dropXLations( Context context, String locale )
{
String selection = String.format( "%s = '%s'", DBHelper.LOCALE,
locale );
initDB( context );
synchronized( s_dbHelper ) {
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
db.delete( DBHelper.TABLE_NAME_LOC, selection, null );
db.close();
}
}
public static void setStringFor( Context context, String key, String value )
{
String selection = String.format( "%s = '%s'", DBHelper.KEY, key );

View file

@ -25,6 +25,9 @@ import android.content.Context;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.res.Resources;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceGroup;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.Menu;
@ -36,12 +39,10 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.TextView;
import android.preference.Preference;
import android.preference.PreferenceGroup;
import android.preference.PreferenceActivity;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IllegalFormatConversionException;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@ -209,7 +210,12 @@ public class LocUtils {
Assert.assertNotNull( params );
String result = getString( context, id );
if ( null != result ) {
result = String.format( result, params );
try {
result = String.format( result, params );
} catch ( IllegalFormatConversionException fce ) {
dropXLations( context );
result = getString( context, id, params );
}
}
return result;
}
@ -495,6 +501,20 @@ public class LocUtils {
return result;
}
private static void dropXLations( Context context )
{
s_xlationsBlessed = null;
s_idsToKeys = null;
String locale = getCurLocale( context );
String msg = String.format( "Dropping bad translations for %s", locale );
Utils.showToast( context, msg );
DbgUtils.logf( msg );
DBUtils.dropXLations( context, locale );
DBUtils.setStringFor( context, localeKey(locale), "" );
}
private static Pattern s_patUnicode = Pattern.compile("(\\\\[Uu][0-9a-fA-F]{4})");
private static Pattern s_patCr = Pattern.compile("\\\\n");