Ejemplo n.º 1
0
        public static PoFile Read(string filePath)
        {
            var      file          = new PoFile();
            var      lines         = File.ReadAllLines(filePath);
            PoRecord currentRecord = null;

            for (int i = PoFile.StartLine; i < lines.Length; i++)
            {
                var currentLine = lines[i];
                if (currentRecord == null)
                {
                    if (currentLine.StartsWith(PoFile.KeyIdentifier))
                    {
                        currentRecord = new PoRecord()
                        {
                            msgid = ExtractTextFromLine(currentLine)
                        };
                    }
                }
                else if (currentLine.StartsWith(PoFile.ValueIdentifier))
                {
                    currentRecord.msgstr = ExtractTextFromLine(currentLine);
                    file.AddRecord(currentRecord);
                    currentRecord = null;
                }
                else
                {
                    currentRecord = null;
                }
            }
            return(file);
        }
        public static PoSheet Read(string filePath)
        {
            var file = new PoSheet();

            WorkBook  workbook = WorkBook.Load(filePath);
            WorkSheet sheet    = workbook.WorkSheets.First();

            var lines = sheet.Rows;

            for (int i = PoSheet.StartLine; i < lines.Count; i++)
            {
                var line          = lines[i];
                var currentRecord = new PoRecord()
                {
                    msgid  = line.Columns[0].StringValue,
                    msgstr = line.Columns[1].StringValue
                };
                file.AddRecord(currentRecord);
            }
            return(file);
        }
Ejemplo n.º 3
0
        public static PoSheet Read(string filePath)
        {
            var file = new PoSheet();

            Application xlApp       = new Application();
            Workbook    xlWorkbook  = xlApp.Workbooks.Open(filePath);
            _Worksheet  xlWorksheet = xlWorkbook.Sheets[1];
            Range       xlRange     = xlWorksheet.UsedRange;

            var lines = xlRange.Rows;

            for (int i = PoSheet.StartLine; i < lines.Count; i++)
            {
                var currentRecord = new PoRecord()
                {
                    msgid  = lines[i, 1].Value,
                    msgstr = lines[i, 2].Value
                };
                file.AddRecord(currentRecord);
            }
            return(file);
        }
        public static void Override(string filePath, PoSheet sourceFile)
        {
            var linesToRead  = File.ReadAllLines(filePath);
            var linesToWrite = new string[linesToRead.Length];

            linesToRead.CopyTo(linesToWrite, 0);
            PoRecord currentRecord = null;

            for (int i = PoFile.StartLine; i < linesToRead.Length; i++)
            {
                var currentLine = linesToRead[i];
                if (currentRecord == null)
                {
                    if (currentLine.StartsWith(PoFile.KeyIdentifier))
                    {
                        currentRecord = new PoRecord()
                        {
                            msgid = ExtractTextFromLine(currentLine)
                        };
                    }
                }
                else if (currentLine.StartsWith(PoFile.ValueIdentifier))
                {
                    var sourceRecord = sourceFile.Records.FirstOrDefault(x => x.msgid == currentRecord.msgid);
                    if (sourceRecord != null)
                    {
                        linesToWrite[i] = BuildValueLine(sourceRecord.msgstr);
                    }
                    currentRecord = null;
                }
                else
                {
                    currentRecord = null;
                }
            }
            File.WriteAllLines(filePath, linesToWrite);
        }
Ejemplo n.º 5
0
 public void AddRecord(PoRecord record)
 {
     Records.Add(record);
 }