Esempio n. 1
0
 /// <summary>TODO: comment</summary>
 public void SaveChanges(bool fireTranslationChanged)
 {
     if (AnyChanges)
     {
         Lingo.SaveTranslation(_translationType, _moduleName, _translation);
         if (fireTranslationChanged && TranslationChanged != null)
         {
             TranslationChanged(Lingo.LoadTranslation(_translationType, _moduleName, _language));
         }
         _anyChanges = false;
     }
 }
Esempio n. 2
0
        /// <summary>Main constructor.</summary>
        /// <param name="translationType">The type containing the <see cref="TrString"/> and <see cref="TrStringNum"/> fields to be translated.</param>
        /// <param name="settings">Settings of the <see cref="TranslationWindow"/>.</param>
        /// <param name="icon">Application icon to use.</param>
        /// <param name="programTitle">Title of the program. Used in the title bar.</param>
        /// <param name="moduleName">Used for locating the translation file to be edited under the Translations directory.</param>
        /// <param name="language">The language to be edited.</param>
        public TranslationWindow(Type translationType, Settings settings, ImageSource icon, string programTitle, string moduleName, Language language)
            : base(settings)
        {
            InitializeComponent();

            _translationType = translationType;
            _moduleName      = moduleName;
            _language        = language;

            if (icon != null)
            {
                Icon = icon;
            }
            Title = "Translating " + programTitle;

            CommandBindings.Add(new CommandBinding(TranslationCommands.SaveAndApply, delegate { SaveChanges(true); }));
            CommandBindings.Add(new CommandBinding(TranslationCommands.Close, delegate { Close(); }));
            CommandBindings.Add(new CommandBinding(TranslationCommands.Find, find));
            CommandBindings.Add(new CommandBinding(TranslationCommands.FindNext, findNext));
            CommandBindings.Add(new CommandBinding(TranslationCommands.FindPrevious, findPrevious));
            CommandBindings.Add(new CommandBinding(TranslationCommands.GotoNextOutOfDateString, gotoNextOutOfDateString));
            CommandBindings.Add(new CommandBinding(TranslationCommands.MarkCurrentStringOutOfDate, markCurrentStringOutOfDate));
            CommandBindings.Add(new CommandBinding(TranslationCommands.MarkAllStringsOutOfDate, markAllStringsOutOfDate));
            CommandBindings.Add(new CommandBinding(TranslationCommands.MarkAllStringsUpToDate, markAllStringsUpToDate));
            CommandBindings.Add(new CommandBinding(TranslationCommands.Font, font));

            CommandBindings.Add(new CommandBinding(TranslationCommands.PrevTextBox, delegate { gotoTextBox(up: true); }));
            CommandBindings.Add(new CommandBinding(TranslationCommands.NextTextBox, delegate { gotoTextBox(up: false); }));
            CommandBindings.Add(new CommandBinding(TranslationCommands.PrevGroup, delegate { gotoGroup(up: true); }));
            CommandBindings.Add(new CommandBinding(TranslationCommands.NextGroup, delegate { gotoGroup(up: false); }));

            var original = (TranslationBase)Activator.CreateInstance(translationType);

            _translation = Lingo.LoadTranslation(translationType, moduleName, language);

            foreach (var group in TranslationDialogHelper.GetGroups(translationType, original, _translation))
            {
                _groups.Add(group);
            }

            ctGroups.Items.Clear();
            ctGroups.ItemsSource = _groups;
        }
Esempio n. 3
0
 /// <summary>Changes the currently selected language in exactly the same way as using one of the UI elements would.</summary>
 /// <param name="language">The desired language. If not available, the default language will be set instead.</param>
 public void SetLanguage(Language language)
 {
     TranslationChanged(language == _defaultLanguage ? new TTranslation() : Lingo.LoadTranslationOrDefault <TTranslation>(_moduleName, ref language));
 }
Esempio n. 4
0
        /// <summary>
        /// Returns a list of UI control descriptors whose state is applicable at the time of invocation. This method should be invoked
        /// every time prior to displaying UI, to obtain the up-to-date UI state. The entries returned are not "live" and will not be updated
        /// to reflect any changes.
        /// </summary>
        /// <remarks>
        /// The list is guaranteed to have at least one item, the default language. Exactly one item will have <see cref="Entry.IsCurrentLanguage"/> set to true.
        /// </remarks>
        protected List <Entry> ListCurrentEntries()
        {
            // Enumerate available languages
            var result          = new List <Entry>();
            var defaultLanguage = new Entry(this, _defaultLanguage);

            result.Add(defaultLanguage);
            var path = PathUtil.AppPathCombine("Translations");

            if (Directory.Exists(path))
            {
                foreach (var file in new DirectoryInfo(path).GetFiles(_moduleName + ".*.xml"))
                {
                    Match match = Regex.Match(file.Name, "^" + Regex.Escape(_moduleName) + @"\.(.*)\.xml$");
                    if (!match.Success)
                    {
                        continue;
                    }
                    var l = Lingo.LanguageFromIsoCode(match.Groups[1].Value);
                    if (l == null)
                    {
                        continue;
                    }
                    result.Add(new Entry(this, l.Value));
                }
                result.Sort((l1, l2) => l1.Language.Value.GetNativeName().CompareTo(l2.Language.Value.GetNativeName()));
            }

            // Remove the English variant suffix if only one such language
            var english = result.Where(e => e.Text.StartsWith("English ")).ToArray();

            if (english.Length == 1)
            {
                english[0].Text = "English";
            }

            // Mark the current language as checked
            (result.SingleOrDefault(e => e.Language == _getCurrentLanguage()) ?? defaultLanguage).IsCurrentLanguage = true;

            // Add the editing UI
            Entry editEntry = null;

            if (_editable)
            {
                result.Add(editEntry = new Entry("&Edit current language", EditCurrentLanguage)
                {
                    SeparatorBefore = true
                });
                result.Add(new Entry("&Create new language", CreateNewLanguage));
            }

            // Disable most items if a translation dialog is currently visible
            if (TranslationDialog != null)
            {
                foreach (var entry in result)
                {
                    if (entry != editEntry)
                    {
                        entry.Enabled = false;
                    }
                }
            }

            return(result);
        }