public async Task TranslateAsync(TranslationRequest request)
        {
            var elementsToTranslate = _resxComparer.CreateElementsToTranslate(
                request.SourceFilePath,
                request.TargetFilePath);

            if (!elementsToTranslate.Any())
            {
                return;
            }

            var ignoreMarkup = new IgnoreForTranslationMarkup("{", "}");

            var translatedElements = await _translationSender.SendElementsAsync(
                request,
                ignoreMarkup,
                elementsToTranslate);

            var alignedElements = _resxAligner.AlignElements(
                request.SourceFilePath,
                request.TargetFilePath,
                translatedElements);

            _resxWriter.WriteResx(alignedElements, request.TargetFilePath);
        }
Exemplo n.º 2
0
        private IReadOnlyCollection <TextTranslationRequest> CreateRequests(
            TranslationRequest request,
            IgnoreForTranslationMarkup ignoreMarkup,
            IReadOnlyCollection <TranslationElement> elementsToTranslate)
        {
            var textParts           = elementsToTranslate.Select(ele => new IdentifiableText(ele.Key, ele.Value)).ToArray();
            var translationRequests = _textrequestFactory.CreateRequests(
                request.TargetLanguageCode,
                request.SourceLanguageCode,
                ignoreMarkup,
                textParts);

            return(translationRequests);
        }
Exemplo n.º 3
0
        public async Task <IReadOnlyCollection <TranslationElement> > SendElementsAsync(
            TranslationRequest request,
            IgnoreForTranslationMarkup ignoreMarkup,
            IReadOnlyCollection <TranslationElement> elementsToTranslate)
        {
            var translationRequests = CreateRequests(request, ignoreMarkup, elementsToTranslate);
            var translationTasks    = translationRequests.Select(req => _textTranslator.TranslateAsync(req));
            var translationResults  = await Task.WhenAll(translationTasks);

            var allTranslatedTexts = translationResults.SelectMany(res => res.TranslatedTexts);
            var result             = allTranslatedTexts.Select(trans => new TranslationElement(trans.Text.Key, trans.Text.Text)).ToList();

            return(result);
        }
Exemplo n.º 4
0
        public async Task TranslateAsync(TranslationRequest request)
        {
            var sourceJson          = _jsonParser.Parse(request.SourceFilePath);
            var targetJson          = _jsonParser.Parse(request.TargetFilePath);
            var elementsToTranslate = _jsonComparer.CreateElementsToTranslate(sourceJson, targetJson);

            if (elementsToTranslate.Count > 0)
            {
                var ignoreMarkup       = new IgnoreForTranslationMarkup("{{", "}}");
                var translatedElements = await _sender.SendElementsAsync(
                    request,
                    ignoreMarkup,
                    elementsToTranslate);

                _jsonAligner.AlignRootElement(targetJson, translatedElements);
                _jsonWriter.WriteJson(targetJson, request.TargetFilePath);
            }
        }
 public ITranslationRequestBuilder WithIgnoreMarkupTag(string beginTag, string endTag)
 {
     _ignoreMarkup = new IgnoreForTranslationMarkup(beginTag, endTag);
     return(this);
 }