Пример #1
0
        /// <summary>
        /// Create a Lang pack with a set of items that will be added to a "Main" category
        /// </summary>
        public LanguagePack(LocalizationItem[] items)
        {
            Version = LanguagePack.VERSION;

            LastUpdated = Utils.GetFrapoch();

            Categories = new List <LocalizationCategory>();

            LocalizationCategory mainCategory = new LocalizationCategory("Main")
            {
                Items = new List <LocalizationItem>(items)
            };

            Categories.Add(mainCategory);

            Items = new Dictionary <string, LocalizationItem>();
            foreach (var category in Categories)
            {
                for (int i = 0; i < category.Items.Count; i++)
                {
                    if (category.Items[i] != null)
                    {
                        Items[category.Items[i].Key] = category.Items[i];
                    }
                }
            }
        }
Пример #2
0
        private void LoadV1(BinaryFormatter formatter, Stream stream)
        {
            // The last time the pack was upated
            LastUpdated = (double)formatter.Deserialize(stream);

            // Number of categories
            int numCategories = (int)formatter.Deserialize(stream);

            for (int ci = 0; ci < numCategories; ci++)
            {
                // Category Name
                var category = new LocalizationCategory((string)formatter.Deserialize(stream));

                // Number of items in category
                int numItems = (int)formatter.Deserialize(stream);

                // Loop through categories
                for (int i = 0; i < numItems; i++)
                {
                    var item = new LocalizationItem();

                    // Item Key
                    item.Key = (string)formatter.Deserialize(stream);
                    // Item Val
                    item.Val = (string)formatter.Deserialize(stream);
                    // Item Tooltip
                    item.Tooltip = (string)formatter.Deserialize(stream);
                    // Item Help
                    item.Help = (string)formatter.Deserialize(stream);
                    // Item Context (Used proved context for translation where needed)
                    item.Context = (string)formatter.Deserialize(stream);

                    category.Items.Add(item);
                    Items[item.Key] = item;
                }

                Categories.Add(category);
            }
        }