public virtual void UpdateCatalog(TranslationProject project, Catalog catalog, ProgressMonitor monitor, string fileName)
{
string text = File.ReadAllText(fileName);
string relativeFileName = MonoDevelop.Core.FileService.AbsoluteToRelativePath(project.BaseDirectory, fileName);
string fileNamePrefix = relativeFileName + ":";
if (String.IsNullOrEmpty(text))
{
return;
}
// Get a list of all excluded regions
List <Match> excludeMatches = new List <Match> ();
foreach (Regex regex in excluded)
{
foreach (Match m in regex.Matches(text))
{
excludeMatches.Add(m);
}
}
// Sort the list by match index
excludeMatches.Sort(delegate(Match a, Match b) {
return(a.Index.CompareTo(b.Index));
});
// Remove from the list all regions which start in an excluded region
int pos = 0;
for (int n = 0; n < excludeMatches.Count; n++)
{
Match m = excludeMatches [n];
if (m.Index < pos)
{
excludeMatches.RemoveAt(n);
n--;
}
else
{
pos = m.Index + m.Length;
}
}
foreach (RegexInfo ri in regexes)
{
int lineNumber = 0;
int oldIndex = 0;
foreach (Match match in ri.Regex.Matches(text))
{
// Ignore matches inside excluded regions
bool ignore = false;
foreach (Match em in excludeMatches)
{
if (match.Index >= em.Index && match.Index < em.Index + em.Length)
{
ignore = true;
LoggingService.LogDebug("Excluded Gettext string '{0}' in file '{1}'", match.Groups[ri.ValueGroupIndex].Value, fileName);
break;
}
}
if (ignore)
{
continue;
}
string mt = match.Groups[ri.ValueGroupIndex].Value;
if (mt.Length == 0)
{
continue;
}
foreach (TransformInfo ti in transforms)
{
mt = ti.Regex.Replace(mt, ti.ReplaceText);
}
try {
mt = StringEscaping.UnEscape(ri.EscapeMode, mt);
} catch (FormatException fex) {
monitor.ReportWarning("Error unescaping string '" + mt + "': " + fex.Message);
continue;
}
if (mt.Trim().Length == 0)
{
continue;
}
//get the plural string if it's a plural form and apply transforms
string pt = ri.PluralGroupIndex != -1 ? match.Groups[ri.PluralGroupIndex].Value : null;
if (pt != null)
{
foreach (TransformInfo ti in transforms)
{
pt = ti.Regex.Replace(pt, ti.ReplaceText);
}
}
//add to the catalog
CatalogEntry entry = catalog.AddItem(mt, pt);
lineNumber += GetLineCount(text, oldIndex, match.Index);
oldIndex = match.Index;
entry.AddReference(fileNamePrefix + lineNumber);
}
}
}