protected override bool OnEntry(string msgid, string msgidPlural, bool hasPlural, string[] translations, string flags, string[] references, string comment, string[] autocomments) { if (String.IsNullOrEmpty(msgid) && !headerParsed) { // gettext header: catalog.ParseHeaderString(translations[0]); catalog.Comment = comment; headerParsed = true; } else { CatalogEntry d = new CatalogEntry(catalog, String.Empty, String.Empty); if (!String.IsNullOrEmpty(flags)) { d.Flags = flags; } d.SetString(msgid); if (hasPlural) { d.SetPluralString(msgidPlural); } d.SetTranslations(translations); d.Comment = comment; for (uint i = 0; i < references.Length; i++) { d.AddReference(references[i]); } for (uint i = 0; i < autocomments.Length; i++) { d.AddAutoComment(autocomments[i]); } catalog.AddItem(d); } return(true); }
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); } } }