Пример #1
0
        private void readPOToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.DefaultExt = ".po";
            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                PoReader       reader  = new PoReader(dialog.FileName);
                List <PoEntry> entries = reader.ReadPo();
                ApplyPo        applyPo = new ApplyPo();
                applyPo.Apply(entries, resourceDirectory, new StringWriter());
                PopulateListView();
            }
        }
Пример #2
0
        private void SynchronizePoFile(string resxDirectory, string poDirectory, string baseName, CultureInfo culture, string programName, string email, string version, TextWriter statusOutput)
        {
            ResourceDirectory resourceDirectory = new ResourceDirectory();

            statusOutput.WriteLine("Reading RESX directory '{0}' for culture '{1}'", resxDirectory, culture.Name);
            resourceDirectory.ReadFiles(resxDirectory, culture);
            resourceDirectory.ReadResources();

            foreach (var resX in resourceDirectory.AllFiles)
            {
                statusOutput.WriteLine("   {0}", resX);
            }
            statusOutput.WriteLine();

            string cultureName = culture.Name;

            if (cultureName.EndsWith("-NO"))
            {
                cultureName = cultureName.Substring(0, 2);
            }
            cultureName = cultureName.Replace("-", "_");

            string poFileName = Path.Combine(poDirectory, baseName + "-" + cultureName + ".po");

            statusOutput.WriteLine("Reading PO file '{0}' for culture '{1}'", poFileName, culture.Name);
            PoReader       reader  = new PoReader(poFileName);
            List <PoEntry> entries = reader.ReadPo();
            ApplyPo        applyPo = new ApplyPo();

            applyPo.Apply(entries, resourceDirectory, statusOutput);

            resourceDirectory.WriteResources();

            PoWriterAttributes attributes = new PoWriterAttributes()
            {
                Name     = programName,
                Email    = email,
                Version  = version,
                writePOT = false
            };

            PoWriter potWriter = new PoWriter(poFileName, attributes);

            potWriter.WritePot(resourceDirectory);
        }
Пример #3
0
        private void SynchronizePoFile(string resxDirectory, string poDirectory, string baseName, CultureInfo culture, string programName, string email, string version, TextWriter statusOutput)
        {
            ResourceDirectory resourceDirectory = new ResourceDirectory();

            statusOutput.WriteLine("Reading RESX directory '{0}' for culture '{1}'", resxDirectory, culture.Name);
            resourceDirectory.ReadFiles(resxDirectory, culture);
            resourceDirectory.ReadResources();

            foreach (var resX in resourceDirectory.AllFiles) {
                statusOutput.WriteLine("   {0}", resX);
            }
            statusOutput.WriteLine();

            string cultureName = culture.Name;
            if (cultureName.EndsWith("-NO"))
                cultureName = cultureName.Substring(0, 2);
            cultureName = cultureName.Replace("-", "_");

            string poFileName = Path.Combine(poDirectory, baseName + "-" + cultureName + ".po");

            statusOutput.WriteLine("Reading PO file '{0}' for culture '{1}'", poFileName, culture.Name);
            PoReader reader = new PoReader(poFileName);
            List<PoEntry> entries = reader.ReadPo();
            ApplyPo applyPo = new ApplyPo();
            applyPo.Apply(entries, resourceDirectory, statusOutput);

            resourceDirectory.WriteResources();

            PoWriterAttributes attributes = new PoWriterAttributes() {
                Name = programName,
                Email = email,
                Version = version,
                writePOT = false
            };

            PoWriter potWriter = new PoWriter(poFileName, attributes);
            potWriter.WritePot(resourceDirectory);
        }
Пример #4
0
 private void readPOToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog dialog = new OpenFileDialog();
     dialog.DefaultExt = ".po";
     if (dialog.ShowDialog(this) == DialogResult.OK) {
         PoReader reader = new PoReader(dialog.FileName);
         List<PoEntry> entries = reader.ReadPo();
         ApplyPo applyPo = new ApplyPo();
         applyPo.Apply(entries, resourceDirectory, new StringWriter());
         PopulateListView();
     }
 }
Пример #5
0
        string DumpLines(PoReader reader)
        {
            StringWriter writer = new StringWriter();
            PoReader.PoLine line;

            while ((line = reader.ReadLine()) != null) {
                writer.Write("{0}: ", reader.lineNumber);
                switch (line.kind) {
                case PoReader.PoLineKind.Blank:
                    writer.WriteLine("blank");  break;
                case PoReader.PoLineKind.Comment:
                    writer.WriteLine("comment"); break;
                case PoReader.PoLineKind.LocationComment:
                    writer.WriteLine("location: {0},{1}", line.str1, line.str2);  break;
                case PoReader.PoLineKind.KeywordString:
                    writer.WriteLine("kw({0}): '{1}'", line.str1, line.str2); break;
                case PoReader.PoLineKind.String:
                    writer.WriteLine("str: '{0}'", line.str1); break;
                default:
                    writer.WriteLine("unknown"); break;
                }
            }

            writer.WriteLine("EOF");

            return writer.ToString();
        }
Пример #6
0
        public void ReadSamplePoLines()
        {
            PoReader reader = new PoReader(GetTestFile("SamplePo.po"));
            string result = DumpLines(reader);
            string expected =
            @"1: comment
            2: comment
            3: comment
            4: kw(msgid): ''
            5: kw(msgstr): ''
            6: str: 'Project-Id-Version: purple-pen
            '
            7: str: 'Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>
            '
            8: blank
            9: location: AboutForm.resx,freeLabel.Text
            10: kw(msgid): 'Purple Pen is free software and may be copied and shared.'
            11: kw(msgstr): 'Purple Pen est un logiciel libre et peut être copié et partagé.'
            12: blank
            13: location: AboutForm.resx,okButton.Text
            14: location: AddCourse.resx,okButton.Text
            15: kw(msgid): 'View Full License'
            16: kw(msgstr): 'Voir la licence complète'
            17: blank
            18: blank
            19: blank
            20: location: AboutForm.resx,disclaimerLabel.Text
            21: kw(msgid): ''
            22: str: 'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS '
            23: str: 'IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, '
            24: kw(msgstr): ''
            25: str: 'CE LOGICIEL EST FOURNI ""TEL QUEL"" PAR LES DÉTENTEURS DU COPYRIGHT ET PAR '
            26: str: 'LES CONTRIBUTEURS. TOUTES GARANTIES EXPLICITES OU IMPLICITES (INCLUANT, MAIS '
            EOF
            ";

            Assert.AreEqual(expected, result);
        }
Пример #7
0
        public void ReadSamplePoEntries()
        {
            PoReader reader = new PoReader(GetTestFile("SamplePo.po"));
            List<PoEntry> entries = reader.ReadPo();
            StringWriter writer = new StringWriter();

            foreach (PoEntry entry in entries) {
                writer.WriteLine("====Entry===");
                writer.WriteLine("English: '{0}'", entry.NonLocalized);
                writer.WriteLine("Translated: '{0}'", entry.Localized);
                writer.WriteLine("Locations:");
                foreach (PoLocation location in entry.Locations) {
                    writer.WriteLine("    {0},{1}", location.FileName, location.Name);
                }
            }

            string result = writer.ToString();
            string expected =
            @"====Entry===
            English: 'Purple Pen is free software and may be copied and shared.'
            Translated: 'Purple Pen est un logiciel libre et peut être copié et partagé.'
            Locations:
            AboutForm.resx,freeLabel.Text
            ====Entry===
            English: 'View Full License'
            Translated: 'Voir la licence complète'
            Locations:
            AboutForm.resx,okButton.Text
            AddCourse.resx,okButton.Text
            ====Entry===
            English: 'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, '
            Translated: 'CE LOGICIEL EST FOURNI ""TEL QUEL"" PAR LES DÉTENTEURS DU COPYRIGHT ET PAR LES CONTRIBUTEURS. TOUTES GARANTIES EXPLICITES OU IMPLICITES (INCLUANT, MAIS '
            Locations:
            AboutForm.resx,disclaimerLabel.Text
            ";

            Assert.AreEqual(expected, result);
        }