public static List <UnitOfWork> FetchUnitsFromFile(Dictionary <string, int> languageToIndexMap, string targetDirectory, string localizationMap) { var excel = new ExcelQueryFactory(localizationMap).Worksheet("Sheet1").Skip(1).ToArray(); var unitsOfWork = new List <UnitOfWork>(); Row currentRow = null; UnitOfWork current = null; for (int i = 0; i < excel.Length; i++) { currentRow = excel[i]; var resxPath = currentRow[0]; if (!String.IsNullOrWhiteSpace(resxPath)) { var absoluteResxPath = Path.Combine(targetDirectory, resxPath); var existing = unitsOfWork.Find(x => x.ResourceFile == absoluteResxPath); if (existing == null) { current = new UnitOfWork { ResourceFile = absoluteResxPath }; unitsOfWork.Add(current); } else { current = existing; } } var key = currentRow[1].ToString(); var en = currentRow[2]; if (!String.IsNullOrWhiteSpace(key)) { var localizedEntry = new LocalizedEntry(key, en); current.Localizations.Add(localizedEntry); foreach (var langKvp in languageToIndexMap) { var localizedString = currentRow[langKvp.Value]; localizedEntry.Localizations.Add(langKvp.Key, localizedString); } } } return(unitsOfWork); }
public static List <UnitOfWork> FetchUnitsFromSpreadsheet(string targetDirectory, string localizationMap, string sheet, Dictionary <string, int> languageToIndexMap = null) { var dt = GetExcelData(localizationMap, sheet); var unitsOfWork = new List <UnitOfWork>(); string[] currentRow = null; UnitOfWork current = null; languageToIndexMap = languageToIndexMap ?? _languageToIndexMap; foreach (var row in dt.AsEnumerable().Skip(1)) { currentRow = row.ItemArray.Select(x => x.ToString()).ToArray(); currentRow[1] = currentRow[1]; if (!String.IsNullOrEmpty(currentRow[0])) { var absoluteResxPath = Path.Combine(targetDirectory, currentRow[0]); var existing = unitsOfWork.Find(x => x.ResourceFile == absoluteResxPath); if (existing == null) { current = new UnitOfWork { ResourceFile = absoluteResxPath }; unitsOfWork.Add(current); } else { current = existing; } } var key = currentRow[1].ToString(); var en = currentRow[2]; if (!String.IsNullOrWhiteSpace(key)) { if (String.IsNullOrEmpty(en)) { en = key; } var localizedEntry = new LocalizedEntry(key, en); current.Localizations.Add(localizedEntry); foreach (var langKvp in languageToIndexMap) { var localizedString = String.IsNullOrEmpty(currentRow[langKvp.Value]) ? null : currentRow[langKvp.Value]; localizedEntry.Localizations.Add(langKvp.Key, localizedString); } } } return(unitsOfWork); }