Esempio n. 1
0
 /// <summary>Writes the specified translation for the specified module to an XML file in the application directory.</summary>
 /// <param name="translationType">Translation class to write.</param>
 /// <param name="moduleName">Name of the module for which this is a translation.</param>
 /// <param name="translation">The translation to save.</param>
 public static void SaveTranslation(Type translationType, string moduleName, TranslationBase translation)
 {
     ClassifyXml.SerializeToFile(translationType, translation, Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Translations", moduleName + "." + translation.Language.GetIsoLanguageCode() + ".xml"));
     if (AlsoSaveTranslationsTo != null && Directory.Exists(AlsoSaveTranslationsTo))
     {
         try
         {
             var filename = Path.Combine(AlsoSaveTranslationsTo, moduleName + "." + translation.Language.GetIsoLanguageCode() + ".xml");
             File.SetAttributes(filename, File.GetAttributes(filename) & ~FileAttributes.ReadOnly);
             ClassifyXml.SerializeToFile(translationType, translation, filename);
         }
         catch { }
     }
 }
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
        public static IEnumerable <TranslationGroup> GetGroups(Type type, TranslationBase original, TranslationBase translation)
        {
            var dic = new Dictionary <object, TranslationGroup>();
            TranslationGroup ungrouped = null;

            getGroups(null, type, original, translation, original.Language.GetNumberSystem(), translation.Language.GetNumberSystem(), dic, ref ungrouped, new object[0], "");
            var enumTypes  = dic.Keys.Select(k => k.GetType()).Distinct().OrderBy(t => t.Name).ToArray();
            var enumValues = enumTypes.SelectMany(t => Enum.GetValues(t).Cast <object>()).ToArray();

            foreach (var key in enumValues)
            {
                if (dic.ContainsKey(key))
                {
                    yield return(dic[key]);
                }
            }
            if (ungrouped != null)
            {
                yield return(ungrouped);
            }
        }
Esempio n. 4
0
 /// <summary>
 ///     Selects the correct string and interpolates the specified arguments.</summary>
 /// <param name="tr">
 ///     Current translation. Its language’s number system will be used to interpolate the translation.</param>
 /// <param name="args">
 ///     Arguments to be interpolated into the translation.</param>
 public string Fmt(TranslationBase tr, params object[] args)
 {
     return(Fmt(tr.Language.GetNumberSystem(), args));
 }