From 3b53d05746e55fd2ef285142230e4eade1a8fcca Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 24 Mar 2015 07:36:11 -0700 Subject: [PATCH] translate language names downloaded as part of dict info. --- .../eehouse/android/xw4/DictsDelegate.java | 30 ++++++++-------- .../org/eehouse/android/xw4/loc/LocUtils.java | 35 +++++++++++++++++-- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java index c3474c87c..52b455af1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java @@ -64,10 +64,11 @@ import java.util.Iterator; import junit.framework.Assert; -import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DictUtils.DictAndLoc; -import org.eehouse.android.xw4.jni.GameSummary; import org.eehouse.android.xw4.DictUtils.DictLoc; +import org.eehouse.android.xw4.DlgDelegate.Action; +import org.eehouse.android.xw4.jni.GameSummary; +import org.eehouse.android.xw4.loc.LocUtils; public class DictsDelegate extends ListDelegateBase implements View.OnClickListener, AdapterView.OnItemLongClickListener, @@ -108,16 +109,17 @@ public class DictsDelegate extends ListDelegateBase private static class DictInfo implements Comparable { public String m_name; - // public boolean m_needsUpdate; public String m_lang; + public String m_langLoc; public int m_nWords; public long m_nBytes; public String m_note; - public DictInfo( String name, String lang, int nWords, long nBytes, - String note ) + public DictInfo( String name, String lang, String langLoc, int nWords, + long nBytes, String note ) { m_name = name; m_lang = lang; + m_langLoc = langLoc; m_nWords = nWords; m_nBytes = nBytes; m_note = note; @@ -136,7 +138,6 @@ public class DictsDelegate extends ListDelegateBase m_numDicts = numDicts; } } - private HashMap m_localInfo; private HashMap m_remoteInfo; private boolean m_launchedForMissing = false; @@ -1174,14 +1175,15 @@ public class DictsDelegate extends ListDelegateBase for ( int ii = 0; !isCancelled() && ii < nLangs; ++ii ) { JSONObject langObj = langs.getJSONObject( ii ); String langName = langObj.getString( "lang" ); + String locLangName = LocUtils.xlateLang( m_context, langName ); if ( null != m_filterLang && - ! m_filterLang.equals( langName ) ) { + ! m_filterLang.equals( locLangName ) ) { continue; } - if ( ! curLangs.contains( langName ) ) { - closedLangs.add( langName ); + if ( ! curLangs.contains( locLangName ) ) { + closedLangs.add( locLangName ); } JSONArray dicts = langObj.getJSONArray( "dicts" ); @@ -1200,13 +1202,13 @@ public class DictsDelegate extends ListDelegateBase note = null; } DictInfo info = - new DictInfo( name, langName, nWords, nBytes, - note ); + new DictInfo( name, langName, locLangName, + nWords, nBytes, note ); if ( !m_quickFetchMode ) { // Check if we have it and it needs an update if ( DictLangCache.haveDict( m_activity, - langName, name )){ + locLangName, name )){ boolean matches = true; String curSum = DictLangCache .getDictMD5Sum( m_activity, name ); @@ -1237,7 +1239,7 @@ public class DictsDelegate extends ListDelegateBase DictInfo[] asArray = new DictInfo[dictNames.size()]; asArray = dictNames.toArray( asArray ); Arrays.sort( asArray ); - m_remoteInfo.put( langName, asArray ); + m_remoteInfo.put( locLangName, asArray ); } } @@ -1251,7 +1253,7 @@ public class DictsDelegate extends ListDelegateBase } return success; - } + } // digestData ///////////////////////////////////////////////////////////////// // DialogInterface.OnCancelListener interface diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocUtils.java index 49955b62b..b92b205dc 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/loc/LocUtils.java @@ -80,10 +80,11 @@ public class LocUtils { private static Boolean s_enabled = null; private static String s_curLocale; private static WeakReference s_latestMenuRef; - private static HashMap, HashSet > s_menuSets + private static Map, HashSet > s_menuSets = new HashMap, HashSet >(); - private static HashMap > s_contextSets + private static Map > s_contextSets = new HashMap >(); + private static Map s_langMap = null; public static void localeChanged( Context context, String newLocale ) { @@ -111,6 +112,36 @@ public class LocUtils { } } + public static String xlateLang( Context context, String lang ) + { + if ( null == s_langMap ) { + s_langMap = new HashMap(); + s_langMap.put( "English", context.getString( R.string.lang_name_english ) ); + s_langMap.put( "French", context.getString( R.string.lang_name_french ) ); + s_langMap.put( "German", context.getString( R.string.lang_name_german ) ); + s_langMap.put( "Turkish", context.getString( R.string.lang_name_turkish ) ); + s_langMap.put( "Arabic", context.getString( R.string.lang_name_arabic ) ); + s_langMap.put( "Spanish", context.getString( R.string.lang_name_spanish ) ); + s_langMap.put( "Swedish", context.getString( R.string.lang_name_swedish ) ); + s_langMap.put( "Polish", context.getString( R.string.lang_name_polish ) ); + s_langMap.put( "Danish", context.getString( R.string.lang_name_danish ) ); + s_langMap.put( "Italian", context.getString( R.string.lang_name_italian ) ); + s_langMap.put( "Dutch", context.getString( R.string.lang_name_dutch ) ); + s_langMap.put( "Catalan", context.getString( R.string.lang_name_catalan ) ); + s_langMap.put( "Portuguese", context.getString( R.string.lang_name_portuguese ) ); + s_langMap.put( "Russian", context.getString( R.string.lang_name_russian ) ); + s_langMap.put( "Czech", context.getString( R.string.lang_name_czech ) ); + s_langMap.put( "Greek", context.getString( R.string.lang_name_greek ) ); + s_langMap.put( "Slovak", context.getString( R.string.lang_name_slovak ) ); + } + + String xlated = s_langMap.get( lang ); + if ( null == xlated ) { + xlated = lang; + } + return xlated; + } + public static void xlateView( Activity activity ) { xlateView( activity, Utils.getContentView( activity ) );