Пример #1
0
        /// <summary>
        /// Create a new language
        /// </summary>
        public void CreateLanguage(string name)
        {
            if (File.Exists(Settings.Instance.LanguageFolder + @"\" + name + @"\strings.xml"))
            {
                throw new TranslatorException("The language \"" + name + "\" already exists.");
            }

            try
            {
                Directory.CreateDirectory(Settings.Instance.LanguageFolder + @"\" + name);
            }
            catch (Exception e)
            {
                throw new TranslatorException("Unable to create the directory " + Settings.Instance.LanguageFolder + @"\" + name, e);
            }


            // Save an empty strings.xml file
            StringArray stringsNew = new StringArray();

            stringsNew.Save(Settings.Instance.LanguageFolder + @"\" + name + @"\strings.xml");

            LanguageInfo langinfo = new LanguageInfo();

            langinfo.Save(Settings.Instance.LanguageFolder + @"\" + name + @"\langinfo.xml");
        }
Пример #2
0
 /// <summary>
 /// Creates all TranlatorItems with the state untranslated
 /// </summary>
 private void DetermineUntranslated(StringArray stringsTranslated, StringArray stringsOriginal)
 {
     foreach (StringItem item in stringsOriginal.GetStringsNotIn(stringsTranslated))
     {
         StringItem itemUntranslated = new StringItem(item);
         itemUntranslated.Text = "";
         Add(new TranslatorItem(itemUntranslated, item, TranslationState.Untranslated));
     }
 }
Пример #3
0
 /// <summary>
 /// Creates all TranlatorItems with the state translated
 /// </summary>
 private void DetermineTranslated(StringArray stringsTranslated, StringArray stringsOriginal)
 {
     foreach (StringItem item in stringsOriginal)
     {
         StringItem itemTranslated = null;
         if (stringsTranslated.GetStringById(item.Id, ref itemTranslated))
         {
             Add(new TranslatorItem(itemTranslated, item, TranslationState.Translated));
         }
     }
 }
Пример #4
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;
                        }
                    }
                }
            }
        }
Пример #5
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);
            }
        }
Пример #6
0
        /// <summary>
        /// Returns the ids of all changed strings
        /// of arr.
        /// </summary>
        public long[] GetStringsChangedIn(StringArray arr)
        {
            ArrayList ret = new ArrayList();

            foreach (StringItem item in strings)
            {
                if (item.Id != 6)               // "XBMC SVN"
                {
                    StringItem stringItem = null;
                    arr.GetStringById(item.Id, ref stringItem);
                    if (stringItem != null && stringItem.Text != item.Text)
                    {
                        ret.Add(item.Id);
                    }
                }
            }

            return((long[])ret.ToArray(typeof(long)));
        }
Пример #7
0
        /// <summary>
        /// Returns a StringArray with all string not in
        /// arr.
        /// </summary>
        public StringArray GetStringsNotIn(StringArray arr)
        {
            StringArray ret = new StringArray();

            foreach (StringItem item in strings)
            {
                if (item.Id != 6)               // "XBMC SVN"
                {
                    StringItem stringItem = null;
                    arr.GetStringById(item.Id, ref stringItem);
                    if (stringItem == null)
                    {
                        ret.Add(item);
                    }
                }
            }

            return(ret);
        }
Пример #8
0
        /// <summary>
        /// Save the current language file
        /// </summary>
        public void Save()
        {
            StringArray strings = new StringArray();

            enumerator = TranslatorArrayEnumerator.All;
            foreach (TranslatorItem item in this)
            {
                if (item.State == TranslationState.Translated || item.State == TranslationState.Changed)
                {
                    strings.Add(item.StringTranslated);
                }
            }

            strings.Sort();

            ArrayList comments = new ArrayList();

            comments.Add("Language file translated with Team XBMC Translator");
            if (Settings.Instance.TranslatorName != "")
            {
                comments.Add("Translator: " + Settings.Instance.TranslatorName);
            }
            if (Settings.Instance.TranslatorEmail != "")
            {
                comments.Add("Email: " + Settings.Instance.TranslatorEmail);
            }

            DateTime time = DateTime.Now;

            comments.Add("Date of translation: " + time.GetDateTimeFormats(System.Globalization.CultureInfo.InvariantCulture)[0]);
            comments.Add("$" + "Revision" + "$");
            if (versionOriginal > 0.0)
            {
                comments.Add("Based on english strings version " + versionOriginal.ToString(System.Globalization.CultureInfo.InvariantCulture));
            }

            strings.Save(Settings.Instance.FilenameTranslated, (string[])comments.ToArray(typeof(string)));

            modified = false;
        }
Пример #9
0
		/// <summary>
		/// Create a new language
		/// </summary>
		public void CreateLanguage(string name)
		{
			if (File.Exists(Settings.Instance.LanguageFolder+@"\"+name+@"\strings.xml"))
				throw new TranslatorException("The language \""+name+"\" already exists.");

			try
			{
				Directory.CreateDirectory(Settings.Instance.LanguageFolder+@"\"+name);
			}
			catch (Exception e)
			{
				throw new TranslatorException("Unable to create the directory "+Settings.Instance.LanguageFolder+@"\"+name, e);
			}


			// Save an empty strings.xml file
			StringArray stringsNew=new StringArray();
			stringsNew.Save(Settings.Instance.LanguageFolder+@"\"+name+@"\strings.xml");

			LanguageInfo langinfo=new LanguageInfo();
			langinfo.Save(Settings.Instance.LanguageFolder+@"\"+name+@"\langinfo.xml");
		}
Пример #10
0
        /// <summary>
        /// Returns a StringArray with all string not in
        /// arr.
        /// </summary>
        public StringArray GetStringsNotIn(StringArray arr)
        {
            StringArray ret=new StringArray();

            foreach (StringItem item in strings)
            {
                if (item.Id!=6) // "XBMC SVN"
                {
                    StringItem stringItem=null;
                    arr.GetStringById(item.Id, ref stringItem);
                    if (stringItem==null)
                        ret.Add(item);
                }
            }

            return ret;
        }
Пример #11
0
        /// <summary>
        /// Returns the ids of all changed strings
        /// of arr.
        /// </summary>
        public long[] GetStringsChangedIn(StringArray arr)
        {
            ArrayList ret=new ArrayList();

            foreach (StringItem item in strings)
            {
                if (item.Id!=6) // "XBMC SVN"
                {
                    StringItem stringItem=null;
                    arr.GetStringById(item.Id, ref stringItem);
                    if (stringItem!=null && stringItem.Text!=item.Text)
                        ret.Add(item.Id);
                }
            }

            return (long[])ret.ToArray(typeof(long));
        }
Пример #12
0
 /// <summary>
 /// Creates all TranlatorItems with the state untranslated
 /// </summary>
 private void DetermineUntranslated(StringArray stringsTranslated, StringArray stringsOriginal)
 {
     foreach (StringItem item in stringsOriginal.GetStringsNotIn(stringsTranslated))
     {
         StringItem itemUntranslated=new StringItem(item);
         itemUntranslated.Text="";
         Add(new TranslatorItem(itemUntranslated, item, TranslationState.Untranslated));
     }
 }
Пример #13
0
 /// <summary>
 /// Creates all TranlatorItems with the state translated
 /// </summary>
 private void DetermineTranslated(StringArray stringsTranslated, StringArray stringsOriginal)
 {
     foreach (StringItem item in stringsOriginal)
     {
         StringItem itemTranslated=null;
         if (stringsTranslated.GetStringById(item.Id, ref itemTranslated))
         {
             Add(new TranslatorItem(itemTranslated, item, TranslationState.Translated));
         }
     }
 }
Пример #14
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;
                    }
                }
            }
        }
Пример #15
0
        /// <summary>
        /// Save the current language file
        /// </summary>
        public void Save()
        {
            StringArray strings=new StringArray();

            enumerator=TranslatorArrayEnumerator.All;
            foreach (TranslatorItem item in this)
            {
                if (item.State==TranslationState.Translated || item.State==TranslationState.Changed)
                    strings.Add(item.StringTranslated);
            }

            strings.Sort();

            ArrayList comments=new ArrayList();
            comments.Add("Language file translated with Team XBMC Translator");
            if (Settings.Instance.TranslatorName!="")
                comments.Add("Translator: "+Settings.Instance.TranslatorName);
            if (Settings.Instance.TranslatorEmail!="")
                comments.Add("Email: "+Settings.Instance.TranslatorEmail);

            DateTime time=DateTime.Now;
            comments.Add("Date of translation: "+time.GetDateTimeFormats(System.Globalization.CultureInfo.InvariantCulture)[0]);
            comments.Add("$"+"Revision"+"$");
            if (versionOriginal>0.0)
                comments.Add("Based on english strings version "+versionOriginal.ToString(System.Globalization.CultureInfo.InvariantCulture));

            strings.Save(Settings.Instance.FilenameTranslated, (string[])comments.ToArray(typeof(string)));

            modified=false;
        }
Пример #16
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);
            }
        }
Пример #17
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);
        }
Пример #18
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);
        }