Ejemplo n.º 1
0
 public static string Format(LocString key, params object[] args)
 {
     return(String.Format(GetString(key), args));
 }
Ejemplo n.º 2
0
 internal void SendMessage(LocString loc)
 {
     SendMessage(MsgLevel.Info, Language.GetString(loc));
 }
Ejemplo n.º 3
0
 public static KeyData Add(HKCategory cat, LocString name, HotKeyCallbackState callback, object state)
 {
     return(Add(cat, HKSubCat.None, (int)name, callback, state));
 }
Ejemplo n.º 4
0
 internal void SendMessage(MsgLevel lvl, LocString loc)
 {
     SendMessage(lvl, Language.GetString(loc));
 }
Ejemplo n.º 5
0
 internal void SendMessage(LocString loc, params object[] args)
 {
     SendMessage(MsgLevel.Info, Language.Format(loc, args));
 }
Ejemplo n.º 6
0
 internal void OverheadMessage(LocString str, params object[] args)
 {
     OverheadMessage(Language.Format(str, args));
 }
Ejemplo n.º 7
0
 internal void OverheadMessage(LocString str)
 {
     OverheadMessage(Language.GetString(str));
 }
Ejemplo n.º 8
0
 internal static LocString Format(LocString loc, object[] args)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 9
0
 internal static string GetString(LocString loc)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 10
0
        internal static bool Load(string lang)
        {
            lang = lang.ToUpper();
            if (m_Current != null && m_Current == lang)
            {
                return(true);
            }

            m_CliLocName = "enu";
            string filename = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Language", String.Format("Razor_lang.{0}", lang));

            if (!File.Exists(filename))
            {
                return(false);
            }
            m_Current = lang;
            List <int> errors   = new List <int>();
            Encoding   encoding = Encoding.ASCII;

            using (StreamReader reader = new StreamReader(filename))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    line = line.Trim();
                    string lower = line.ToLower();

                    if (line == "" || line[0] == '#' || line[0] == ';' || (line.Length >= 2 && line[0] == '/' && line[1] == '/'))
                    {
                        continue;
                    }
                    else if (lower == "[controls]" || lower == "[strings]")
                    {
                        break;
                    }

                    if (lower.StartsWith("::encoding"))
                    {
                        try
                        {
                            int idx = lower.IndexOf('=') + 1;
                            if (idx > 0 && idx < lower.Length)
                            {
                                encoding = Encoding.GetEncoding(line.Substring(idx).Trim());
                            }
                        }
                        catch
                        {
                            encoding = null;
                        }

                        if (encoding == null)
                        {
                            MessageBox.Show("Error: The encoding specified in the language file was not valid.  Using ASCII.", "Invalid Encoding", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            encoding = Encoding.ASCII;
                        }
                        break;
                    }
                }
            }

            using (StreamReader reader = new StreamReader(filename, encoding))
            {
                //m_Dict.Clear(); // just overwrite the old lang, rather than erasing it (this way if this lang is missing something, it'll appear in the old one
                int    lineNum = 0;
                string line;
                bool   controls = true;
                int    idx      = 0;

                while ((line = reader.ReadLine()) != null)
                {
                    try
                    {
                        line = line.Trim();
                        lineNum++;
                        if (line == "" || line[0] == '#' || line[0] == ';' || (line.Length >= 2 && line[0] == '/' && line[1] == '/'))
                        {
                            continue;
                        }
                        string lower = line.ToLower();
                        if (lower == "[controls]")
                        {
                            controls = true;
                            continue;
                        }
                        else if (lower == "[strings]")
                        {
                            controls = false;
                            continue;
                        }
                        else if (lower.StartsWith("::cliloc"))
                        {
                            idx = lower.IndexOf('=') + 1;
                            if (idx > 0 && idx < lower.Length)
                            {
                                m_CliLocName = lower.Substring(idx).Trim().ToUpper();
                            }
                            continue;
                        }
                        else if (lower.StartsWith("::encoding"))
                        {
                            continue;
                        }

                        idx = line.IndexOf('=');
                        if (idx < 0)
                        {
                            errors.Add(lineNum);
                            continue;
                        }

                        string key   = line.Substring(0, idx).Trim();
                        string value = line.Substring(idx + 1).Trim().Replace("\\n", "\n");

                        if (controls)
                        {
                            if (!m_Controls.ContainsKey(key))
                            {
                                m_Controls.Add(key, "");
                            }
                            m_Controls[key] = value;
                        }
                        else
                        {
                            LocString loc = (LocString)Convert.ToInt32(key);
                            if (!m_Strings.ContainsKey(loc))
                            {
                                m_Strings.Add(loc, "");
                            }
                            m_Strings[loc] = value;
                        }
                    }
                    catch
                    {
                        errors.Add(lineNum);
                    }
                }        //while
            }            //using

            if (errors.Count > 0)
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendFormat("Razor enountered errors on the following lines while loading the file '{0}'\r\n", filename);
                foreach (int t in errors)
                {
                    sb.AppendFormat("Line {0}\r\n", t);
                }

                new MessageDialog("Language Pack Load Errors", true, sb.ToString()).Show();
            }

            LoadCliLoc();

            m_Loaded = true;
            return(true);
        }