mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-11 08:48:06 +01:00
new type of problem: make a string array in ListPreference localizable
This commit is contained in:
parent
589b740af6
commit
073c461693
3 changed files with 43 additions and 8 deletions
|
@ -287,10 +287,10 @@
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="game_summary_values">
|
<string-array name="game_summary_values">
|
||||||
<item>@string/game_summary_field_empty</item>
|
<item>loc:game_summary_field_empty</item>
|
||||||
<item>@string/game_summary_field_language</item>
|
<item>loc:game_summary_field_language</item>
|
||||||
<item>@string/game_summary_field_opponents</item>
|
<item>loc:game_summary_field_opponents</item>
|
||||||
<item>@string/game_summary_field_state</item>
|
<item>loc:game_summary_field_state</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="confirm_sms_reasons">
|
<string-array name="confirm_sms_reasons">
|
||||||
|
|
|
@ -23,6 +23,11 @@ package org.eehouse.android.xw4;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.eehouse.android.xw4.loc.LocUtils;
|
||||||
|
|
||||||
|
|
||||||
public class XWSumListPreference extends XWListPreference {
|
public class XWSumListPreference extends XWListPreference {
|
||||||
|
|
||||||
private static final int[] s_ADDROWS = {
|
private static final int[] s_ADDROWS = {
|
||||||
|
@ -37,25 +42,32 @@ public class XWSumListPreference extends XWListPreference {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Why I exist: insert the rowid and gameid lines if debug is on
|
// Why I exist: insert the rowid and gameid lines if debug is on
|
||||||
|
@Override
|
||||||
protected void onAttachedToActivity()
|
protected void onAttachedToActivity()
|
||||||
{
|
{
|
||||||
super.onAttachedToActivity();
|
super.onAttachedToActivity();
|
||||||
|
|
||||||
|
CharSequence[] entries = getEntries();
|
||||||
|
CharSequence[] newEntries = LocUtils.xlateStrings( m_context, entries );
|
||||||
|
if ( ! newEntries.equals( entries ) ) {
|
||||||
|
setEntries( newEntries );
|
||||||
|
setEntryValues( newEntries );
|
||||||
|
}
|
||||||
|
|
||||||
if ( BuildConfig.DEBUG || XWPrefs.getDebugEnabled( m_context ) ) {
|
if ( BuildConfig.DEBUG || XWPrefs.getDebugEnabled( m_context ) ) {
|
||||||
CharSequence[] entries = getEntries();
|
entries = getEntries();
|
||||||
CharSequence lastRow = entries[entries.length - 1];
|
CharSequence lastRow = entries[entries.length - 1];
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
|
|
||||||
String[] addRows = new String[s_ADDROWS.length];
|
String[] addRows = new String[s_ADDROWS.length];
|
||||||
for ( int ii = 0; !done && ii < s_ADDROWS.length; ++ii ) {
|
for ( int ii = 0; !done && ii < s_ADDROWS.length; ++ii ) {
|
||||||
String addRow = m_context.getString( s_ADDROWS[ii] );
|
String addRow = LocUtils.getString( m_context, s_ADDROWS[ii] );
|
||||||
done = lastRow.equals( addRow );
|
done = lastRow.equals( addRow );
|
||||||
addRows[ii] = addRow;
|
addRows[ii] = addRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !done ) {
|
if ( !done ) {
|
||||||
CharSequence[] newEntries =
|
newEntries = new CharSequence[entries.length + addRows.length];
|
||||||
new CharSequence[entries.length + addRows.length];
|
|
||||||
System.arraycopy( entries, 0, newEntries, 0,
|
System.arraycopy( entries, 0, newEntries, 0,
|
||||||
entries.length );
|
entries.length );
|
||||||
System.arraycopy( addRows, 0, newEntries, entries.length,
|
System.arraycopy( addRows, 0, newEntries, entries.length,
|
||||||
|
|
|
@ -82,6 +82,29 @@ public class LocUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String xlateString( Context context, String str )
|
||||||
|
{
|
||||||
|
if ( str.startsWith( LOC_PREFIX ) ) {
|
||||||
|
str = str.substring( LOC_PREFIX.length() );
|
||||||
|
int id = LocIDs.getID( str );
|
||||||
|
if ( LocIDs.NOT_FOUND != id ) {
|
||||||
|
str = getString( context, id );
|
||||||
|
} else {
|
||||||
|
DbgUtils.logf( "nothing for %s", str );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CharSequence[] xlateStrings( Context context, CharSequence[] strs )
|
||||||
|
{
|
||||||
|
CharSequence[] result = new CharSequence[strs.length];
|
||||||
|
for ( int ii = 0; ii < strs.length; ++ii ) {
|
||||||
|
result[ii] = xlateString( context, strs[ii].toString() );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getString( Context context, int id )
|
public static String getString( Context context, int id )
|
||||||
{
|
{
|
||||||
String str = context.getString( id );
|
String str = context.getString( id );
|
||||||
|
|
Loading…
Add table
Reference in a new issue