/// <summary>
        /// Creates all TranlatorItems with the state changed.
        /// It also saves the master language history
        /// </summary>
        private void DetermineChanged(StringArray stringsTranslated, StringArray stringsOriginal)
        {
            string filenameSaved = System.Windows.Forms.Application.LocalUserAppDataPath.Substring(0, System.Windows.Forms.Application.LocalUserAppDataPath.LastIndexOf(@"\")) + @"\strings.xml";
            string filenamePrev  = System.Windows.Forms.Application.LocalUserAppDataPath.Substring(0, System.Windows.Forms.Application.LocalUserAppDataPath.LastIndexOf(@"\")) + @"\stringsPrev.xml";

            // No history yet?
            if (!File.Exists(filenameSaved))
            {                   // Copy our master language, to have a history
                File.Copy(Settings.Instance.FilenameOriginal, filenameSaved, true);
                return;
            }

            StringArray stringsSaved = new StringArray();

            stringsSaved.Load(filenameSaved);

            // Check the version of the saved master language
            if (stringsOriginal.Version > stringsSaved.Version)
            {                   // saved is older then our current master language,
                                // update history
                File.Copy(filenameSaved, filenamePrev, true);
                File.Copy(Settings.Instance.FilenameOriginal, filenameSaved, true);
            }
            else if (stringsOriginal.Version < stringsSaved.Version)
            {             // Oh Oh, current master is older then the saved one, thow exception
                throw new TranslatorException("File " + Settings.Instance.FilenameOriginal + " is older then the one last used for this translation.");
            }

            stringsSaved.Clear();

            if (File.Exists(filenamePrev))
            {                   // we need at two file to do the diff
                StringArray stringsPrev = new StringArray();
                stringsPrev.Load(filenamePrev);

                // check for changed items
                foreach (long id in stringsPrev.GetStringsChangedIn(stringsOriginal))
                {
                    TranslatorItem translatorItem = null;
                    if (GetItemById(id, ref translatorItem))
                    {
                        if (translatorItem.StringTranslated.Text != "")
                        {
                            translatorItem.State = TranslationState.Changed;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Loads the current language file and checks its string for its state
        /// </summary>
        public void Load()
        {
            if (Settings.Instance.LanguageFolder == "" || Settings.Instance.Language == "")
            {
                return;
            }

            modified = false;

            if (!File.Exists(Settings.Instance.FilenameOriginal))
            {
                throw new TranslatorException("File " + Settings.Instance.FilenameOriginal + " was not found. Please be sure your language folder is set properly.");
            }

            if (!File.Exists(Settings.Instance.FilenameTranslated))
            {
                throw new TranslatorException("File " + Settings.Instance.FilenameTranslated + " was not found. Please be sure your language folder is set properly.");
            }

            StringArray stringsOriginal = new StringArray();

            stringsOriginal.Load(Settings.Instance.FilenameOriginal);

            versionOriginal = stringsOriginal.Version;

            StringArray stringsTranslated = new StringArray();

            stringsTranslated.Load(Settings.Instance.FilenameTranslated);

            try
            {
                DetermineTranslated(stringsTranslated, stringsOriginal);
                DetermineUntranslated(stringsTranslated, stringsOriginal);
                DetermineChanged(stringsTranslated, stringsOriginal);
                Sort();

                foreach (TranslatorItem item in strings)
                {                 // Add StringModified to the stringUpdated delegate
                    // to be informed if a string has changed
                    item.StringTranslated.stringUpdated += new StringItem.StringUpdatedDelegate(StringModified);
                }
            }
            catch (Exception e)
            {
                throw new TranslatorException("Error processing xml data", e);
            }
        }
Example #3
0
        /// <summary>
        /// Creates all TranlatorItems with the state changed.
        /// It also saves the master language history
        /// </summary>
        private void DetermineChanged(StringArray stringsTranslated, StringArray stringsOriginal)
        {
            string filenameSaved=System.Windows.Forms.Application.LocalUserAppDataPath.Substring(0, System.Windows.Forms.Application.LocalUserAppDataPath.LastIndexOf(@"\"))+@"\strings.xml";
            string filenamePrev=System.Windows.Forms.Application.LocalUserAppDataPath.Substring(0, System.Windows.Forms.Application.LocalUserAppDataPath.LastIndexOf(@"\"))+@"\stringsPrev.xml";

            // No history yet?
            if (!File.Exists(filenameSaved))
            {	// Copy our master language, to have a history
                File.Copy(Settings.Instance.FilenameOriginal, filenameSaved, true);
                return;
            }

            StringArray stringsSaved=new StringArray();

            stringsSaved.Load(filenameSaved);

            // Check the version of the saved master language
            if (stringsOriginal.Version>stringsSaved.Version)
            {	// saved is older then our current master language,
                // update history
                File.Copy(filenameSaved, filenamePrev, true);
                File.Copy(Settings.Instance.FilenameOriginal, filenameSaved, true);
            }
            else if (stringsOriginal.Version<stringsSaved.Version)
            { // Oh Oh, current master is older then the saved one, thow exception
                throw new TranslatorException("File "+Settings.Instance.FilenameOriginal+" is older then the one last used for this translation.");
            }

            stringsSaved.Clear();

            if (File.Exists(filenamePrev))
            {	// we need at two file to do the diff
                StringArray stringsPrev=new StringArray();
                stringsPrev.Load(filenamePrev);

                // check for changed items
                foreach (long id in stringsPrev.GetStringsChangedIn(stringsOriginal))
                {
                    TranslatorItem translatorItem=null;
                    if (GetItemById(id, ref translatorItem))
                    {
                        if (translatorItem.StringTranslated.Text!="")
                            translatorItem.State=TranslationState.Changed;
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Loads the current language file and checks its string for its state
        /// </summary>
        public void Load()
        {
            if (Settings.Instance.LanguageFolder=="" || Settings.Instance.Language=="")
                return;

            modified=false;

            if (!File.Exists(Settings.Instance.FilenameOriginal))
                throw new TranslatorException("File "+Settings.Instance.FilenameOriginal+" was not found. Please be sure your language folder is set properly.");

            if (!File.Exists(Settings.Instance.FilenameTranslated))
                throw new TranslatorException("File "+Settings.Instance.FilenameTranslated+" was not found. Please be sure your language folder is set properly.");

            StringArray stringsOriginal=new StringArray();
            stringsOriginal.Load(Settings.Instance.FilenameOriginal);

            versionOriginal=stringsOriginal.Version;

            StringArray stringsTranslated=new StringArray();
            stringsTranslated.Load(Settings.Instance.FilenameTranslated);

            try
            {
                DetermineTranslated(stringsTranslated, stringsOriginal);
                DetermineUntranslated(stringsTranslated, stringsOriginal);
                DetermineChanged(stringsTranslated, stringsOriginal);
                Sort();

                foreach (TranslatorItem item in strings)
                { // Add StringModified to the stringUpdated delegate
                    // to be informed if a string has changed
                    item.StringTranslated.stringUpdated+=new StringItem.StringUpdatedDelegate(StringModified);
                }
            }
            catch(Exception e)
            {
                throw new TranslatorException("Error processing xml data", e);
            }
        }
Example #5
0
        /// <summary>
        /// Checks if a language file is valid
        /// </summary>
        private void menuItemValidateFile_Click(object sender, System.EventArgs e)
        {
            openFileDialog1.InitialDirectory=Settings.Instance.LanguageFolder;
            if (openFileDialog1.ShowDialog()==DialogResult.Cancel)
                return;

            StringArray strings=new StringArray();

            try
            {
                strings.Load(openFileDialog1.FileName);
            }
            catch(TranslatorException ex)
            {
                ShowMessageBox(BuildErrorMessageText(ex), MessageBoxIcon.Error);
                return;
            }

            ShowMessageBox("The file " + openFileDialog1.FileName + " is valid.", MessageBoxIcon.Information);
        }
Example #6
0
        /// <summary>
        /// Converts a language file to the new format
        /// </summary>
        private void menuItemConvert_Click(object sender, System.EventArgs e)
        {
            openFileDialog1.InitialDirectory=Settings.Instance.LanguageFolder;
            if (openFileDialog1.ShowDialog()==DialogResult.Cancel)
                return;

            StringArray strings=new StringArray();

            try
            {
                strings.Load(openFileDialog1.FileName);
            }
            catch(TranslatorException ex)
            {
                ShowMessageBox(BuildErrorMessageText(ex), MessageBoxIcon.Error);
                return;
            }

            saveFileDialog1.InitialDirectory=openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.LastIndexOf(@"\"));
            if (saveFileDialog1.ShowDialog()==DialogResult.Cancel)
                return;

            try
            {
                string[] comment=new string[1];
                comment[0]="$"+"Revision"+"$";
                strings.Save(saveFileDialog1.FileName, comment);
            }
            catch(TranslatorException ex)
            {
                ShowMessageBox(BuildErrorMessageText(ex), MessageBoxIcon.Error);
                return;
            }

            MessageBox.Show("File "+saveFileDialog1.FileName+" was succesfully saved.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }