merge in jb-release history after reset to jb-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 958a6c4..9313894 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -59,19 +59,30 @@
     <string name="enter">\u2193</string>
     <!-- Displayed on buttons on screen for the sin function. -->
     <string name="sin">sin</string>
+    <!-- Do not translate. What we replace translated SIN with for calculating sin.-->
+    <string translate="false" name="sin_mathematical_value">sin</string>
     <!-- Displayed on buttons on screen for the cos function. -->
     <string name="cos">cos</string>
+    <!-- Do not translate. What we replace translated COS with for calculating cos. -->
+    <string translate="false" name="cos_mathematical_value">cos</string>
     <!-- Displayed on buttons on screen for the tan function. -->
     <string name="tan">tan</string>
-       
+    <!-- Do not translate. What we replace translated TAN with for calculating tan. -->
+    <string translate="false" name="tan_mathematical_value">tan</string>
     <!-- Do not translate. Unicode pi sign; don't translate. Displayed as button on screen. -->
     <string name="pi">\u03c0</string>
     <!-- Displayed on buttons on screen for the e function. -->
     <string name="e">e</string>
+    <!-- Do not translate. What we replace translated e with for calculating e. -->
+    <string translate="false" name="e_mathematical_value">e</string>
     <!-- Displayed on buttons on screen for the ln function. -->
     <string name="ln">ln</string>
+    <!-- Do not translate. What we replace translated ln with for calculating ln. -->
+    <string translate="false" name="ln_mathematical_value">ln</string>
     <!-- Displayed on buttons on screen for the log function. -->
     <string name="lg">log</string>
+    <!-- Do not translate. What we replace translated lg with for calculating lg. -->
+    <string translate="false" name="lg_mathematical_value">lg</string>
     <!-- Displayed on buttons on screen for a left parenthesis. -->
     <string name="leftParen">(</string>
     <!-- Displayed on buttons on screen for a right parenthesis. -->
diff --git a/src/com/android/calculator2/Logic.java b/src/com/android/calculator2/Logic.java
index 690e892..a91090c 100644
--- a/src/com/android/calculator2/Logic.java
+++ b/src/com/android/calculator2/Logic.java
@@ -22,12 +22,15 @@
 import android.view.KeyEvent;
 import android.widget.EditText;
 import android.content.Context;
+import android.content.res.Resources;
 
+import java.util.HashMap;
 import java.util.Locale;
+import java.util.Map.Entry;
+import java.util.Set;
 
 import org.javia.arity.Symbols;
 import org.javia.arity.SyntaxException;
-import org.javia.arity.Util;
 
 class Logic {
     private CalculatorDisplay mDisplay;
@@ -60,9 +63,12 @@
     }
 
     private Listener mListener;
+    private Context mContext;
+    private Set<Entry<String, String>> mTranslationsSet;
 
     Logic(Context context, History history, CalculatorDisplay display) {
-        mErrorString = context.getResources().getString(R.string.error);
+        mContext = context;
+        mErrorString = mContext.getResources().getString(R.string.error);
         mHistory = history;
         mDisplay = display;
         mDisplay.setLogic(this);
@@ -230,7 +236,8 @@
             input = input.substring(0, size - 1);
             --size;
         }
-
+        // Find and replace any translated mathematical functions.
+        input = replaceTranslations(input);
         double value = mSymbols.eval(input);
 
         String result = "";
@@ -243,6 +250,32 @@
         return result.replace('-', MINUS).replace(INFINITY, INFINITY_UNICODE);
     }
 
+    private void addTranslation(HashMap<String, String> map, int t, int m) {
+        Resources res = mContext.getResources();
+        String translated = res.getString(t);
+        String math = res.getString(m);
+        if (!TextUtils.equals(translated, math)) {
+            map.put(translated, math);
+        }
+    }
+
+    private String replaceTranslations(String input) {
+        if (mTranslationsSet == null) {
+            HashMap<String, String> map = new HashMap<String, String>();
+            addTranslation(map, R.string.sin, R.string.sin_mathematical_value);
+            addTranslation(map, R.string.cos, R.string.cos_mathematical_value);
+            addTranslation(map, R.string.tan, R.string.tan_mathematical_value);
+            addTranslation(map, R.string.e, R.string.e_mathematical_value);
+            addTranslation(map, R.string.ln, R.string.ln_mathematical_value);
+            addTranslation(map, R.string.lg, R.string.lg_mathematical_value);
+            mTranslationsSet = map.entrySet();
+        }
+        for (Entry<String, String> entry : mTranslationsSet) {
+            input = input.replace(entry.getKey(), entry.getValue());
+        }
+        return input;
+    }
+
     private String tryFormattingWithPrecision(double value, int precision) {
         // The standard scientific formatter is basically what we need. We will
         // start with what it produces and then massage it a bit.