Beispiel #1
0
		/// <summary>
		/// Load language database and files
		/// </summary>
		/// <param name="lng"></param>
		/// <param name="abrev"></param>
		/// <param name="longname"></param>
		/// <returns></returns>
		private static bool LoadLanguages()
		{
			if (log.IsInfoEnabled)
				log.Info("[LanguageMgr] Loading translations ID...");
			
			if (DOL.GS.ServerProperties.Properties.USE_DBLANGUAGE)
			{
				IList<DBLanguage> objs = GameServer.Database.SelectAllObjects<DBLanguage>();
				foreach (DBLanguage obj in objs)
				{
					if (!IDSentences.ContainsKey(obj.TranslationID))
					{
						IDSentences.Add(obj.TranslationID, new Dictionary<string, string>());
						IDSentences[obj.TranslationID].Add("EN", obj.EN);
						IDSentences[obj.TranslationID].Add("DE", obj.DE != null && obj.DE != "" ? obj.DE : obj.EN);
						IDSentences[obj.TranslationID].Add("FR", obj.FR != null && obj.FR != "" ? obj.FR : obj.EN);
						IDSentences[obj.TranslationID].Add("IT", obj.IT != null && obj.IT != "" ? obj.IT : obj.EN);
						IDSentences[obj.TranslationID].Add("CU", obj.CU != null && obj.CU != "" ? obj.CU : obj.EN);
					}
				}
			}

			if (!IDSentences.ContainsKey("SHORT_NAME"))
			{
				IDSentences.Add("SHORT_NAME", new Dictionary<string, string>());
				IDSentences["SHORT_NAME"].Add("EN", "EN");
				IDSentences["SHORT_NAME"].Add("DE", "DE");
				IDSentences["SHORT_NAME"].Add("FR", "FR");
				IDSentences["SHORT_NAME"].Add("IT", "IT");
				IDSentences["SHORT_NAME"].Add("CU", "CU");
			}

			if (!IDSentences.ContainsKey("LONG_NAME"))
			{
				IDSentences.Add("LONG_NAME", new Dictionary<string, string>());
				IDSentences["LONG_NAME"].Add("EN", "English");
				IDSentences["LONG_NAME"].Add("DE", "Deutsch");
				IDSentences["LONG_NAME"].Add("FR", "Français");
				IDSentences["LONG_NAME"].Add("IT", "Italian");
				IDSentences["LONG_NAME"].Add("CU", "Custom");
			}

			m_refreshFromFiles = new List<string>();
			foreach (string abrev in IDSentences["SHORT_NAME"].Keys)
				CheckFromFiles(abrev);

			if (DOL.GS.ServerProperties.Properties.USE_DBLANGUAGE)
			{
				if (m_refreshFromFiles.Count > 0)
				{
					foreach (string id in m_refreshFromFiles)
					{
						bool create = false;
						if (IDSentences.ContainsKey(id))
						{
							DBLanguage obj = (DBLanguage)GameServer.Database.SelectObject<DBLanguage>("`TranslationID` = '" + GameServer.Database.Escape(id) + "'");
							if (obj == null)
							{
								obj = new DBLanguage();
								obj.TranslationID = id;
								create = true;
							}
							obj.EN = IDSentences[id]["EN"];
							obj.DE = IDSentences[id]["DE"];
							obj.FR = IDSentences[id]["FR"];
							obj.IT = IDSentences[id]["IT"];
							obj.CU = IDSentences[id]["CU"];
							if (create) GameServer.Database.AddObject(obj);
							else GameServer.Database.SaveObject(obj);
						}

						if (log.IsWarnEnabled)
							log.Warn("[LanguageMgr] TranslationID <" + id + "> " + (create ? "created" : "updated") + " in database!");
					}

					if (log.IsWarnEnabled)
						log.Warn("[LanguageMgr] Loaded " + m_refreshFromFiles.Count + " translations ID from files to database!");
				}
			}
			m_refreshFromFiles.Clear();

			if (log.IsInfoEnabled)
				log.Info("[LanguageMgr] Translations ID loaded.");
			
			return true;
		}
Beispiel #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="player"></param>
 /// <param name="response"></param>
 private void Confirm(GamePlayer player, byte response)
 {
     if (player == null || response != 0x01) return;
     string id = player.TempProperties.getProperty<string>("LANGUAGEMGR-ID", "");
     string lang = player.TempProperties.getProperty<string>("LANGUAGEMGR-LANG", "");
     string sentence = player.TempProperties.getProperty<string>("LANGUAGEMGR-TEXT", "");
     if (id == "" || lang == "" || sentence == "") return;
     player.TempProperties.removeProperty("LANGUAGEMGR-ID");
     player.TempProperties.removeProperty("LANGUAGEMGR-LANG");
     player.TempProperties.removeProperty("LANGUAGEMGR-TEXT");
     if (!LanguageMgr.IDSentences.ContainsKey(id))
     {
         DisplayMessage(player.Client, "The TranslationID <" + id + "> does not exist!");
         return;
     }
     if (!LanguageMgr.IDSentences[id].ContainsKey(lang))
     {
         DisplayMessage(player.Client, "The TranslationID <" + id + "> does not contain the language <" + lang + "> !");
         return;
     }
     LanguageMgr.IDSentences[id][lang] = sentence;
     bool create = false;
     DBLanguage obj = GameServer.Database.SelectObject<DBLanguage>("`TranslationID` = '" + GameServer.Database.Escape(id) + "'");
     if (obj == null)
     {
         obj = new DBLanguage();
         obj.TranslationID = id;
         create = true;
     }
     switch (lang)
     {
         case "EN": obj.EN = sentence; break;
         case "DE": obj.DE = sentence; break;
         case "FR": obj.FR = sentence; break;
         case "IT": obj.IT = sentence; break;
         case "CU": obj.CU = sentence; break;
         default: break;
     }
     if (create) GameServer.Database.AddObject(obj);
     else GameServer.Database.SaveObject(obj);
     DisplayMessage(player.Client, "The Translation [" + id + "] [" + lang + "] is now <" + sentence + "> (" + (create ? "created" : "updated") + ") !");
     LanguageMgr.Refresh(id);
 }