public LocaleTable LoadLocaleTable(string locale)
        {
            // Temp locale
            {
                LocaleTable locale_table = LoadTempLocaleTable(locale);
                if (null != locale_table)
                {
                    Logging.Info("Loaded TEMP locale for {0} with {1} items.", locale_table, locale_table.Count);
                    return(locale_table);
                }
            }

            // Real locale
            try
            {
                LocaleTable locale_table = LocaleTable.Load(GetFilenameForLocale(locale));
                if (null != locale_table)
                {
                    Logging.Info("Loaded REAL locale for {0} with {1} items.", locale_table, locale_table.Count);
                    return(locale_table);
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "Problem loading locale.");
            }

            // Give up
            return(null);
        }
        public void LoadLocale(string locale)
        {
            LocaleTable locale_table_en = LocalisationManager.Instance.LoadLocaleTable(LocalisationManager.DEFAULT_LOCALE);

            LocaleTable locale_table = LocalisationManager.Instance.LoadLocaleTable(locale);

            if (null == locale_table)
            {
                locale_table = new LocaleTable();
            }

            List <LocalisationRow> rows = new List <LocalisationRow>();

            foreach (var pair in locale_table_en)
            {
                LocalisationRow row = new LocalisationRow();
                row.Id      = pair.Key;
                row.Default = pair.Value;
                if (locale_table.ContainsKey(pair.Key))
                {
                    row.Translation = locale_table[pair.Key];
                }

                rows.Add(row);
            }

            GridEditor.ItemsSource = rows;
        }
        public void SaveTempLocaleTable(string locale, LocaleTable locale_table)
        {
            string filename = GetFilenameForTempLocale(locale);

            Directory.CreateDirectory(Path.GetDirectoryName(filename));
            locale_table.Save(filename);
            Logging.Info("Saved locale " + locale);
        }
        public string GetString_NORMAL(string key)
        {
            foreach (string locale in GetLocaleOrder())
            {
                LocaleTable locale_table = GetLocaleTable(locale);
                if (null != locale_table)
                {
                    string content = null;
                    if (locale_table.TryGetValue(key, out content))
                    {
                        return(content);
                    }
                }
            }

            return(null);
        }
        public LocaleTable LoadTempLocaleTable(string locale)
        {
            // Temp locale
            try
            {
                LocaleTable locale_table = LocaleTable.Load(GetFilenameForTempLocale(locale));
                if (null != locale_table)
                {
                    return(locale_table);
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "Problem loading temp locale.");
            }

            return(null);
        }
        public string GetString_TIP(string key)
        {
            StringBuilder sb = new StringBuilder();

            foreach (string locale in GetLocaleOrder())
            {
                LocaleTable locale_table = GetLocaleTable(locale);
                if (null != locale_table)
                {
                    string content = null;
                    if (locale_table.TryGetValue(key, out content))
                    {
                        sb.AppendLine(content);
                        sb.AppendLine();
                    }
                }
            }

            return(sb.ToString().TrimEnd());
        }
        private void DoFlush(bool force)
        {
            if (!force && last_flush_time.ElapsedMilliseconds < 3000)
            {
                return;
            }

            last_flush_time.Restart();

            List <LocalisationRow> rows         = (List <LocalisationRow>)GridEditor.ItemsSource;
            LocaleTable            locale_table = new LocaleTable();

            foreach (LocalisationRow row in rows)
            {
                if (!String.IsNullOrEmpty(row.Translation))
                {
                    locale_table[row.Id] = row.Translation.Replace(Environment.NewLine, "\\n");
                }
            }

            // Write to disk...
            LocalisationManager.Instance.SaveTempLocaleTable(current_locale, locale_table);
        }
        public static LocaleTable Load(string filename)
        {
            try
            {
                if (File.Exists(filename))
                {
                    LocaleTable locale_table = new LocaleTable();

                    string[] lines = File.ReadAllLines(filename);
                    foreach (string line in lines)
                    {
                        string[] parts = line.Split(LINE_SPLITTER_ARRAY, 2);
                        if (2 == parts.Length)
                        {
                            parts[1] = parts[1].Replace("\\n", Environment.NewLine);
                            locale_table[parts[0]] = String.Format(parts[1]);
                        }
                        else
                        {
                            if (!String.IsNullOrWhiteSpace(line))
                            {
                                Logging.Warn("Ignoring locale line: " + line);
                            }
                        }
                    }

                    return(locale_table);
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "Error loading locale file " + filename);
            }

            return(null);
        }