public async Task Translate(string languageCode, [Remainder] string message) { var config = TranslateService.GetTranslateGuild(Context.Guild.Id); //Ensure whitelist isn't enforced unless the list is populated if (config.WhitelistRoles.Any()) { //Check to see if the user has a whitelisted role if (!config.WhitelistRoles.Any(x => (Context.User as IGuildUser)?.RoleIds.Contains(x) == true)) { await ReplyAsync("You do not have enough permissions to run translations."); return; } } var response = TranslateService.Translate(Context.Guild.Id, message, languageCode); if (response.ResponseResult != TranslateService.TranslateResponse.Result.Success) { return; } var embed = TranslateService.GetTranslationEmbed(response); if (embed == null) { return; } await ReplyAsync("", false, embed.Build()); }
public override void AfterCreateEntity(TEntity t) { Type thisType = GetType(); PropertyInfo[] thisProperties = thisType.GetProperties(); TranslateService translateService = ServiceProvider.GetService <TranslateService>(); foreach (var localization in Localizations) { Type localization_Type = localization.GetType(); PropertyInfo[] localization_Properties = localization_Type.GetProperties(); foreach (PropertyInfo localization_Property in localization_Properties) { if (localization_Property.IsStringProperty()) { PropertyInfo thisProperty = thisProperties.FirstOrDefault(w => w.Name == localization_Property.Name); if (thisProperty == null) { continue; } translateService.Translate( thisProperty.GetValue(this, null)?.ToString(), localization_Property.GetValue(localization, null)?.ToString(), localization.CultureCode); } } } }
public static async Task <string> ToUserLocale(this string text, IDialogContext context) { context.UserData.TryGetValue(AppSettings.UserLanguageKey, out string userLanguageCode); text = await TranslateService.Translate(text, AppSettings.DefaultLanguage, userLanguageCode); return(text); }
private async void CommandHandler(object sender, ExecutedRoutedEventArgs ea) { var tweet = (TwitterStatus)ea.Parameter; var lang = CultureInfo.InstalledUICulture.TwoLetterISOLanguageName; tweet.TranslatedText = (string)Application.Current.FindResource("translate-text-working"); tweet.TranslatedText = await TranslateService.Translate(tweet.FullText, lang).ConfigureAwait(true); }
public async Task ReturnNullWhenGivenBadSettings() { // Arrange var service = new TranslateService(badMockSettings.Object); // Act var result = await service.Translate("Caine"); // Assert Assert.Null(result); }
#pragma warning disable CA1822 // (used in XAML) Mark members as static #pragma warning disable RCS1213 // (used in XAML) Remove unused member declaration. #pragma warning disable S1144 // (used in XAML) Unused private types or members should be removedremoved private async void OnTranslateClick(object?_, RoutedEventArgs __) { if (DataContext is not null) { var tweet = (TwitterStatus)DataContext; var fromLang = tweet.Language ?? "und"; var toLang = CultureInfo.InstalledUICulture.TwoLetterISOLanguageName; tweet.TranslatedText = App.GetString("translate-text-working"); tweet.TranslatedText = await TranslateService.Translate(tweet.FullText, fromLang, toLang).ConfigureAwait(true); } }
private async void CommandHandler(object sender, ExecutedRoutedEventArgs ea) { try { var tweet = (TwitterStatus)ea.Parameter; var fromLang = tweet.Language ?? "und"; var toLang = CultureInfo.InstalledUICulture.TwoLetterISOLanguageName; tweet.TranslatedText = App.GetString("translate-text-working"); tweet.TranslatedText = await TranslateService.Translate(tweet.FullText, fromLang, toLang, Settings.TranslateApiKey).ConfigureAwait(true); } catch (Exception ex) { TraceService.Message(ex.Message); } }
static void Main(string[] args) { var word = "I hate you bitch"; var key = "trnsl.1.1.20180420T093654Z.f08eef8abc092cf0.c6d723d0624aed5f2c7083659c70ff0c761bd403"; var url = "https://translate.yandex.net/api/v1.5/tr.json/translate?lang=ru-en"; var wordTranslator = new TranslateService(key, url); url = "https://microsoft-translator-text.p.rapidapi.com/translate?to=ru&api-version=3.0&from=en&profanityAction=NoAction&textType=plain"; var textTranslator = new TranslateService(key, url); Console.WriteLine("Пробуй перевести слово " + word); //wordTranslator.Translate(word).ContinueWith(x => // { // Console.WriteLine(x.Result?.Translations?.FirstOrDefault()?.Text); // }); textTranslator.Translate(word).ContinueWith(x => { Console.WriteLine("Перевод" + x.Result.Translations.FirstOrDefault().Text); }); ToVoiceService vs = new ToVoiceService(); ParametersBuilder parameters = new VoiceParametersBuilder(); parameters.SetUrl("https://translate.google.com.vn/translate_tts"); parameters.SetOriginLanguage(Lang.en); vs.SetParameters(parameters); vs.GetFile(word).ContinueWith(x => { byte[] ms = x.Result; using (FileStream fs = new FileStream(word + ".mp3", FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Write(ms, 0, ms.Length); } }); Console.ReadKey(); }
private async void OnTranslateClick(object?_, RoutedEventArgs __) { try { if (DataContext is not null) { var tweet = (TwitterStatus)DataContext; var fromLang = tweet.Language ?? "und"; var toLang = CultureInfo.InstalledUICulture.TwoLetterISOLanguageName; tweet.TranslatedText = App.GetString("translate-text-working"); tweet.TranslatedText = await TranslateService.Translate( tweet.FullText, fromLang, toLang, (App.MainWindow.DataContext as MainWindowViewModel)?.Settings.TranslateApiKey) .ConfigureAwait(true); } } catch (Exception ex) { TraceService.Message(ex.Message); } }