using System; using System.Text; using System.Collections; using System.Text.RegularExpressions; namespace Duck.Managers { /// /// Provides functions for management of localizeable strings. /// public static class stringManager { #region Declares /// /// Contains the strings loaded from system_strings. /// private static Hashtable langStrings; /// /// The language extension to use for the emulator. /// internal static string langExt; #endregion #region Methods /// /// Initializes the string manager with a certain language. /// /// The language to use for the emulator, eg, 'en' for English. public static void Init(string langExtension) { langExt = langExtension; langStrings = new Hashtable(); IO.WriteLine("Loading strings from duck_strings table for language '" + langExtension + "' ..."); string[] langKeys = DB.runReadColumn("SELECT lkey FROM duck_strings ORDER BY id ASC", 0); string[] langVars = DB.runReadColumn("SELECT lvalue_" + langExt + " FROM duck_strings ORDER BY id ASC", 0); for (int i = 0; i < langKeys.Length; i++) { if (langKeys[i] == "") continue; if (langVars[i] == "") langVars[i] = langKeys[i]; langStrings.Add(langKeys[i], langVars[i]); } IO.WriteLine("Loaded " + langStrings.Count + " strings from duck_strings table."); } /// /// Retrieves a system_strings entry for a certain key. The strings are loaded at the initialization of the string manager. /// /// The key of the string to retrieve. public static string getString(string stringID) { try { return langStrings[stringID].ToString(); } catch { return stringID; } } /// /// Returns a boolean that indicates if a certain string contains at least one number. /// /// The string to check. public static bool hasNumbers(string s) { return Regex.IsMatch(s, @"\d+"); } /// /// Returns a boolean that indicates if a certain string contains numbers only. /// /// The string to check. public static bool isNumeric(string s) { Double result; return Double.TryParse(s,System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.CurrentCulture, out result); } #endregion } }