Exemple #1
0
 public void RemoveEntry(string msgstr)
 {
     foreach (Translation translation in this.Translations)
     {
         string  poFileName = translation.PoFile;
         Catalog catalog    = new Catalog(this);
         catalog.Load(new MonoDevelop.Core.ProgressMonitor(), poFileName);
         CatalogEntry entry = catalog.FindItem(msgstr);
         if (entry != null)
         {
             catalog.RemoveItem(entry);
             catalog.Save(poFileName);
         }
     }
 }
        public CatalogEntry (Catalog owner, CatalogEntry dt)
		{
			this.owner = owner;
			str = dt.str;
			plural = dt.plural;
			hasPlural = dt.hasPlural;
			translations = new List<string> (dt.translations);
			references = new List<string> (dt.references);
			autocomments = new List<string> (dt.autocomments);
			isFuzzy = dt.isFuzzy;
			isModified = dt.isModified;
			isAutomatic = dt.isAutomatic;
            hasBadTokens = dt.hasBadTokens;
            moreFlags =dt.moreFlags;
            comment = dt.comment;
            validity = dt.validity;
            errorString = dt.errorString;
        }
Exemple #3
0
 public CatalogEntry(Catalog owner, CatalogEntry dt)
 {
     this.owner   = owner;
     str          = dt.str;
     plural       = dt.plural;
     hasPlural    = dt.hasPlural;
     translations = new List <string> (dt.translations);
     references   = new List <string> (dt.references);
     autocomments = new List <string> (dt.autocomments);
     isFuzzy      = dt.isFuzzy;
     isModified   = dt.isModified;
     isAutomatic  = dt.isAutomatic;
     hasBadTokens = dt.hasBadTokens;
     moreFlags    = dt.moreFlags;
     comment      = dt.comment;
     validity     = dt.validity;
     errorString  = dt.errorString;
 }
Exemple #4
0
 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);
 }
Exemple #5
0
		public void UpdateEntry (CatalogEntry entry)
		{	
			TreeIter iter, foundIter = TreeIter.Zero;
			
			// Look if selected is the same - only wanted usecase
			if (treeviewEntries.Selection.GetSelected (out iter)) {
				CatalogEntry storeEntry = store.GetValue (iter, (int)Columns.CatalogEntry) as CatalogEntry;
				if (entry.Equals (storeEntry))
					foundIter = iter;
			}
						
			// Update data
			if (foundIter.Stamp != TreeIter.Zero.Stamp) {
				store.SetValue (foundIter, (int)Columns.Fuzzy, entry.IsFuzzy);
				store.SetValue (foundIter, (int)Columns.Stock, GetStockForEntry (entry));
				store.SetValue (foundIter, (int)Columns.RowColor, GetRowColorForEntry (entry));
				store.SetValue (foundIter, (int)Columns.ForeColor, GetForeColorForEntry (entry));
			}
		}
Exemple #6
0
		public void SelectEntry (CatalogEntry entry)
		{
//			if (updateThread.IsBusy)
//				return;
			
			TreeIter iter;
			if (store.GetIterFirst (out iter)) {
				do {
					CatalogEntry curEntry = store.GetValue (iter, 4) as CatalogEntry;
					if (entry == curEntry) {
						this.treeviewEntries.Selection.SelectIter (iter);
						TreePath iterPath = store.GetPath (iter);
						if (!IsVisible (iterPath))
							this.treeviewEntries.ScrollToCell (iterPath, treeviewEntries.GetColumn (0), true, 0, 0);
						return;
					}
				} while (store.IterNext (ref iter));
			}
			store.AppendValues (GetStockForEntry (entry), 
			                    entry.IsFuzzy,
			                    EscapeForTreeView (entry.String), 
			                    EscapeForTreeView (entry.GetTranslation (0)), 
			                    entry,
			                    GetRowColorForEntry (entry),
			                    GetTypeSortIndicator (entry),
			                    GetForeColorForEntry (entry)
			);
			SelectEntry (entry);
		}
Exemple #7
0
		static int GetTypeSortIndicator (CatalogEntry entry)
		{
			return entry.IsFuzzy ? 1 : entry.IsTranslated ? 0 : 2;
		}
Exemple #8
0
		Color GetRowColorForEntry (CatalogEntry entry)
		{
			if (entry.References.Length == 0)
				return missing;
			return entry.IsFuzzy ? fuzzy : entry.IsTranslated ? Style.Base (StateType.Normal) : untranslated;
		}
Exemple #9
0
		void EditEntry (CatalogEntry entry)
		{
			this.isUpdating = true;
			try {
				currentEntry = entry;
				this.texteditorOriginal.Caret.Location = new DocumentLocation (1, 1);
				this.texteditorOriginal.Document.Text = entry != null ? entry.String : "";
				this.texteditorOriginal.VAdjustment.Value = this.texteditorOriginal.HAdjustment.Value = 0;
				
//				if (GtkSpell.IsSupported && !gtkSpellSet.ContainsKey (this.textviewOriginal)) {
//					GtkSpell.Attach (this.textviewOriginal, "en");
//					this.gtkSpellSet[this.textviewOriginal] = true;
//				}
//				
				this.vbox8.Visible = entry != null && entry.HasPlural;
				this.notebookTranslated.ShowTabs = entry != null && entry.HasPlural;
				
				if (entry != null && entry.HasPlural) {
					this.texteditorPlural.Caret.Location = new DocumentLocation (1, 1);
					this.texteditorPlural.Document.Text = entry.PluralString;
					this.texteditorPlural.VAdjustment.Value = this.texteditorPlural.HAdjustment.Value = 0;
//					if (GtkSpell.IsSupported && !gtkSpellSet.ContainsKey (this.textviewOriginalPlural)) {
//						GtkSpell.Attach (this.textviewOriginalPlural, "en");
//						this.gtkSpellSet[this.textviewOriginalPlural] = true;
//					}
				}
				
				this.foundInStore.Clear ();
				
				if (entry != null) { 
					RemoveTextViewsFrom (entry.NumberOfTranslations);
					
					for (int i = this.notebookTranslated.NPages; i < entry.NumberOfTranslations; i++) {
						AddTextview (i);
					}
					
					for (int i = 0; i < entry.NumberOfTranslations; i++) {
						Mono.TextEditor.TextEditor textView = GetTextView (i);
						if (textView == null)
							continue;
						textView.ClearSelection ();
						textView.Document.Text = entry != null ?  entry.GetTranslation (i) : "";
						textView.Caret.Offset = textView.Document.Text.Length;
						textView.VAdjustment.Value = textView.HAdjustment.Value = 0;
						textView.Document.CommitUpdateAll ();
					}
					
					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, DesktopService.GetIconForFile (fullName, IconSize.Menu));
					}
				}
				
				this.textviewComments.Buffer.Text = entry != null ?  entry.Comment : null;
				
/*				if (GtkSpell.IsSupported) {
					foreach (TextView view in this.gtkSpellSet.Keys)
						GtkSpell.Recheck (view);
				}*/
			} finally {
				this.isUpdating = false;
			}
		}
Exemple #10
0
		public void AddChange (CatalogEntry entry, string oldText, string text, int index)
		{
			if (inUndoOperation)
				return;
			redoStack.Clear ();
			undoStack.Push (new Change (this, entry, oldText, text, index));
		}
Exemple #11
0
			public override string FailReason (CatalogEntry entry)
			{
				foreach (System.Text.RegularExpressions.Match match in Regex.Matches (entry.String, @"\{.\}", RegexOptions.None))  {
					if (!entry.GetTranslation (0).Contains (match.Value)) 
						return GettextCatalog.GetString ("Original string '{0}' contains '{1}', translation doesn't.", entry.String, match.Value);
				}
				return "";
			}
Exemple #12
0
        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);
                }
            }
        }
		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;
		}
Exemple #14
0
		Color GetForeColorForEntry (CatalogEntry entry)
		{
			if (entry.References.Length == 0)
				return Styles.POEditor.EntryMissingBackgroundColor;
			return entry.IsFuzzy ? Style.Black : entry.IsTranslated ? Style.Text (StateType.Normal) : Style.Black;
		}
Exemple #15
0
		static string iconMissing = "md-warning";//"md-translation-missing";
		
		Color GetRowColorForEntry (CatalogEntry entry)
		{
			if (entry.References.Length == 0)
				return Styles.POEditor.EntryMissingBackgroundColor;
			return entry.IsFuzzy ? Styles.POEditor.EntryFuzzyBackgroundColor : entry.IsTranslated ? Style.Base (StateType.Normal) : Styles.POEditor.EntryUntranslatedBackgroundColor;
		}
Exemple #16
0
			public override string FailReason (CatalogEntry entry)
			{
				if (entry.String.Contains ("_") && !entry.GetTranslation (0).Contains ("_"))
					return GettextCatalog.GetString ("Original string '{0}' contains '_', translation doesn't.", entry.String);
				return GettextCatalog.GetString ("Original string '{0}' doesn't contain '_', translation does.", entry.String);
			}
Exemple #17
0
			public override bool EntryFails (CatalogEntry entry)
			{
				foreach (System.Text.RegularExpressions.Match match in Regex.Matches (entry.String, @"\{.\}", RegexOptions.None))  {
					if (!entry.GetTranslation (0).Contains (match.Value)) 
						return true;
				}
				return false;
			}
Exemple #18
0
			public abstract bool EntryFails (CatalogEntry entry);
Exemple #19
0
			public Change (POEditorWidget widget, CatalogEntry entry, string oldText, string text, int index)
			{
				this.widget = widget;
				this.Entry = entry;
				this.OldText = oldText;
				this.Text  = text;
				this.Index = index;
			}
Exemple #20
0
			public abstract string FailReason (CatalogEntry entry);
Exemple #21
0
		void RemoveEntry (CatalogEntry entry)
		{
			bool yes = MessageService.AskQuestion (GettextCatalog.GetString ("Do you really want to remove the translation string {0} (It will be removed from all translations)?", entry.String),
			                                                            AlertButton.Cancel, AlertButton.Remove) == AlertButton.Remove;

			if (yes) {
				TranslationProject project = IdeApp.ProjectOperations.CurrentSelectedSolutionItem as TranslationProject;
				if (project != null) {
					foreach (POEditorWidget widget in widgets)
						widget.RemoveEntryByString (entry.String);
					project.RemoveEntry (entry.String);
				}
			}
		}
Exemple #22
0
			public override bool EntryFails (CatalogEntry entry)
			{
				return entry.String.EndsWith (".") && !entry.GetTranslation (0).EndsWith (".");
			}
Exemple #23
0
		static string GetStockForEntry (CatalogEntry entry)
		{
			if (entry.References.Length == 0)
				return Gtk.Stock.DialogError;
			return entry.IsFuzzy ? iconFuzzy : entry.IsTranslated ? iconValid : iconMissing;
		}
Exemple #24
0
			public override string FailReason (CatalogEntry entry)
			{
				return GettextCatalog.GetString ("Translation for '{0}' doesn't end with '.'.", entry.String);
			}
Exemple #25
0
		Color GetForeColorForEntry (CatalogEntry entry)
		{
			if (entry.References.Length == 0)
				return missing;
			return entry.IsFuzzy ? Style.Black : entry.IsTranslated ? Style.Text (StateType.Normal) : Style.Black;
		}
Exemple #26
0
			public override bool EntryFails (CatalogEntry entry)
			{
				return char.IsLetter (entry.String[0]) && char.IsLetter (entry.GetTranslation (0)[0])  &&
						char.IsUpper (entry.String[0]) && !char.IsUpper (entry.GetTranslation (0)[0]);
			}
Exemple #27
0
		bool ShouldFilter (CatalogEntry entry, string filter)
		{
			if (entry.IsFuzzy) {
				if (!this.togglebuttonFuzzy.Active) {
					return true;
				}
			} else {
				if (!entry.IsTranslated && !this.togglebuttonMissing.Active)
					return true;
				if (entry.IsTranslated && !this.togglebuttonOk.Active)
					return true;
			}
			
			if (String.IsNullOrEmpty (filter)) 
				return false;
			if (DoSearchIn != SearchIn.Translated) {
				if (IsMatch (entry.String, filter))
					return false;
				if (entry.HasPlural) {
					if (IsMatch (entry.PluralString, filter))
						return false;
				}
			}
			
			if (DoSearchIn != SearchIn.Original) {
				for (int i = 0; i < entry.NumberOfTranslations; i++) {
					if (IsMatch (entry.GetTranslation (i), filter))
						return false;
				}
			}
			return true;
		}
Exemple #28
0
			public override string FailReason (CatalogEntry entry)
			{
				return GettextCatalog.GetString ("Casing mismatch in '{0}'", entry.String);
			}
Exemple #29
0
			public TranslationTask (POEditorWidget widget, CatalogEntry entry, string description) : base (widget.poFileName,
			                                                                           description, 0, 0,
			                                                                           TaskSeverity.Error, TaskPriority.Normal, null, widget)
			{
				this.widget = widget;
				this.entry  = entry;
			}
Exemple #30
0
			public override bool EntryFails (CatalogEntry entry)
			{
				return entry.String.Contains ("_") && !entry.GetTranslation (0).Contains ("_") ||
					!entry.String.Contains ("_") && entry.GetTranslation (0).Contains ("_");
				
			}