Beispiel #1
0
        internal static string GenerateCustomText(Subtitle subtitle, Subtitle translation, string title, string templateString)
        {
            var arr = templateString.Split('Æ');
            var sb  = new StringBuilder();

            sb.Append(ExportCustomTextFormat.GetHeaderOrFooter(title, subtitle, arr[1]));
            string template = ExportCustomTextFormat.GetParagraphTemplate(arr[2]);

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p     = subtitle.Paragraphs[i];
                string    start = ExportCustomTextFormat.GetTimeCode(p.StartTime, arr[3]);
                string    end   = ExportCustomTextFormat.GetTimeCode(p.EndTime, arr[3]);
                string    text  = ExportCustomTextFormat.GetText(p.Text, arr[4]);

                string translationText = string.Empty;
                if (translation != null && translation.Paragraphs != null && translation.Paragraphs.Count > 0)
                {
                    var trans = Utilities.GetOriginalParagraph(i, p, translation.Paragraphs);
                    if (trans != null)
                    {
                        translationText = trans.Text;
                    }
                }
                string paragraph = ExportCustomTextFormat.GetParagraph(template, start, end, text, translationText, i, p.Actor, p.Duration, arr[3]);
                sb.Append(paragraph);
            }
            sb.Append(ExportCustomTextFormat.GetHeaderOrFooter(title, subtitle, arr[5]));
            return(sb.ToString());
        }
Beispiel #2
0
        private string GenerateText(Subtitle subtitle, Subtitle translation, string title)
        {
            if (listViewTemplates.SelectedItems.Count != 1)
            {
                return(string.Empty);
            }

            if (title == null)
            {
                title = string.Empty;
            }
            else
            {
                title = System.IO.Path.GetFileNameWithoutExtension(title);
            }

            try
            {
                int idx = listViewTemplates.SelectedItems[0].Index;
                var arr = _templates[idx].Split('Æ');
                var sb  = new StringBuilder();
                sb.Append(ExportCustomTextFormat.GetHeaderOrFooter(title, subtitle, arr[1]));
                string template = ExportCustomTextFormat.GetParagraphTemplate(arr[2]);
                for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
                {
                    Paragraph p     = _subtitle.Paragraphs[i];
                    string    start = ExportCustomTextFormat.GetTimeCode(p.StartTime, arr[3]);
                    string    end   = ExportCustomTextFormat.GetTimeCode(p.EndTime, arr[3]);
                    string    text  = ExportCustomTextFormat.GetText(p.Text, arr[4]);

                    string translationText = string.Empty;
                    if (translation != null && translation.Paragraphs != null && translation.Paragraphs.Count > 0)
                    {
                        var trans = Utilities.GetOriginalParagraph(idx, p, translation.Paragraphs);
                        if (trans != null)
                        {
                            translationText = trans.Text;
                        }
                    }

                    string paragraph = ExportCustomTextFormat.GetParagraph(template, start, end, text, translationText, i, p.Duration, arr[3]);
                    sb.Append(paragraph);
                }
                sb.Append(ExportCustomTextFormat.GetHeaderOrFooter(title, subtitle, arr[5]));
                return(sb.ToString());
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }