Index: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchPolicy.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchPolicy.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchPolicy.java |
index b7da20b266ae7e53bf201457264cf565b3ef22d4..c1dd99165225d41d4ab8a96cbee7f51d44801bee 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchPolicy.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchPolicy.java |
@@ -5,6 +5,7 @@ |
package org.chromium.chrome.browser.contextualsearch; |
import android.content.Context; |
+import android.text.TextUtils; |
import org.chromium.base.VisibleForTesting; |
import org.chromium.chrome.browser.ChromeVersionInfo; |
@@ -15,6 +16,7 @@ import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
import org.chromium.content.browser.ContentViewCore; |
import java.net.URL; |
+import java.util.List; |
import java.util.regex.Pattern; |
import javax.annotation.Nullable; |
@@ -356,6 +358,31 @@ class ContextualSearchPolicy { |
return mPreferenceManager.getContextualSearchTapCount(); |
} |
+ /** |
+ * Determines whether translation is needed between the given languages. |
+ * @param sourceLanguage The source language code; language we're translating from. |
+ * @param targetLocales A list of target language codes; languages we might translating to. |
+ * @return Whether translation is needed or not. |
+ */ |
+ boolean needsTranslation(String sourceLanguage, List<String> targetLocales) { |
+ // For now, we just look for a language match, ignoring |
+ // regional variations, so pt-BR will match pt-PT. We do this because it |
+ // seems unlikely the user would want translations from different dialects. |
+ for (String target : targetLocales) { |
+ if (TextUtils.equals(sourceLanguage.substring(0, 2), target.substring(0, 2))) { |
+ return false; |
+ } |
+ } |
+ return true; |
+ } |
+ |
+ /** |
+ * @return Whether translation should be enabled or not. |
+ */ |
+ boolean isTranslationEnabled() { |
+ return ContextualSearchFieldTrial.isQuickAnswersEnabled(); |
+ } |
+ |
// -------------------------------------------------------------------------------------------- |
// Private helpers. |
// -------------------------------------------------------------------------------------------- |