diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2012-02-14 08:54:03 +0100 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2012-02-14 08:54:03 +0100 |
| commit | 7b56b083de8f1470e26bab5750e581eaaf7c0581 (patch) | |
| tree | 25f8e74d96ae78ae1efd274e8507eede8a78b740 /main/src/cgeo/geocaching/utils/TranslationUtils.java | |
| parent | b9225c7008e49de51e5bfcd40f867e130f988a80 (diff) | |
| parent | c04f7f1c5e6d3e5af825b755fc457ca3c9214767 (diff) | |
| download | cgeo-7b56b083de8f1470e26bab5750e581eaaf7c0581.zip cgeo-7b56b083de8f1470e26bab5750e581eaaf7c0581.tar.gz cgeo-7b56b083de8f1470e26bab5750e581eaaf7c0581.tar.bz2 | |
Merge remote-tracking branch 'campbeb/implement1073'
Conflicts:
main/res/values/strings.xml
Diffstat (limited to 'main/src/cgeo/geocaching/utils/TranslationUtils.java')
| -rw-r--r-- | main/src/cgeo/geocaching/utils/TranslationUtils.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/utils/TranslationUtils.java b/main/src/cgeo/geocaching/utils/TranslationUtils.java new file mode 100644 index 0000000..e086ab6 --- /dev/null +++ b/main/src/cgeo/geocaching/utils/TranslationUtils.java @@ -0,0 +1,46 @@ +package cgeo.geocaching.utils; + +import cgeo.geocaching.activity.AbstractActivity; + +import android.content.Intent; +import android.net.Uri; + +import java.net.URLEncoder; + +/** + * Utilities used for translating + */ +public final class TranslationUtils { + + private static final String translationWebsite = "http://translate.google.com/"; + private static final String translationForceClassicMode = "?vi=c"; + private static final String translationAutoSelect = "#auto"; + private static final String translationFieldSeparator = "|"; + + public static final int translationTextLengthToWarn = 500; + + /** + * Build a URI for Google Translate + * + * @param toLang + * The two-letter lowercase ISO language codes as defined by ISO 639-1 + * @param text + * The text to be translated + * @return URI ready to be parsed + */ + public static String buildTranslationURI(final String toLang, final String text) { + return translationWebsite + translationForceClassicMode + translationAutoSelect + translationFieldSeparator + toLang + translationFieldSeparator + URLEncoder.encode(text).replace("+", "%20"); + } + + /** + * Send Intent for Google Translate. Can be caught by Google Translate App or browser + * + * @param toLang + * The two-letter lowercase ISO language codes as defined by ISO 639-1 + * @param text + * The text to be translated + */ + public static void startActivityTranslate(final AbstractActivity context, final String toLang, final String text) { + context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(buildTranslationURI(toLang, text)))); + } +} |
