save edited translations

This commit is contained in:
Eric House 2014-05-14 06:46:08 -07:00
parent 3040003126
commit d00e49f843
3 changed files with 53 additions and 15 deletions

View file

@ -19,10 +19,11 @@
package org.eehouse.android.xw4.loc;
import android.content.Intent;
import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import org.eehouse.android.xw4.DelegateBase;
@ -32,6 +33,8 @@ public class LocItemEditDelegate extends DelegateBase {
private static final String KEY = "KEY";
private Activity m_activity;
private String m_key;
private EditText m_edit;
protected LocItemEditDelegate( Activity activity, Bundle savedInstanceState )
{
@ -44,16 +47,32 @@ public class LocItemEditDelegate extends DelegateBase {
setContentView( R.layout.loc_item_edit );
String key = getIntent().getStringExtra( KEY );
m_key = key;
TextView view = (TextView)findViewById( R.id.english_view );
view.setText( key );
view = (TextView)findViewById( R.id.xlated_view_blessed );
view.setText( LocUtils.getXlation( m_activity, true, key ) );
view.setText( LocUtils.getXlation( m_activity, key, false, true ) );
m_edit = (EditText)findViewById( R.id.xlated_view_local );
m_edit.setText( LocUtils.getXlation( m_activity, key, true, true ) );
setLabel( R.id.english_label, R.string.loc_main_english );
setLabel( R.id.blessed_label, R.string.loc_main_yourlang );
setLabel( R.id.local_label, R.string.loc_main_yourlang );
}
@Override
protected void onPause()
{
// Save any local translation
CharSequence txt = m_edit.getText();
if ( null != txt && 0 < txt.length() ) {
LocUtils.setXlation( m_activity, m_key, txt.toString() );
}
super.onPause();
}
private void setLabel( int viewID, int strID )
{
TextView view = (TextView)findViewById( viewID );

View file

@ -63,7 +63,7 @@ public class LocListItem extends LinearLayout
private void setXlated()
{
m_xlation = LocUtils.getXlation( getContext(), true, m_pair.getKey() );
m_xlation = LocUtils.getXlation( getContext(), m_pair.getKey(), true );
if ( null != m_xlation ) {
m_pair.setXlation( m_xlation );
m_xlated.setText( m_xlation );

View file

@ -155,7 +155,7 @@ public class LocUtils {
public static String xlateString( Context context, String str )
{
if ( LocIDs.getS_MAP( context ).containsKey( str ) ) {
String xlation = getXlation( context, true, str );
String xlation = getXlation( context, str, true );
if ( null != xlation ) {
str = xlation;
}
@ -198,7 +198,7 @@ public class LocUtils {
String result = null;
String key = keyForID( context, id );
if ( null != key ) {
result = getXlation( context, canUseDB, key );
result = getXlation( context, key, canUseDB );
}
if ( null == result ) {
@ -229,19 +229,38 @@ public class LocUtils {
s_xlationsLocal.put( key, txt );
}
public static String getXlation( Context context, boolean canUseDB,
String key )
protected static String getXlation( Context context, String key,
boolean canUseDB )
{
return getXlation( context, key, null, canUseDB );
}
protected static String getXlation( Context context, String key,
boolean forceLocal, boolean canUseDB )
{
return getXlation( context, key, new Boolean(forceLocal), canUseDB );
}
private static String getXlation( Context context, String key,
Boolean forceLocal, boolean canUseDB )
{
if ( canUseDB ) {
loadXlations( context );
}
String result = null;
if ( null != s_xlationsLocal ) {
result = s_xlationsLocal.get( key );
if ( null == forceLocal || forceLocal ) {
if ( null != s_xlationsLocal ) {
result = s_xlationsLocal.get( key );
}
}
if ( null == result && null != s_xlationsBlessed ) {
result = s_xlationsBlessed.get( key );
if ( null == forceLocal || !forceLocal ) {
if ( null == result && null != s_xlationsBlessed ) {
result = s_xlationsBlessed.get( key );
}
}
if ( UPPER_CASE && null == result ) {
result = toUpperCase( key );
}
@ -340,7 +359,7 @@ public class LocUtils {
String key = iter.next();
String english = context.getString( map.get( key ) );
Assert.assertTrue( english.equals( key ) );
String xlation = getXlation( context, true, key );
String xlation = getXlation( context, key, true );
result[ii] = new LocSearcher.Pair( key, english, xlation );
}
return result;
@ -396,8 +415,8 @@ public class LocUtils {
private static void loadXlations( Context context )
{
if ( null == s_xlationsLocal || null == s_xlationsBlessed ) {
Object[] asObjs = DBUtils.getXlations( context,
getCurLocale( context ) );
Object[] asObjs =
DBUtils.getXlations( context, getCurLocale( context ) );
s_xlationsLocal = (Map<String,String>)asObjs[0];
s_xlationsBlessed = (Map<String,String>)asObjs[1];
DbgUtils.logf( "loadXlations: got %d local strings, %d blessed strings",