Beispiel #1
0
        static PoHeader Entry2Header(PoEntry entry)
        {
            PoHeader header = new PoHeader();
            var      option = StringSplitOptions.RemoveEmptyEntries;

            foreach (string line in entry.Translated.Split(new[] { '\n' }, option))
            {
                var fields = line.Split(new[] { ": " }, 2, StringSplitOptions.None);
                if (fields.Length != 2)
                {
                    throw new FormatException("Invalid format line: " + line);
                }

                ParseHeaderLine(header, fields[0], fields[1]);
            }

            return(header);
        }
Beispiel #2
0
        static void WriteHeader(PoHeader header, TextWriter writer)
        {
            writer.WriteLine(@"msgid """"");
            writer.WriteLine(@"msgstr """"");
            writer.WriteLine(@"""Project-Id-Version: {0}\n""", header.ProjectIdVersion ?? string.Empty);
            writer.WriteLine(@"""Report-Msgid-Bugs-To: {0}\n""", header.ReportMsgidBugsTo ?? string.Empty);
            writer.WriteLine(@"""POT-Creation-Date: {0}\n""", header.CreationDate ?? string.Empty);
            writer.WriteLine(@"""PO-Revision-Date: {0}\n""", header.RevisionDate ?? string.Empty);
            writer.WriteLine(@"""Last-Translator: {0}\n""", header.LastTranslator ?? string.Empty);
            writer.WriteLine(@"""Language-Team: {0}\n""", header.LanguageTeam ?? string.Empty);
            writer.WriteLine(@"""Language: {0}\n""", header.Language ?? string.Empty);
            writer.WriteLine(@"""MIME-Version: {0}\n""", PoHeader.MimeVersion);
            writer.WriteLine(@"""Content-Type: {0}\n""", PoHeader.ContentType);
            writer.WriteLine(@"""Content-Transfer-Encoding: {0}\n""", PoHeader.ContentTransferEncoding);
            WriteIfNotEmpty(writer, @"""Plural-Forms: {0}\n""", header.PluralForms);

            foreach (var entry in header.Extensions)
            {
                writer.WriteLine(@"""X-{0}: {1}\n""", entry.Key, entry.Value);
            }
        }
Beispiel #3
0
        static void ParseHeaderLine(PoHeader header, string key, string value)
        {
            switch (key)
            {
            case "Project-Id-Version":
                header.ProjectIdVersion = value;
                break;

            case "Report-Msgid-Bugs-To":
                header.ReportMsgidBugsTo = value;
                break;

            case "POT-Creation-Date":
                header.CreationDate = value;
                break;

            case "PO-Revision-Date":
                header.RevisionDate = value;
                break;

            case "Last-Translator":
                header.LastTranslator = value;
                break;

            case "Language-Team":
                header.LanguageTeam = value;
                break;

            case "Language":
                header.Language = value;
                break;

            case "Plural-Forms":
                header.PluralForms = value;
                break;

            case "MIME-Version":
                if (value != "1.0")
                {
                    throw new FormatException("Invalid MIME version");
                }
                break;

            case "Content-Type":
                if (value != "text/plain; charset=UTF-8")
                {
                    throw new FormatException("Invalid Content-Type");
                }
                break;

            case "Content-Transfer-Encoding":
                if (value != "8bit")
                {
                    throw new FormatException("Invalid Content-Transfer-Encoding");
                }
                break;

            default:
                // Ignore extended / tool-specific fields
                if (key.Length > 2 && key.Substring(0, 2) == "X-")
                {
                    header.Extensions[key.Substring(2)] = value;
                    break;
                }

                throw new FormatException("Unknown header key: " + key);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Po"/> class.
 /// </summary>
 /// <param name="headerArg">PO header.</param>
 public Po(PoHeader headerArg)
     : this()
 {
     Header = headerArg;
 }