Author: mkrueger
Date: 2007-07-19 01:37:57 -0400 (Thu, 19 Jul 2007)
New Revision: 82265
Modified:
trunk/monodevelop/Extras/MonoDevelop.Gettext/ChangeLog
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext.Editor/CatalogEntry.cs
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext.Editor/POEditorWidget.cs
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext/TranslationProject.cs
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext/TranslationService.cs
Log:
* MonoDevelop.Gettext.Editor/CatalogEntry.cs,
MonoDevelop.Gettext.Editor/POEditorWidget.cs,
MonoDevelop.Gettext/TranslationService.cs,
MonoDevelop.Gettext/TranslationProject.cs: Improved reference
update code. Fixed comment handling and some translation editor
behavior issues.
Modified: trunk/monodevelop/Extras/MonoDevelop.Gettext/ChangeLog
===================================================================
--- trunk/monodevelop/Extras/MonoDevelop.Gettext/ChangeLog 2007-07-19
02:35:08 UTC (rev 82264)
+++ trunk/monodevelop/Extras/MonoDevelop.Gettext/ChangeLog 2007-07-19
05:37:57 UTC (rev 82265)
@@ -1,3 +1,12 @@
+2007-07-19 Mike Krüger <[EMAIL PROTECTED]>
+
+ * MonoDevelop.Gettext.Editor/CatalogEntry.cs,
+ MonoDevelop.Gettext.Editor/POEditorWidget.cs,
+ MonoDevelop.Gettext/TranslationService.cs,
+ MonoDevelop.Gettext/TranslationProject.cs: Improved reference
+ update code. Fixed comment handling and some translation editor
+ behavior issues.
+
2007-07-18 Mike Krüger <[EMAIL PROTECTED]>
* MonoDevelop.Gettext.Editor/CatalogEntry.cs,
Modified:
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext/TranslationProject.cs
===================================================================
---
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext/TranslationProject.cs
2007-07-19 02:35:08 UTC (rev 82264)
+++
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext/TranslationProject.cs
2007-07-19 05:37:57 UTC (rev 82265)
@@ -83,25 +83,62 @@
return Path.Combine (base.BaseDirectory, isoCode +
".po");
}
- public void AddTranslationString (string originalString, string
fileName, int lineNr)
+ public class MatchLocation
{
- AddTranslationString (originalString, null, fileName,
lineNr);
+ string originalString;
+ string originalPluralString;
+ int line;
+
+ public string OriginalString {
+ get { return originalString; }
+ }
+
+ public string OriginalPluralString {
+ get { return originalPluralString; }
+ }
+
+ public int Line {
+ get { return line; }
+ }
+
+ public MatchLocation (string originalString, string
originalPluralString, int line)
+ {
+ this.originalString = originalString;
+ this.originalPluralString =
originalPluralString;
+ this.line = line;
+ }
+
+ public MatchLocation (string originalString, int line)
: this (originalString, null, line)
+ {
+ }
}
- public void AddTranslationString (string originalString, string
originalPluralString, string fileName, int lineNr)
+ public void AddTranslationStrings (string fileName,
List<TranslationProject.MatchLocation> matches)
{
+ string relativeFileName =
MonoDevelop.Core.Runtime.FileService.AbsoluteToRelativePath
(this.BaseDirectory, fileName);
foreach (Translation translation in this.Translations) {
string poFileName = GetFileName (translation);
Catalog catalog = new Catalog (poFileName);
- if (catalog.FindItem (originalString) == null) {
- CatalogEntry newEntry = new
CatalogEntry (catalog, originalString, originalPluralString);
-
- newEntry.AddReference
(MonoDevelop.Core.Runtime.FileService.AbsoluteToRelativePath
(this.BaseDirectory, fileName) + ":" + lineNr);
- if (!String.IsNullOrEmpty
(originalPluralString))
- newEntry.SetTranslations (new
string[] {"", ""});
- catalog.AddItem (newEntry);
- catalog.Save (poFileName);
+
+ foreach (CatalogEntry entry in catalog) {
+ foreach (string reference in
entry.References) {
+ if (reference.StartsWith
(relativeFileName + ":"))
+ entry.RemoveReference
(reference);
+ }
}
+
+ foreach (MatchLocation match in matches) {
+ CatalogEntry entry = catalog.FindItem
(match.OriginalString);
+ if (entry == null) {
+ entry = new CatalogEntry
(catalog, match.OriginalString, match.OriginalPluralString);
+ if (!String.IsNullOrEmpty
(match.OriginalPluralString))
+ entry.SetTranslations
(new string[] {"", ""});
+ catalog.AddItem (entry);
+ }
+ entry.AddReference (relativeFileName +
":" + match.Line);
+ }
+
+ catalog.Save (poFileName);
}
}
Modified:
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext/TranslationService.cs
===================================================================
---
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext/TranslationService.cs
2007-07-19 02:35:08 UTC (rev 82264)
+++
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext/TranslationService.cs
2007-07-19 05:37:57 UTC (rev 82265)
@@ -27,6 +27,7 @@
//
using System;
+using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
@@ -85,9 +86,11 @@
{
string text = File.ReadAllText (fileName);
if (!String.IsNullOrEmpty (text)) {
+ List<TranslationProject.MatchLocation> matches
= new List<TranslationProject.MatchLocation> ();
foreach (Match match in
xmlTranslationPattern.Matches (text)) {
- translationProject.AddTranslationString
(match.Groups[1].Value, fileName, GetLineNumber (text, match.Index));
+ matches.Add (new
TranslationProject.MatchLocation (match.Groups[1].Value, GetLineNumber (text,
match.Index)));
}
+ translationProject.AddTranslationStrings
(fileName, matches);
}
}
@@ -96,9 +99,11 @@
{
string text = File.ReadAllText (fileName);
if (!String.IsNullOrEmpty (text)) {
+ List<TranslationProject.MatchLocation> matches
= new List<TranslationProject.MatchLocation> ();
foreach (Match match in
steticTranslationPattern.Matches (text)) {
- translationProject.AddTranslationString
(match.Groups[1].Value, fileName, GetLineNumber (text, match.Index));
+ matches.Add (new
TranslationProject.MatchLocation (match.Groups[1].Value, GetLineNumber (text,
match.Index)));
}
+ translationProject.AddTranslationStrings
(fileName, matches);
}
}
@@ -109,13 +114,14 @@
{
string text = File.ReadAllText (fileName);
if (!String.IsNullOrEmpty (text)) {
- Console.WriteLine ("find matches");
+ List<TranslationProject.MatchLocation> matches
= new List<TranslationProject.MatchLocation> ();
foreach (Match match in
translationPattern.Matches (text)) {
- translationProject.AddTranslationString
(match.Groups[1].Value, fileName, GetLineNumber (text, match.Index));
+ matches.Add (new
TranslationProject.MatchLocation (match.Groups[1].Value, GetLineNumber (text,
match.Index)));
}
foreach (Match match in
pluralTranslationPattern.Matches (text)) {
- translationProject.AddTranslationString
(match.Groups[1].Value, match.Groups[2].Value, fileName, GetLineNumber (text,
match.Index));
+ matches.Add (new
TranslationProject.MatchLocation (match.Groups[1].Value, match.Groups[2].Value,
GetLineNumber (text, match.Index)));
}
+ translationProject.AddTranslationStrings
(fileName, matches);
}
}
Modified:
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext.Editor/CatalogEntry.cs
===================================================================
---
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext.Editor/CatalogEntry.cs
2007-07-19 02:35:08 UTC (rev 82264)
+++
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext.Editor/CatalogEntry.cs
2007-07-19 05:37:57 UTC (rev 82265)
@@ -130,8 +130,7 @@
}
// Returns array of all occurences of this string in source code.
- public string[] References
- {
+ public string[] References {
get { return references.ToArray (); }
}
@@ -139,10 +138,11 @@
public string Comment
{
get { return comment; }
- set
- {
- comment = value;
- MarkOwnerDirty ();
+ set {
+ if (comment != value) {
+ comment = value;
+ MarkOwnerDirty ();
+ }
}
}
@@ -170,6 +170,12 @@
{
references.Clear ();
}
+
+ public void RemoveReference (string reference)
+ {
+ if (references.Contains (reference))
+ references.Remove (reference);
+ }
// Sets the string.
public void SetString (string str)
@@ -190,10 +196,13 @@
{
while (index >= translations.Count)
translations.Add (String.Empty);
- translations[index] = translation;
+
+ if (translations[index] != translation) {
+ translations[index] = translation;
- validity = Validity.Unknown;
- MarkOwnerDirty ();
+ validity = Validity.Unknown;
+ MarkOwnerDirty ();
+ }
}
// Sets all translations.
Modified:
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext.Editor/POEditorWidget.cs
===================================================================
---
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext.Editor/POEditorWidget.cs
2007-07-19 02:35:08 UTC (rev 82264)
+++
trunk/monodevelop/Extras/MonoDevelop.Gettext/MonoDevelop.Gettext.Editor/POEditorWidget.cs
2007-07-19 05:37:57 UTC (rev 82265)
@@ -117,16 +117,27 @@
};
this.textviewTranslated.Buffer.Changed += delegate {
+ if (this.isUpdating)
+ return;
this.currentEntry.SetTranslation
(textviewTranslated.Buffer.Text, 0);
UpdateProgressBar ();
};
this.textviewTranslatedPlural.Buffer.Changed +=
delegate {
+ if (this.isUpdating)
+ return;
this.currentEntry.SetTranslation
(textviewTranslatedPlural.Buffer.Text, 1);
UpdateProgressBar ();
};
this.textviewComments.Buffer.Changed += delegate {
- this.currentEntry.Comment =
textviewComments.Buffer.Text;
+ if (this.isUpdating)
+ return;
+ string[] lines =
textviewComments.Buffer.Text.Split (new string[] {Environment.NewLine },
StringSplitOptions.None);
+ for (int i = 0; i < lines.Length; i++) {
+ if (!lines[i].StartsWith ("#"))
+ lines[i] = "# " + lines[i];
+ }
+ this.currentEntry.Comment = String.Join
(Environment.NewLine, lines);
UpdateProgressBar ();
};
}
@@ -148,33 +159,38 @@
void EditEntry (CatalogEntry entry)
{
- currentEntry = entry;
- this.textviewOriginal.Buffer.Text = entry.String;
- this.textviewTranslated.Buffer.Text =
entry.GetTranslation (0);
-
- frameOriginalPlural.Visible =
frameTranslatedPlural.Visible = entry.HasPlural;
-
- if (entry.HasPlural) {
- this.textviewOriginalPlural.Buffer.Text =
entry.PluralString;
- this.textviewTranslatedPlural.Buffer.Text =
entry.GetTranslation (1);
- }
-
- this.foundInStore.Clear ();
- foreach (string reference in entry.References) {
- string file;
- string line;
- int i = reference.IndexOf (':');
- if (i >= 0) {
- file = reference.Substring (0, i);
- line = reference.Substring (i + 1);
- } else {
- file = reference;
- line = "?";
+ this.isUpdating = true;
+ try {
+ currentEntry = entry;
+ this.textviewOriginal.Buffer.Text =
entry.String;
+ this.textviewTranslated.Buffer.Text =
entry.GetTranslation (0);
+
+ frameOriginalPlural.Visible =
frameTranslatedPlural.Visible = entry.HasPlural;
+
+ if (entry.HasPlural) {
+ this.textviewOriginalPlural.Buffer.Text
= entry.PluralString;
+
this.textviewTranslatedPlural.Buffer.Text = entry.GetTranslation (1);
}
- string fullName = System.IO.Path.Combine
(System.IO.Path.GetDirectoryName (this.poFileName), file);
- this.foundInStore.AppendValues (file, line,
fullName);
+
+ this.foundInStore.Clear ();
+ foreach (string reference in entry.References) {
+ string file;
+ string line;
+ int i = reference.IndexOf (':');
+ if (i >= 0) {
+ file = reference.Substring (0,
i);
+ line = reference.Substring (i +
1);
+ } else {
+ file = reference;
+ line = "?";
+ }
+ string fullName =
System.IO.Path.Combine (System.IO.Path.GetDirectoryName (this.poFileName),
file);
+ this.foundInStore.AppendValues (file,
line, fullName);
+ }
+ this.textviewComments.Buffer.Text =
entry.Comment;
+ } finally {
+ this.isUpdating = false;
}
- this.textviewComments.Buffer.Text = entry.Comment;
}
#endregion
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches