Extract TextSecure strings for i18n.

1) Change all instances which use concatenation to build strings
with variables in them to use string formatting instead.

2) Extract all string literals from layouts and menus into strings.xml

3) Extract all string literals from code into strings.xml
This commit is contained in:
Moxie Marlinspike
2012-09-07 20:03:23 -07:00
parent 45c058b46d
commit 4c3b7cbe08
89 changed files with 1228 additions and 1205 deletions

View File

@@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2011 Whisper Systems
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -10,12 +10,20 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.thoughtcrime.securesms;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import org.thoughtcrime.securesms.crypto.IdentityKey;
import org.thoughtcrime.securesms.crypto.InvalidKeyException;
import org.thoughtcrime.securesms.crypto.InvalidVersionException;
@@ -26,17 +34,9 @@ import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.MemoryCleaner;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
/**
* Activity for displaying sent/received session keys.
*
*
* @author Moxie Marlinspike
*/
@@ -44,26 +44,26 @@ public class ReceiveKeyActivity extends Activity {
private TextView descriptionText;
private TextView signatureText;
private Button confirmButton;
private Button cancelButton;
private Button verifySessionButton;
private Button verifyIdentityButton;
private Recipient recipient;
private long threadId;
private MasterSecret masterSecret;
private KeyExchangeMessage keyExchangeMessage;
private KeyExchangeProcessor keyExchangeProcessor;
private boolean sent;
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.receive_key_activity);
initializeResources();
try {
initializeKey();
@@ -76,110 +76,100 @@ public class ReceiveKeyActivity extends Activity {
}
initializeListeners();
}
@Override
protected void onDestroy() {
MemoryCleaner.clean(masterSecret);
super.onDestroy();
}
private void initializeText() {
if (keyExchangeProcessor.hasCompletedSession()) initializeTextForExistingSession();
else initializeTextForNewSession();
initializeSignatureText();
}
private void initializeCorruptedKeyText() {
descriptionText.setText("ERROR:\n\nYou have received a corrupted public key. This key can not be processed, please re-initiate a secure session.");
descriptionText.setText(R.string.error_you_have_received_a_corrupted_public_key);
confirmButton.setVisibility(View.GONE);
}
private void initializeBadVersionText() {
descriptionText.setText("ERROR:\n\nYou have received a public key from an unsupported version of the protocol. This key can not be processed, please re-initiate a secure session.");
confirmButton.setVisibility(View.GONE);
descriptionText.setText(R.string.error_you_have_received_a_public_key_from_an_unsupported_version_of_the_protocol);
confirmButton.setVisibility(View.GONE);
}
private void initializeSignatureText() {
if (!keyExchangeMessage.hasIdentityKey()) {
signatureText.setText("This key exchange message does not include an identity signature.");
signatureText.setText(R.string.this_key_exchange_message_does_not_include_an_identity_signature);
return;
}
IdentityKey identityKey = keyExchangeMessage.getIdentityKey();
String identityName = DatabaseFactory.getIdentityDatabase(this).getNameForIdentity(masterSecret, identityKey);
if (identityName == null) {
signatureText.setText("This key exchange message includes an identity signature, but you do not yet trust it.");
signatureText.setText(R.string.this_key_exchange_message_includes_an_identity_signature_but_you_do_not_yet_trust_it);
} else {
signatureText.setText("This key exchange message includes an identity signature which you trust for: " + identityName);
signatureText.setText(String.format(getString(R.string.this_key_exchange_message_includes_an_identity_signature_which_you_trust_for_s), identityName));
}
}
private void initializeTextForExistingSession() {
if (keyExchangeProcessor.isRemoteKeyExchangeForExistingSession(keyExchangeMessage)) {
descriptionText.setText("This is the key that you sent to start your current encrypted session with " + recipient.toShortString());
descriptionText.setText(String.format(getString(R.string.this_is_the_key_that_you_sent_to_start_your_current_encrypted_session_with_s), recipient.toShortString()));
this.confirmButton.setVisibility(View.GONE);
this.verifySessionButton.setVisibility(View.VISIBLE);
this.verifyIdentityButton.setVisibility(View.VISIBLE);
} else if (keyExchangeProcessor.isLocalKeyExchangeForExistingSession(keyExchangeMessage)) {
descriptionText.setText("This is the key that you received to start your current encrypted session with " + recipient.toShortString());
descriptionText.setText(String.format(getString(R.string.this_is_the_key_that_you_received_to_start_your_current_encrypted_session_with_s), recipient.toShortString()));
this.confirmButton.setVisibility(View.GONE);
this.verifySessionButton.setVisibility(View.VISIBLE);
this.verifyIdentityButton.setVisibility(View.VISIBLE);
} else {
descriptionText.setText("You have received a Key Exchange message from " + recipient.toShortString() + "." +
"\n\nWARNING: You already have an encrypted session with this contact." +
" If you choose to accept this key exchange message, it will destroy your " +
"existing session and you will have to re-authenticate. Would you like to complete " +
"this key exchange?");
descriptionText.setText(String.format(getString(R.string.you_have_received_a_key_exchange_message_from_s_warning_you_already_have_an_encrypted_session), recipient.toShortString()));
this.confirmButton.setVisibility(View.VISIBLE);
this.verifyIdentityButton.setVisibility(View.GONE);
this.verifySessionButton.setVisibility(View.GONE);
}
}
}
private void initializeTextForNewSession() {
if (keyExchangeProcessor.hasInitiatedSession() && !this.sent)
descriptionText.setText("You have received a Key Exchange message from " + recipient.toShortString() +
". You have previously initiated a session with this contact, " +
"and by accepting this key you will complete the key exchange. " +
"Would you like to complete this key exchange?");
descriptionText.setText(String.format(getString(R.string.you_have_received_a_key_exchange_message_from_s_you_have_previously_initiated), recipient.toShortString()));
else if (keyExchangeProcessor.hasInitiatedSession() && this.sent)
descriptionText.setText("You have initiated a Key Exchange message with " + recipient.toShortString() +
" but have not yet received a reply.");
descriptionText.setText(String.format(getString(R.string.you_have_initiated_a_key_exchange_message_with_s_but_have_not_yet_received_a_reply), recipient.toShortString()));
else if (!keyExchangeProcessor.hasInitiatedSession() && !this.sent)
descriptionText.setText("You have received a Key Exchange message from " + recipient.toShortString() +
". You have no existing session with this contact, would you like " +
"to complete this key exchange?");
descriptionText.setText(String.format(getString(R.string.you_have_received_a_key_exchange_message_from_s_you_have_no_existing_session), recipient.toShortString()));
}
private void initializeKey() throws InvalidKeyException, InvalidVersionException {
String messageBody = getIntent().getStringExtra("body");
this.keyExchangeMessage = new KeyExchangeMessage(messageBody);
}
private void initializeResources() {
this.descriptionText = (TextView) findViewById(R.id.description_text);
this.signatureText = (TextView) findViewById(R.id.signature_text);
this.confirmButton = (Button) findViewById(R.id.ok_button);
this.cancelButton = (Button) findViewById(R.id.cancel_button);
this.verifyIdentityButton = (Button)findViewById(R.id.verify_identity_button);
this.verifySessionButton = (Button)findViewById(R.id.verify_session_button);
this.verifyIdentityButton = (Button) findViewById(R.id.verify_identity_button);
this.verifySessionButton = (Button) findViewById(R.id.verify_session_button);
this.recipient = getIntent().getParcelableExtra("recipient");
this.threadId = getIntent().getLongExtra("thread_id", -1);
this.masterSecret = (MasterSecret)getIntent().getParcelableExtra("master_secret");
this.sent = getIntent().getBooleanExtra("sent", false);
this.keyExchangeProcessor = new KeyExchangeProcessor(this, masterSecret, recipient);
}
private void initializeListeners() {
this.confirmButton.setOnClickListener(new OkListener());
this.cancelButton.setOnClickListener(new CancelListener());
this.verifyIdentityButton.setOnClickListener(new VerifyIdentityListener());
this.verifySessionButton.setOnClickListener(new VerifySessionListener());
}
private class VerifyIdentityListener implements View.OnClickListener {
public void onClick(View v) {
Intent intent = new Intent(ReceiveKeyActivity.this, VerifyIdentityActivity.class);
@@ -189,7 +179,7 @@ public class ReceiveKeyActivity extends Activity {
finish();
}
}
private class VerifySessionListener implements View.OnClickListener {
public void onClick(View v) {
Intent intent = new Intent(ReceiveKeyActivity.this, VerifyKeysActivity.class);
@@ -199,14 +189,14 @@ public class ReceiveKeyActivity extends Activity {
finish();
}
}
private class OkListener implements View.OnClickListener {
public void onClick(View v) {
keyExchangeProcessor.processKeyExchangeMessage(keyExchangeMessage, threadId);
keyExchangeProcessor.processKeyExchangeMessage(keyExchangeMessage, threadId);
finish();
}
}
private class CancelListener implements View.OnClickListener {
public void onClick(View v) {
ReceiveKeyActivity.this.finish();