public string DetectLanguageCodeFromFileName( IInheritedSettings settings, string fileName) { // Bug_ when no project loaded, therefore create. if (settings == null) { settings = Project.Empty; } // -- if (string.IsNullOrEmpty(fileName)) { return(settings.EffectiveNeutralLanguageCode); } else { fileName = ZlpPathHelper.GetFileNameFromFilePath(fileName); fileName = removeOptionalDefaultTypes(settings, fileName, null); // Check for non-neutral, first. if (IsNonNeutralLanguageFileName(settings, fileName)) { return(extractBlock(settings, fileName, PhLanguagecode)); } else { // Is neutral language. return(settings.EffectiveNeutralLanguageCode); } } }
public static string GetExtension( IInheritedSettings settings, string fileName ) { return(extractBlock(settings, fileName, PhExtension)); }
//CHANGED extract language string inside next to last point delimited part //returns culture string like de-DE or null or empty if neutral file guessed public static string GetBaseName( IInheritedSettings settings, string fileName ) { return(extractBlock(settings, fileName, PhBasename)); }
public static bool IsNeutralLanguageFileName( IInheritedSettings settings, string filePath) { //CHANGED just invert decision return(!IsNonNeutralLanguageFileName(settings, filePath)); }
/// <summary> /// Check whether the export of duplicates is enabled/disabled and then /// check whether was exported in the past. /// </summary> private static bool wasAlreadyExported( ICollection <string> exportedReferenceLanguageValues, PreparedInformation preparedInformation, IInheritedSettings parentSettings, DataRow row) { if (preparedInformation.EliminateDuplicateRows) { // Column 0=FileGroup checksum, column 1=Tag name. for (var columnIndex = 2; columnIndex < row.Table.Columns.Count; ++columnIndex) { var languageCode = IsFileName(row.Table.Columns[columnIndex].ColumnName) ? new LanguageCodeDetection(preparedInformation.Project).DetectLanguageCodeFromFileName( parentSettings, row.Table.Columns[columnIndex].ColumnName) : row.Table.Columns[columnIndex].ColumnName; if (string.Compare(preparedInformation.ReferenceLanguageCode, languageCode, StringComparison.OrdinalIgnoreCase) == 0) { var languageValue = ConvertHelper.ToString(row[columnIndex]); return(exportedReferenceLanguageValues.Contains(languageValue)); } } return(false); } else { return(false); } }
private int getDestinationTableColumnIndex( IInheritedSettings settings, DataTable dataTable, string languageCode) { var columnIndex = 0; foreach (DataColumn column in dataTable.Columns) { if (columnIndex > 1) // Column 0=FileGroup checksum, column 1=Tag name. { var lc = ExcelExportController.IsFileName(column.ColumnName) ? new LanguageCodeDetection( _information.Project) .DetectLanguageCodeFromFileName( settings, column.ColumnName) : column.ColumnName; if (string.Compare(lc, languageCode, StringComparison.OrdinalIgnoreCase) == 0) { return(column.Ordinal); } } columnIndex++; } // -- // 2011-01-24, Uwe Keim: No direct (like "en-US") found, try fuzzy (like "en"). columnIndex = 0; foreach (DataColumn column in dataTable.Columns) { if (columnIndex > 1) // Column 0=FileGroup checksum, column 1=Tag name. { var lc = ExcelExportController.IsFileName(column.ColumnName) ? new LanguageCodeDetection( _information.Project) .DetectLanguageCodeFromFileName( settings, column.ColumnName) : column.ColumnName; if (lc.StartsWith(languageCode, StringComparison.InvariantCultureIgnoreCase)) { return(column.Ordinal); } } columnIndex++; } // -- return(-1); }
public bool IsNeutralCulture( IInheritedSettings settings, CultureInfo culture) { return(culture == MakeValidCulture( settings.EffectiveNeutralLanguageCode)); }
public CultureInfo DetectCultureFromFileName( IInheritedSettings settings, string fileName) { var culture = DetectLanguageCodeFromFileName( settings, fileName); return(MakeValidCulture(culture)); }
private static bool hasChangedTextSinceLastExport( SnapshotController ssc, PreparedInformation preparedInformation, IInheritedSettings settings, DataRow row) { var lcs = new List <string>(new[] { preparedInformation.ReferenceLanguageCode }); for (var i = 0; i < lcs.Count; ++i) { lcs[i] = lcs[i].ToLowerInvariant(); } // ReSharper disable LoopCanBeConvertedToQuery); foreach (DataColumn column in row.Table.Columns) // ReSharper restore LoopCanBeConvertedToQuery { // Column 0=FileGroup checksum, column 1=Tag name. if (column.Ordinal != 0 && column.Ordinal != 1 && !isCommentColumn(column)) { var languageCode = IsFileName(column.ColumnName) ? new LanguageCodeDetection(preparedInformation.Project).DetectLanguageCodeFromFileName( settings, column.ColumnName) : column.ColumnName; languageCode = languageCode.ToLowerInvariant(); if (/*lcs.Contains(languageCode.Substring(0, 2)) ||*/ lcs.Contains(languageCode)) { var languageValue = ConvertHelper.ToString(row[column], string.Empty); if (!StringExtensionMethods.IsNullOrWhiteSpace(languageValue)) { var fileGroup = row[0] as string; var tagName = row[1] as string; if (hasValueChanged(ssc, fileGroup, tagName, languageCode, languageValue)) { return(true); } } } } } return(false); }
private static string removeOptionalDefaultTypes( IInheritedSettings settings, string fileName, ICollection <string> removedTypes) { if (settings == null || string.IsNullOrEmpty(fileName)) { return(fileName); } else { var odfts = settings.EffectiveDefaultFileTypesToIgnoreArray; if (odfts.Length > 0) { foreach (var odft in odfts) { var p = string.Format( @"\b({0})\b", Regex.Escape(odft)); var before = fileName; fileName = Regex.Replace(fileName, p, string.Empty, RegexOptions.IgnoreCase); if (fileName != before && removedTypes != null) { removedTypes.Add(odft); } } return(fileName); } else { return(fileName); } } }
public static bool IsNonNeutralLanguageFileName( IInheritedSettings settings, string filePath) { var fn = ZlpPathHelper.GetFileNameFromFilePath(filePath); var baseDotCount = settings == null ? 0 : settings.EffectiveBaseNameDotCount; //CHANGED: special case if settings.EffectiveBaseNameDotCount < 0, guess culture from name: if (settings == null || baseDotCount <= 0) { var cultureString = GetLanguageCodeFromFileNameSuffix(settings, filePath); return(!string.IsNullOrEmpty(cultureString)); } else { var nonNeutralDotCount = getDotCount(settings.EffectiveNonNeutralLanguageFileNamePattern); var dc = getDotCount(fn); return(dc == nonNeutralDotCount + baseDotCount); } }
public string DetectLanguageCodeFromFileName( IInheritedSettings settings, string fileName) { // Bug_ when no project loaded, therefore create. if (settings == null) { settings = Project.Empty; } // -- if (string.IsNullOrEmpty(fileName)) { return(settings.EffectiveNeutralLanguageCode); } else { fileName = ZlpPathHelper.GetFileNameFromFilePath(fileName); fileName = removeOptionalDefaultTypes(settings, fileName, null); // Check for non-neutral, first. if (IsNonNeutralLanguageFileName(settings, fileName)) { //return extractBlock(settings, fileName, PhLanguagecode); var startLangPos = fileName.IndexOf('_'); var endLangPosition = fileName.IndexOf('.', startLangPos); var result = fileName.Substring(startLangPos + 1, endLangPosition - startLangPos - 1); return(result); } else { // Is neutral language. return(settings.EffectiveNeutralLanguageCode); } } }
//CHANGED extract language string inside next to last point delimited part //returns culture string like de-DE or null or empty if neutral file guessed public static string GetLanguageCodeFromFileNameSuffix( IInheritedSettings settings, string fileName ) { var cultureString = string.Empty; if (string.IsNullOrEmpty(fileName)) { return(null); //no suffix found } else { fileName = ZlpPathHelper.GetFileNameFromFilePath(fileName); fileName = ZlpPathHelper.GetFileNameWithoutExtension(fileName); fileName = removeOptionalDefaultTypes(settings, fileName, null); var baseName = fileName.ToLowerInvariant(); if (!string.IsNullOrEmpty(baseName)) { var pPos = fileName.LastIndexOf('.'); if (pPos > -1 && pPos < fileName.Length - 1) { var possibleCulture = fileName.Substring(pPos + 1); if (!string.IsNullOrEmpty(possibleCulture)) { if (IsValidCultureName(possibleCulture)) { cultureString = fileName.Substring(pPos + 1); } } } } } return(cultureString); }
private static string extractBlock( IInheritedSettings settings, string text, string after) { if (string.IsNullOrEmpty(text)) { return(text); //no suffix found } else { // Bug_ when no project loaded, therefore create. if (settings == null) { settings = Project.Empty; } var patternOrigin = IsNonNeutralLanguageFileName(settings, text) ? settings.EffectiveNonNeutralLanguageFileNamePattern : settings.EffectiveNeutralLanguageFileNamePattern; var optionalTypes = new List <string>(); text = removeOptionalDefaultTypes(settings, text, optionalTypes); if (after == PhOptionaltypes) { return((optionalTypes.Count > 0 ? optionalTypes[0] : null) ?? string.Empty); } //remove pattern: patternOrigin = patternOrigin.Replace(PhOptionaltypes, string.Empty); if (!patternOrigin.Contains(after)) { if (after == PhLanguagecode) { //special case neutral cuture return(settings.EffectiveNeutralLanguageCode); } } var pattern = patternOrigin; var block = text; string leftBlock; string rightBlock; string leftPattern; string rightPattern; //trim right while (!string.IsNullOrEmpty(block) && !string.IsNullOrEmpty(pattern) && pattern.Contains(after)) { splitBlockRight(pattern, @".", out leftPattern, out rightPattern); splitBlockRight(block, @".", out leftBlock, out rightBlock); if (rightPattern == PhBasename) { //we must trim from left now because basename may expand multiple blocks break; } if (rightPattern == after) { //we are done return(rightBlock); } pattern = leftPattern; block = leftBlock; } //trim left while (!string.IsNullOrEmpty(block) && !string.IsNullOrEmpty(pattern) && pattern.Contains(after)) { splitBlockLeft(pattern, @".", out leftPattern, out rightPattern); splitBlockLeft(block, @".", out leftBlock, out rightBlock); if (leftPattern == after) { if (leftPattern == PhBasename && string.IsNullOrEmpty(rightPattern)) { //return remaining block return(block); } //we are done return(leftBlock); } pattern = rightPattern; block = rightBlock; } //if we gets here, we have problems with pattern. throw new ArgumentException( string.Format( Resources.SR_LanguageCodeDetection_extractBlock_PatternDoesNotMatch, after, patternOrigin, text)); } }
public CultureInfo DetectCultureFromFileName( IInheritedSettings settings, string fileName) { var culture = DetectLanguageCodeFromFileName( settings, fileName); return MakeValidCulture(culture); }
public string DetectLanguageCodeFromFileName( IInheritedSettings settings, string fileName) { // Bug_ when no project loaded, therefore create. if (settings == null) { settings = Project.Empty; } // -- if (string.IsNullOrEmpty(fileName)) { return settings.EffectiveNeutralLanguageCode; } else { fileName = ZlpPathHelper.GetFileNameFromFilePath(fileName); fileName = removeOptionalDefaultTypes(settings, fileName, null); // Check for non-neutral, first. if (IsNonNeutralLanguageFileName(settings, fileName)) { return extractBlock(settings, fileName, PhLanguagecode); } else { // Is neutral language. return settings.EffectiveNeutralLanguageCode; } } }
//CHANGED extract language string inside next to last point delimited part //returns culture string like de-DE or null or empty if neutral file guessed public static string GetLanguageCodeFromFileNameSuffix( IInheritedSettings settings, string fileName ) { var cultureString = string.Empty; if (string.IsNullOrEmpty(fileName)) { return null; //no suffix found } else { fileName = ZlpPathHelper.GetFileNameFromFilePath(fileName); fileName = ZlpPathHelper.GetFileNameWithoutExtension(fileName); fileName = removeOptionalDefaultTypes(settings, fileName, null); var baseName = fileName.ToLowerInvariant(); if (!string.IsNullOrEmpty(baseName)) { var pPos = fileName.LastIndexOf('.'); if (pPos > -1 && pPos < fileName.Length - 1) { var possibleCulture = fileName.Substring(pPos + 1); if (!string.IsNullOrEmpty(possibleCulture)) { if (IsValidCultureName(possibleCulture)) { cultureString = fileName.Substring(pPos + 1); } } } } } return cultureString; }
//CHANGED extract language string inside next to last point delimited part //returns culture string like de-DE or null or empty if neutral file guessed public static string GetBaseName( IInheritedSettings settings, string fileName ) { return extractBlock(settings, fileName, PhBasename); }
public static string GetExtension( IInheritedSettings settings, string fileName ) { return extractBlock(settings, fileName, PhExtension); }
public static bool IsNeutralLanguageFileName( IInheritedSettings settings, string filePath) { //CHANGED just invert decision return !IsNonNeutralLanguageFileName(settings, filePath); }
public static bool IsNonNeutralLanguageFileName( IInheritedSettings settings, string filePath) { var fn = ZlpPathHelper.GetFileNameFromFilePath(filePath); var baseDotCount = settings == null ? 0 : settings.EffectiveBaseNameDotCount; //CHANGED: special case if settings.EffectiveBaseNameDotCount < 0, guess culture from name: if (settings == null || baseDotCount <= 0) { var cultureString = GetLanguageCodeFromFileNameSuffix(settings, filePath); return !string.IsNullOrEmpty(cultureString); } else { var nonNeutralDotCount = getDotCount(settings.EffectiveNonNeutralLanguageFileNamePattern); var dc = getDotCount(fn); return dc == nonNeutralDotCount + baseDotCount; } }
private static DataTable removeUnusedColumns( PreparedInformation preparedInformation, IInheritedSettings settings, DataTable table) { var result = new DataTable(); // -- // Columns. // Order: // 1. The filegroup checksum column. // 2. The name column. // 3. The reference language column. // 4. All other columns. // 5. The comment column. // 1. result.Columns.Add(table.Columns[0].ColumnName, typeof(string)); // 2. result.Columns.Add(table.Columns[1].ColumnName, typeof(string)); // 3. foreach (DataColumn column in table.Columns) { // Column 0=FileGroup checksum, column 1=Tag name. if (column.Ordinal != 0 && column.Ordinal != 1) { var languageCode = IsFileName(column.ColumnName) ? new LanguageCodeDetection(preparedInformation.Project).DetectLanguageCodeFromFileName( settings, column.ColumnName) : column.ColumnName; if (string.Compare(preparedInformation.ReferenceLanguageCode, languageCode, StringComparison.OrdinalIgnoreCase) == 0) { result.Columns.Add(column.ColumnName); break; } } } // 4. foreach (DataColumn column in table.Columns) { // Column 0=FileGroup checksum, column 1=Tag name. if (column.Ordinal != 0 && column.Ordinal != 1) { var languageCode = IsFileName(column.ColumnName) ? new LanguageCodeDetection(preparedInformation.Project).DetectLanguageCodeFromFileName( settings, column.ColumnName) : column.ColumnName; if (string.Compare(preparedInformation.ReferenceLanguageCode, languageCode, StringComparison.OrdinalIgnoreCase) != 0) { if (wantExportLanguageCode(preparedInformation, languageCode)) { result.Columns.Add(column.ColumnName); } } } } // 5. if (preparedInformation.ExportCommentColumn) { result.Columns.Add(table.Columns[table.Columns.Count - 1].ColumnName, typeof(string)); } // -- // Rows. foreach (DataRow sourceRow in table.Rows) { var destinationRow = result.NewRow(); foreach (DataColumn column in result.Columns) { destinationRow[column.ColumnName] = sourceRow[column.ColumnName]; } result.Rows.Add(destinationRow); } // -- return(result); }
private static string removeOptionalDefaultTypes( IInheritedSettings settings, string fileName, ICollection<string> removedTypes) { if (settings == null || string.IsNullOrEmpty(fileName)) { return fileName; } else { var odfts = settings.EffectiveDefaultFileTypesToIgnoreArray; if (odfts.Length > 0) { foreach (var odft in odfts) { var p = string.Format( @"\b({0})\b", Regex.Escape(odft)); var before = fileName; fileName = Regex.Replace(fileName, p, string.Empty, RegexOptions.IgnoreCase); if (fileName != before && removedTypes != null) { removedTypes.Add(odft); } } return fileName; } else { return fileName; } } }
private static string extractBlock( IInheritedSettings settings, string text, string after) { if (string.IsNullOrEmpty(text)) { return text; //no suffix found } else { // Bug_ when no project loaded, therefore create. if (settings == null) { settings = Project.Empty; } var patternOrigin = IsNonNeutralLanguageFileName(settings, text) ? settings.EffectiveNonNeutralLanguageFileNamePattern : settings.EffectiveNeutralLanguageFileNamePattern; var optionalTypes = new List<string>(); text = removeOptionalDefaultTypes(settings, text, optionalTypes); if (after == PhOptionaltypes) { return (optionalTypes.Count > 0 ? optionalTypes[0] : null) ?? string.Empty; } //remove pattern: patternOrigin = patternOrigin.Replace(PhOptionaltypes, string.Empty); if (!patternOrigin.Contains(after)) { if (after == PhLanguagecode) { //special case neutral cuture return settings.EffectiveNeutralLanguageCode; } } var pattern = patternOrigin; var block = text; string leftBlock; string rightBlock; string leftPattern; string rightPattern; //trim right while (!string.IsNullOrEmpty(block) && !string.IsNullOrEmpty(pattern) && pattern.Contains(after)) { splitBlockRight(pattern, @".", out leftPattern, out rightPattern); splitBlockRight(block, @".", out leftBlock, out rightBlock); if (rightPattern == PhBasename) { //we must trim from left now because basename may expand multiple blocks break; } if (rightPattern == after) { //we are done return rightBlock; } pattern = leftPattern; block = leftBlock; } //trim left while (!string.IsNullOrEmpty(block) && !string.IsNullOrEmpty(pattern) && pattern.Contains(after)) { splitBlockLeft(pattern, @".", out leftPattern, out rightPattern); splitBlockLeft(block, @".", out leftBlock, out rightBlock); if (leftPattern == after) { if (leftPattern == PhBasename && string.IsNullOrEmpty(rightPattern)) { //return remaining block return block; } //we are done return leftBlock; } pattern = rightPattern; block = rightBlock; } //if we gets here, we have problems with pattern. throw new ArgumentException( string.Format( Resources.SR_LanguageCodeDetection_extractBlock_PatternDoesNotMatch, after, patternOrigin, text)); } }
public bool IsNeutralCulture( IInheritedSettings settings, CultureInfo culture) { return culture == MakeValidCulture( settings.EffectiveNeutralLanguageCode); }
private int getDestinationTableColumnIndex( IInheritedSettings settings, DataTable dataTable, string languageCode) { var columnIndex = 0; foreach (DataColumn column in dataTable.Columns) { if (columnIndex > 1) // Column 0=FileGroup checksum, column 1=Tag name. { var lc = ExcelExportController.IsFileName(column.ColumnName) ? new LanguageCodeDetection( _information.Project) .DetectLanguageCodeFromFileName( settings, column.ColumnName) : column.ColumnName; if (string.Compare(lc, languageCode, StringComparison.OrdinalIgnoreCase) == 0) { return column.Ordinal; } } columnIndex++; } // -- // 2011-01-24, Uwe Keim: No direct (like "en-US") found, try fuzzy (like "en"). columnIndex = 0; foreach (DataColumn column in dataTable.Columns) { if (columnIndex > 1) // Column 0=FileGroup checksum, column 1=Tag name. { var lc = ExcelExportController.IsFileName(column.ColumnName) ? new LanguageCodeDetection( _information.Project) .DetectLanguageCodeFromFileName( settings, column.ColumnName) : column.ColumnName; if (lc.StartsWith(languageCode, StringComparison.InvariantCultureIgnoreCase)) { return column.Ordinal; } } columnIndex++; } // -- return -1; }
private static bool wantExportRow( SnapshotController ssc, PreparedInformation preparedInformation, IInheritedSettings settings, DataRow row, CommentVisibilityScope commentVisibilityScope) { if (FileGroup.IsCompleteRowEmpty(row) && !preparedInformation.ExportCompletelyEmptyRows || // http://www.codeproject.com/KB/aspnet/ZetaResourceEditor.aspx?msg=3367544#xx3367544xx) FileGroup.IsInternalRow(row)) { return(false); } if (preparedInformation.OnlyExportRowsWithNoTranslation) { var emptyCount = 0; // ReSharper disable LoopCanBeConvertedToQuery foreach (DataColumn column in row.Table.Columns) // ReSharper restore LoopCanBeConvertedToQuery { // Column 0=FileGroup checksum, column 1=Tag name. if (column.Ordinal != 0 && column.Ordinal != 1 && !isCommentColumn(column)) { var languageCode = IsFileName(column.ColumnName) ? new LanguageCodeDetection(preparedInformation.Project).DetectLanguageCodeFromFileName( settings, column.ColumnName) : column.ColumnName; if (string.Compare(languageCode, preparedInformation.ReferenceLanguageCode, StringComparison.OrdinalIgnoreCase) != 0) { if (ConvertHelper.ToString(row[column], string.Empty).Trim().Length <= 0) { emptyCount++; } } } } if (preparedInformation.Project.EnableExcelExportSnapshots) { return(emptyCount > 0 || preparedInformation.OnlyExportRowsWithChangedTexts && hasChangedTextSinceLastExport(ssc, preparedInformation, settings, row)); } else { return(emptyCount > 0); } } else { if (preparedInformation.Project.EnableExcelExportSnapshots) { return(!preparedInformation.OnlyExportRowsWithChangedTexts || hasChangedTextSinceLastExport(ssc, preparedInformation, settings, row)); } else { return(true); } } }