private void AddResx2DatasetRow(string key, string value, string comment, ResxData rd, string[] cultureList, string[] excludeList, string fileRelativePath, string fileDestination, bool includeNonTranslatableTxt)
        {
            if (excludeList.FirstOrDefault(x => key.EndsWith(x)) != null)
            {
                return;
            }

            if (!includeNonTranslatableTxt &&
                (string.IsNullOrEmpty(value) ||
                 !string.IsNullOrEmpty(comment) && comment.StartsWith("#NonTranslatable", StringComparison.InvariantCultureIgnoreCase)))
            {
                return;
            }

            value = value.Replace("\r", "\\r").Replace("\n", "\\n");

            ResxData.ResxRow r = rd.Resx.NewResxRow();
            r.FileSource      = fileRelativePath;
            r.FileDestination = fileDestination;
            r.Key             = key;
            r.Value           = value;
            r.Comment         = comment;

            rd.Resx.AddResxRow(r);

            foreach (string cult in cultureList)
            {
                ResxData.ResxLocalizedRow lr = rd.ResxLocalized.NewResxLocalizedRow();

                lr.Key = r.Key;
                // change get from resx now if exists.
                lr.Value   = String.Empty;
                lr.Culture = cult;

                lr.ParentId = r.Id;
                lr.SetParentRow(r);

                rd.ResxLocalized.AddResxLocalizedRow(lr);
            }
        }
        private ResxData XlsToDataSet(string xlsFile)
        {
            ResxData rd = new ResxData();

            using (ExcelPackage app = new ExcelPackage(new FileInfo(xlsFile)))
            {
                ExcelWorksheets sheets = app.Workbook.Worksheets;
                ExcelWorksheet  sheet  = sheets[1];

                int row = DATA_ROWS_OFFSET;

                bool continueLoop = true;
                while (continueLoop)
                {
                    string fileSrc = (sheet.Cells[row, COL1_IDX__RESX_SRC] as ExcelRange).Text.ToString();

                    if (String.IsNullOrEmpty(fileSrc))
                    {
                        break;
                    }

                    ResxData.ResxRow r = rd.Resx.NewResxRow();
                    r.FileSource      = (sheet.Cells[row, COL1_IDX__RESX_SRC] as ExcelRange).Text.ToString();
                    r.FileDestination = (sheet.Cells[row, COL2_IDX__RESX_DEST] as ExcelRange).Text.ToString();
                    r.Key             = (sheet.Cells[row, COL3_IDX__KEY] as ExcelRange).Text.ToString();
                    r.Value           = (sheet.Cells[row, COL4_IDX__VALUE] as ExcelRange).Text.ToString();
                    r.Comment         = (sheet.Cells[row, COL5_IDX__COMMENT] as ExcelRange).Text.ToString();

                    rd.Resx.AddResxRow(r);

                    bool hasCulture = true;
                    int  col        = DATA_COLS_OFFSET;
                    while (hasCulture)
                    {
                        string cult = (sheet.Cells[CULTURE_ROW, col] as ExcelRange).Text.ToString();

                        if (String.IsNullOrEmpty(cult))
                        {
                            break;
                        }

                        ResxData.ResxLocalizedRow lr = rd.ResxLocalized.NewResxLocalizedRow();
                        lr.Culture  = cult;
                        lr.Key      = (sheet.Cells[row, COL3_IDX__KEY] as ExcelRange).Text.ToString();
                        lr.Value    = (sheet.Cells[row, col] as ExcelRange).Text.ToString();
                        lr.ParentId = r.Id;
                        lr.SetParentRow(r);

                        rd.ResxLocalized.AddResxLocalizedRow(lr);

                        col++;
                    }

                    row++;
                }

                rd.AcceptChanges();
            }

            return(rd);
        }
Exemplo n.º 3
0
        private ResxData XlsToDataSet(string xlsFile)
        {
            Excel.Application app = new Excel.Application();
            Excel.Workbook    wb  = app.Workbooks.Open(xlsFile,
                                                       0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
                                                       true, false, 0, true, false, false);

            Excel.Sheets sheets = wb.Worksheets;

            Excel.Worksheet sheet = (Excel.Worksheet)sheets.get_Item(1);

            ResxData rd = new ResxData();

            int row = 3;

            bool continueLoop = true;

            while (continueLoop)
            {
                string fileSrc = (sheet.Cells[row, 1] as Excel.Range).Text.ToString();

                if (String.IsNullOrEmpty(fileSrc))
                {
                    break;
                }

                ResxData.ResxRow r = rd.Resx.NewResxRow();

                r.FileSource      = (sheet.Cells[row, 1] as Excel.Range).Text.ToString();
                r.FileDestination = (sheet.Cells[row, 2] as Excel.Range).Text.ToString();
                r.Key             = (sheet.Cells[row, 3] as Excel.Range).Text.ToString();
                r.Value           = (sheet.Cells[row, 4] as Excel.Range).Text.ToString();

                rd.Resx.AddResxRow(r);

                bool hasCulture = true;
                int  col        = 5;
                while (hasCulture)
                {
                    string cult = (sheet.Cells[2, col] as Excel.Range).Text.ToString();

                    if (String.IsNullOrEmpty(cult))
                    {
                        break;
                    }

                    ResxData.ResxLocalizedRow lr = rd.ResxLocalized.NewResxLocalizedRow();

                    lr.Culture  = cult;
                    lr.Key      = (sheet.Cells[row, 3] as Excel.Range).Text.ToString();
                    lr.Value    = (sheet.Cells[row, col] as Excel.Range).Text.ToString();
                    lr.ParentId = r.Id;

                    lr.SetParentRow(r);

                    rd.ResxLocalized.AddResxLocalizedRow(lr);

                    col++;
                }

                row++;
            }

            rd.AcceptChanges();

            wb.Close(false, m_objOpt, m_objOpt);
            app.Quit();

            return(rd);
        }
Exemplo n.º 4
0
        private void ReadResx(string fileName, string projectRoot, ResxData rd, string[] cultureList, string[] excludeList, bool useFolderNamespacePrefix)
        {
            FileInfo fi = new FileInfo(fileName);

            string fileRelativePath = fi.FullName.Remove(0, AddBS(projectRoot).Length);

            string fileDestination;

            if (useFolderNamespacePrefix)
            {
                fileDestination = GetNamespacePrefix(AddBS(projectRoot), AddBS(fi.DirectoryName)) + fi.Name;
            }
            else
            {
                fileDestination = fi.Name;
            }

            ResXResourceReader reader = new ResXResourceReader(fileName);

            reader.BasePath = fi.DirectoryName;

            try
            {
                IDictionaryEnumerator ide = reader.GetEnumerator();

                #region read
                foreach (DictionaryEntry de in reader)
                {
                    if (de.Value is string)
                    {
                        string key = (string)de.Key;

                        bool exclude = false;
                        foreach (string e in excludeList)
                        {
                            if (key.EndsWith(e))
                            {
                                exclude = true;
                                break;
                            }
                        }

                        if (!exclude)
                        {
                            string value = de.Value.ToString();

                            ResxData.ResxRow r = rd.Resx.NewResxRow();

                            r.FileSource      = fileRelativePath;
                            r.FileDestination = fileDestination;
                            r.Key             = key;

                            value = value.Replace("\r", "\\r");
                            value = value.Replace("\n", "\\n");

                            r.Value = value;

                            rd.Resx.AddResxRow(r);


                            foreach (string cult in cultureList)
                            {
                                ResxData.ResxLocalizedRow lr = rd.ResxLocalized.NewResxLocalizedRow();

                                lr.Key     = r.Key;
                                lr.Value   = String.Empty;
                                lr.Culture = cult;

                                lr.ParentId = r.Id;
                                lr.SetParentRow(r);

                                rd.ResxLocalized.AddResxLocalizedRow(lr);
                            }
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show("A problem occured reading " + fileName + "\n" + ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            reader.Close();
        }