Ejemplo n.º 1
0
 public async void TranslateEmptyLanguage()
 {
     var tr = new Translator("", "");
     string text = "Bike";
     var res = await tr.Translate(text);
     Assert.Inconclusive(res);
 }
Ejemplo n.º 2
0
 public async void TranslateEnToRuTest()
 {
     var tr = new Translator("en", "ru");
     string text = "Book";
     var res = await tr.Translate(text);
     Assert.AreEqual("Книга", res);
 }
Ejemplo n.º 3
0
 public async void TranslateRuToEnTest()
 {
     var tr = new Translator("ru", "en");
     string text = "Кошка";
     var res = await tr.Translate(text);
     Assert.AreEqual("Cat", res);
 }
Ejemplo n.º 4
0
        public bool OnActionItemClicked(ActionMode mode, IMenuItem item)
        {
            switch (item.ItemId)
            {
                case Resource.Id.translate:
                    int min = 0;
                    int max = book.Text.Length;
                    if (book.IsFocused)
                    {
                        int selStart = book.SelectionStart;
                        int selEnd = book.SelectionEnd;

                        min = Math.Max(0, Math.Min(selStart, selEnd));
                        max = Math.Max(0, Math.Max(selStart, selEnd));
                    }
                    var selectedText = book.Text.Substring(min, max - min);
                    try
                    {
                        ConfigureTranslator();
                        var translator = new Translator(_langFrom, _langTo);
                        var res = translator.Translate(selectedText).GetAwaiter().GetResult();
                        ShowEditDialog(selectedText, res);
                    }
                    catch (System.Exception)
                    {
                        Toast.MakeText(ParentActivity, "Missing internet connection", ToastLength.Short).Show();
                    }
                    mode.Finish();
                    return true;
                default:
                    break;
            }
            return false;
        }
Ejemplo n.º 5
0
 public async void TranslateEmptyTextTest()
 {
     var tr = new Translator("en", "ru");
     string text = "";
     var res = await tr.Translate(text);
     Assert.AreEqual(null, res);
     Assert.Pass(res);
 }