Beispiel #1
0
        private void CompileTranslation(MetadataCsvReader meta, TextReader translation, TextReader source, TextWriter dest)
        {
            var src          = new CharCountingReader(source);
            var substitution = new SpanPairReader(translation);

            _config = DotConfig.GetConfiguration(Workspace.SourcePath);

            foreach (TextSpan span in meta.GetSpans())
            {
                int preserveSize = (int)span.Offset - src.Position;
                if (src.TextCopyTo(dest, preserveSize) != preserveSize)
                {
                    return;
                }

                string translated = substitution.ReadCorrespondingSpan(span);
                translated = ApplyPostProcess(span, src, translated);
                if (translated == null)
                {
                    continue;
                }
                dest.Write(translated);
            }
            _ = src.TextCopyTo(dest, int.MaxValue);
            // TODO: warn mismatch of translation having more line
        }
Beispiel #2
0
        public void BuildTranslation()
        {
            string translation = GetAlternativeTranslationIfExists();
            string destPath    = Util.PrecreateDirectory(Workspace.DestinationPath);

            if (!StringWithCodePage.ReadAllTextAutoDetect(Workspace.SourcePath, out StringWithCodePage sourceText))
            {
                File.Copy(Workspace.SourcePath, destPath, true);
                return;
            }

            Encoding destinationEncoding = sourceText.Encoding.CodePage == 932 ? _cp949 : _utf8WithBom;

            using var meta           = new MetadataCsvReader(Workspace.MetadataPath);
            using StreamReader trans = File.OpenText(translation);
            using var source         = new StringReader(sourceText.Content);
            using var dest           = new StreamWriter(File.Create(destPath), destinationEncoding);
            CompileTranslation(meta, trans, source, dest);
        }