public static IList<TranslationItemWithCategory> LoadNeutralItems()
        {
            Translation neutralTranslation = new Translation();
            try
            {
                //Set language to neutral to get neutral translations
                GitCommands.AppSettings.CurrentTranslation = "";

                List<Type> translatableTypes = TranslationUtl.GetTranslatableTypes();
                foreach (Type type in translatableTypes)
                {
                    ITranslate obj = TranslationUtl.CreateInstanceOfClass(type) as ITranslate;
                    if (obj != null)
                        obj.AddTranslationItems(neutralTranslation);
                }
            }
            finally
            {
                neutralTranslation.Sort();

                //Restore translation
                GitCommands.AppSettings.CurrentTranslation = null;
            }

            IList<TranslationItemWithCategory> neutralItems =
                (from translationCategory in neutralTranslation.TranslationCategories
                 from translationItem in translationCategory.Body.TranslationItems
                 select new TranslationItemWithCategory(translationCategory.Name, translationItem)).ToList();
            return neutralItems;
        }
 public static void Serialize(Translation translation, string path)
 {
     using (TextWriter tw = new StreamWriter(path, false))
     {
         XmlSerializer serializer = new XmlSerializer(typeof(Translation));
         serializer.Serialize(tw, translation);
     }
 }
        public void CreateInstanceOfClass()
        {
            // just reference to GitUI
            MouseWheelRedirector.Active = true;

            List<Type> translatableTypes = TranslationUtl.GetTranslatableTypes();

            var testTranslation = new Translation();

            foreach (Type type in translatableTypes)
            {
                try
                {
                    ITranslate obj = TranslationUtl.CreateInstanceOfClass(type) as ITranslate;
                    obj.AddTranslationItems(testTranslation);
                    obj.TranslateItems(testTranslation);
                }
                catch (System.Exception)
                {
                    Trace.WriteLine("Problem with class: " + type.FullName);
                    throw;
                }
            }
        }       
        public static List<TranslationItemWithCategory> LoadTranslation(Translation translation, IEnumerable<TranslationItemWithCategory> neutralItems)
        {
            List<TranslationItemWithCategory> translateItems = new List<TranslationItemWithCategory>();

            var oldTranslationItems =
                (from translationCategory in translation.TranslationCategories
                 from translationItem in translationCategory.Body.TranslationItems
                 select new TranslationItemWithCategory(translationCategory.Name, translationItem)).ToList();

            var dict = new Dictionary<string, string>();
            foreach (var item in neutralItems)
            {
                var curItems = oldTranslationItems.Where(
                        trItem => trItem.Category.TrimStart('_') == item.Category.TrimStart('_') &&
                                  trItem.Name.TrimStart('_') == item.Name.TrimStart('_') &&
                                  trItem.Property == item.Property);
                var curItem = curItems.FirstOrDefault();

                if (curItem == null)
                {
                    curItem = item.Clone();
                    translateItems.Add(curItem);
                    continue;
                }

                oldTranslationItems.Remove(curItem);
                curItem.Category = item.Category;
                curItem.Name = item.Name;

                string source = curItem.NeutralValue ?? item.NeutralValue;
                if (!String.IsNullOrEmpty(curItem.TranslatedValue) && !dict.ContainsKey(source))
                    dict.Add(source, curItem.TranslatedValue);

                // Source text changed
                if (!curItem.IsSourceEqual(item.NeutralValue) &&
                    (!String.IsNullOrEmpty(curItem.TranslatedValue) && !curItem.IsSourceEqual(item.NeutralValue)))
                {
                    curItem.TranslatedValue = "";
                }
                curItem.NeutralValue = item.NeutralValue;
                translateItems.Add(curItem);
            }

            foreach (var item in oldTranslationItems)
            {
                // Obsolete should be added only to dictionary
                if (!String.IsNullOrEmpty(item.TranslatedValue) &&
                    item.NeutralValue != null && !dict.ContainsKey(item.NeutralValue))
                {
                    dict.Add(item.NeutralValue, item.TranslatedValue);
                }
            }

            // update untranslated items
            var untranlatedItems =
                from trItem in translateItems
                where (String.IsNullOrEmpty(trItem.TranslatedValue)) && dict.ContainsKey(trItem.NeutralValue)
                select trItem;

            foreach (var untranlatedItem in untranlatedItems)
            {
                untranlatedItem.TranslatedValue = dict[untranlatedItem.NeutralValue];
            }
            return translateItems;
        }
        public static void SaveTranslation(string languageCode, IEnumerable<TranslationItemWithCategory> items, string filename)
        {
            var foreignTranslation = new Translation(GitCommands.AppSettings.ProductVersion, languageCode);
            foreach (TranslationItemWithCategory translateItem in items)
            {
                var item = translateItem.GetTranslationItem();

                var ti = new TranslationItem(item.Name, item.Property, item.Source, item.Value);
                ti.Value = ti.Value ?? String.Empty;
                foreignTranslation.FindOrAddTranslationCategory(translateItem.Category).Body.AddTranslationItem(ti);
            }
            TranslationSerializer.Serialize(foreignTranslation, filename);
        }
        private void translations_SelectedIndexChanged(object sender, EventArgs e)
        {
            AskForSave();
            changesMade = false;

            translation = (Translation)Translator.GetTranslation(translations.Text);
            LoadTranslation();
            UpdateCategoriesList();
            FillTranslateGrid(translateCategories.SelectedItem as TranslationCategory);

            if (translation == null)
            {
                _NO_TRANSLATE_languageCode.Text = "";
                return;
            }

            try
            {
                var culture = new CultureInfo(translation.LanguageCode);
                _NO_TRANSLATE_languageCode.Text = string.Concat(culture.TwoLetterISOLanguageName, " (", culture.DisplayName, ")");
            }
            catch
            {
                _NO_TRANSLATE_languageCode.Text = translation.LanguageCode;
            }
        }