Exemple #1
0
        private string LookupDeepl(string sourcetext)
        {
            if (_deeplConnect == null)
            {
                _deeplConnect = new DeepLTranslationProviderConnecter(_options.ApiKey, _options.Identifier);
            }
            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 #3
0
 public bool SupportsLanguageDirection(LanguagePair languageDirection)
 {
     return(DeepLTranslationProviderConnecter.IsLanguagePairSupported(languageDirection.SourceCulture,
                                                                      languageDirection.TargetCulture));
 }
Exemple #4
0
 public DeepLMtTranslationProviderLanguageDirection(DeepLMtTranslationProvider deepLMtTranslationProvider, LanguagePair languageDirection, DeepLTranslationProviderConnecter connecter)
 {
     _deepLMtTranslationProvider = deepLMtTranslationProvider;
     _languageDirection          = languageDirection;
     _options   = deepLMtTranslationProvider.Options;
     _connecter = connecter;
 }