Exemple #1
0
        private async Task <List <PreTranslateSegment> > PrepareTempData(List <PreTranslateSegment> preTranslateSegments)
        {
            try
            {
                for (var i = 0; i < preTranslateSegments.Count; i++)
                {
                    if (preTranslateSegments[i] != null)
                    {
                        string sourceText;
                        var    newSeg = preTranslateSegments[i].TranslationUnit.SourceSegment.Duplicate();

                        if (newSeg.HasTags)
                        {
                            var tagPlacer = new DeepLTranslationProviderTagPlacer(newSeg);
                            sourceText = tagPlacer.PreparedSourceText;
                        }
                        else
                        {
                            sourceText = newSeg.ToPlain();
                        }

                        preTranslateSegments[i].SourceText = sourceText;
                    }
                }

                var translator = new DeepLTranslationProviderConnecter(_options.ApiKey, _options.Formality);

                await Task.Run(() => Parallel.ForEach(preTranslateSegments, segment =>
                {
                    if (segment != null)
                    {
                        segment.PlainTranslation = translator.Translate(_languageDirection, segment.SourceText);
                    }
                })).ConfigureAwait(true);

                return(preTranslateSegments);
            }
            catch (Exception e)
            {
                _logger.Error($"{e.Message}\n {e.StackTrace}");
            }

            preTranslateSegments.ForEach(seg =>
            {
                if (seg.PlainTranslation == null)
                {
                    seg.PlainTranslation = string.Empty;
                }
            });
            return(preTranslateSegments);
        }
Exemple #2
0
		private string LookupDeepl(string sourcetext)
		{
			if (_deeplConnect == null)
			{
				_deeplConnect = new DeepLTranslationProviderConnecter(_options.ApiKey);
			}
			else
			{
				_deeplConnect.ApiKey = _options.ApiKey;
			}

			var translatedText = _deeplConnect.Translate(_languageDirection, sourcetext);
			return translatedText;
		}
        private async Task <List <PreTranslateSegment> > PrepareTempData(List <PreTranslateSegment> preTranslatesegments)
        {
            try
            {
                for (var i = 0; i < preTranslatesegments.Count; i++)
                {
                    if (preTranslatesegments[i] != null)
                    {
                        string sourceText;
                        var    newseg = preTranslatesegments[i].TranslationUnit.SourceSegment.Duplicate();

                        if (newseg.HasTags)
                        {
                            var tagPlacer = new DeepLTranslationProviderTagPlacer(newseg);
                            sourceText = tagPlacer.PreparedSourceText;
                        }
                        else
                        {
                            sourceText = newseg.ToPlain();
                        }

                        preTranslatesegments[i].SourceText = sourceText;
                    }
                }


                var translator = new DeepLTranslationProviderConnecter(_options.ApiKey, _options.Identifier);

                await Task.Run(() => Parallel.ForEach(preTranslatesegments, segment =>
                {
                    if (segment != null)
                    {
                        segment.PlainTranslation = translator.Translate(_languageDirection, segment.SourceText);
                    }
                })).ConfigureAwait(true);

                return(preTranslatesegments);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(preTranslatesegments);
        }
Exemple #4
0
 private string LookupDeepL(string sourceText)
 {
     return(_connecter.Translate(_languageDirection, sourceText));
 }