示例#1
0
        public void Load(string outputFileName)
        {
            // Clear all previous translations
            this.Clear();

            // Init extra type
            Type [] extraTypes = this.GetExtraTypes();

            // Create an instance of the XmlSerializer class of type Contact array
            XmlSerializer x = new XmlSerializer(typeof(object[]), extraTypes);

            // Read the XML file if it exists ---
            FileStream fs = new FileStream(outputFileName, FileMode.Open);

            if (fs != null)
            {
                // Deserialize the content of the XML file to a Contact array utilizing XMLReader
                XmlReader reader  = new XmlTextReader(fs);
                object[]  objects = (object[])x.Deserialize(reader);

                // Add each member of the Contact array to the hash table
                for (int i = 0; i < objects.Length; i++)
                {
                    XmlTranslatorElement currentObject = (XmlTranslatorElement)objects[i];
                    m_InternalLanguageHashTable.Add(currentObject.InternalName, currentObject);

                    // Incease instance counter
                    this.ComputeInstanceCounter();
                }

                // Close handle
                fs.Close();
            }
        }
示例#2
0
 /// <summary>
 /// Main function to call to translate a text
 /// </summary>
 /// <param name="internalName">internal name to use for searching translation</param>
 /// <returns>Return the transalated string or an error string</returns>
 public string Translate(string internalName)
 {
     if (m_InternalLanguageHashTable.ContainsKey(internalName))
     {
         XmlTranslatorElement oCurrentElement = m_InternalLanguageHashTable [internalName] as XmlTranslatorElement;
         return(oCurrentElement.Translate(this.CurrentLanguage));
     }
     return(string.Format(CultureInfo.InvariantCulture, "NOT_FOUND_{0}", internalName));
 }
示例#3
0
        public void AddOrUpdateContainer(XmlTranslatorElement objectToAdd)
        {
            if (objectToAdd == null)
            {
                throw new ArgumentNullException("objectToAdd", SystemErrors.TranslateError("ArgumentNull"));
            }

            if (m_InternalLanguageHashTable.ContainsKey(objectToAdd.InternalName))
            {
                m_InternalLanguageHashTable [objectToAdd.InternalName] = objectToAdd;
            }
            else
            {
                m_InternalLanguageHashTable.Add(objectToAdd.InternalName, objectToAdd);
            }
        }
示例#4
0
		public void AddOrUpdateContainer (XmlTranslatorElement objectToAdd)
		{
			if( objectToAdd == null)
			{
				throw new ArgumentNullException ("objectToAdd", SystemErrors.TranslateError ("ArgumentNull"));
			}

			if (m_InternalLanguageHashTable.ContainsKey (objectToAdd.InternalName))
			{
				m_InternalLanguageHashTable [objectToAdd.InternalName] = objectToAdd;
			}
			else
			{
				m_InternalLanguageHashTable.Add(objectToAdd.InternalName, objectToAdd);
			}
		}
示例#5
0
		public void GenerateFile (string fileName)
		{
			XmlTranslatorElement element;

			// Add word translation
			element = new XmlTranslatorElement ("TRAD_Test", 0);
			element.AddOrUpdate (Language.French, "Ceci est un test", "Vincent", DateTime.Now);
			element.AddOrUpdate (Language.English, "This is a test", "Vincent", DateTime.Now);
			this.AddOrUpdateContainer (element);

			// Add word translation
			element = new XmlTranslatorElement ("TRAD_Languages", 0);
			element.AddOrUpdate (Language.French, "Langages", "Vincent", DateTime.Now);
			element.AddOrUpdate (Language.English, "Languages", "Vincent", DateTime.Now);
			this.AddOrUpdateContainer (element);

			// Add word translation
			this.Save (fileName);
		}
示例#6
0
		static public void GenerateFile ()
		{
			XmlTranslatorElement element;

			// Argument NULL
			element = new XmlTranslatorElement ("ArgumentNull", 0);
			element.AddOrUpdate (Language.French, "Argument définit à Null", "Vincent", DateTime.Now);
			element.AddOrUpdate (Language.English, "Argument set to Null", "Vincent", DateTime.Now);
			SystemErrors.Instance.AddOrUpdateContainer (element);

			// Bad URL, remote file not found
			element = new XmlTranslatorElement ("UriFormatException", 0);
			element.AddOrUpdate (Language.French, "Format d'Url incorrect ou fichier absent", "Vincent", DateTime.Now);
			element.AddOrUpdate (Language.English, "Bad Uri or file missing", "Vincent", DateTime.Now);
			SystemErrors.Instance.AddOrUpdateContainer (element);


			// Save file
			SystemErrors.Instance.Save (SystemErrors.ErrorsFileName);
		}
示例#7
0
        static public void GenerateFile()
        {
            XmlTranslatorElement element;

            // Argument NULL
            element = new XmlTranslatorElement("ArgumentNull", 0);
            element.AddOrUpdate(Language.French, "Argument définit à Null", "Vincent", DateTime.Now);
            element.AddOrUpdate(Language.English, "Argument set to Null", "Vincent", DateTime.Now);
            SystemErrors.Instance.AddOrUpdateContainer(element);

            // Bad URL, remote file not found
            element = new XmlTranslatorElement("UriFormatException", 0);
            element.AddOrUpdate(Language.French, "Format d'Url incorrect ou fichier absent", "Vincent", DateTime.Now);
            element.AddOrUpdate(Language.English, "Bad Uri or file missing", "Vincent", DateTime.Now);
            SystemErrors.Instance.AddOrUpdateContainer(element);


            // Save file
            SystemErrors.Instance.Save(SystemErrors.ErrorsFileName);
        }
示例#8
0
		public void InitDefault ()
		{
			m_MyInt			= 69;
			m_MyString		= "This is a test string";
			m_MyXmlString	= new XmlString ("Native XML string object");
			m_MyFloat		= 3.14f;

			m_MyXmlDateTime				= new XmlDateTime (DateTime.Now);
			m_MyXmlColor				= new XmlColor	(Color.BurlyWood);
			m_MyXmlSizeF2d				= new XmlSizeF2d (452.62f, 895.7989f);
			m_MyXmlItemKeyAndValue		= new XmlItemKeyAndValue ("KeyNameToUse", m_MyXmlColor);
			m_MyXmlTranslatorElement	= new XmlTranslatorElement ("MyInternalName", 0);
			m_MyXmlTranslatorElement.AddOrUpdate (Language.English, "My translated text", "The last modifiying person", DateTime.Now);
			m_MyXmlTranslatorElement.AddOrUpdate (Language.German, "My translated text in German", "The last modifiying person", DateTime.Now);

			m_MyXmlPen			= new XmlPen (Color.Violet, 20);

			m_MyArrayList		= new ArrayList ();
			m_MyArrayList.Add (this.MyInt);
			m_MyArrayList.Add (this.MyFloat);
			m_MyArrayList.Add (this.MyString);
			m_MyArrayList.Add (this.MyXmlString);
			
			m_MyXmlList			= new XmlList ();
			m_MyXmlList.Add (this.MyInt);
			m_MyXmlList.Add (this.MyFloat);
			m_MyXmlList.Add (this.MyString);
			m_MyXmlList.Add (this.MyXmlString);

			m_MyXmlHashtable	= new XmlHashtable ();
			m_MyXmlHashtable.Add ("HashElement1", m_MyInt);
			m_MyXmlHashtable.Add ("HashElement2", m_MyString);
			m_MyXmlHashtable.Add ("HashElement3", m_MyXmlString);
			m_MyXmlHashtable.Add ("HashElement4", m_MyFloat);
			m_MyXmlHashtable.Add ("HashElement5", m_MyXmlList);
		}
示例#9
0
        public XmlTranslatorElement CreateContainer(string internalName)
        {
            XmlTranslatorElement element = new XmlTranslatorElement(internalName, this.ComputeInstanceCounter());

            return(element);
        }
示例#10
0
		public XmlTranslatorElement CreateContainer (string internalName)
		{
			XmlTranslatorElement element = new XmlTranslatorElement (internalName, this.ComputeInstanceCounter ());

			return element;
		}