示例#1
0
        public static IDictionary <string, List <TranslationItemWithCategory> > LoadNeutralItems()
        {
            IDictionary <string, TranslationFile> neutralTranslation = new Dictionary <string, TranslationFile>();

            try
            {
                // Set language to neutral to get neutral translations
                GitCommands.AppSettings.CurrentTranslation = "";

                var translatableTypes = TranslationUtil.GetTranslatableTypes();
                foreach (var(key, types) in translatableTypes)
                {
                    var translation = new TranslationFile();
                    try
                    {
                        foreach (Type type in types)
                        {
                            try
                            {
                                if (TranslationUtil.CreateInstanceOfClass(type) is ITranslate obj)
                                {
                                    obj.AddTranslationItems(translation);
                                    if (obj is IDisposable disposable)
                                    {
                                        disposable.Dispose();
                                    }
                                }
                            }
                            catch
                            {
                                // no-op
                            }
                        }
                    }
                    finally
                    {
                        translation.Sort();
                        neutralTranslation[key] = translation;
                    }
                }
            }
            finally
            {
                // Restore translation
                GitCommands.AppSettings.CurrentTranslation = null;
            }

            return(GetItemsDictionary(neutralTranslation));
        }
        private void FillNeutralTranslation()
        {
            try
            {
                //Set language to neutral to get neutral translations
                GitCommands.AppSettings.CurrentTranslation = "";

                var translatableTypes = TranslationUtl.GetTranslatableTypes();
                progressBar.Maximum = translatableTypes.Sum(types => types.Value.Count);
                progressBar.Visible = true;

                int index = 0;
                foreach (var types in translatableTypes)
                {
                    var translation = new TranslationFile();
                    try
                    {
                        foreach (Type type in types.Value)
                        {
                            ITranslate obj = TranslationUtl.CreateInstanceOfClass(type) as ITranslate;
                            if (obj != null)
                            {
                                obj.AddTranslationItems(translation);
                            }

                            progressBar.Value = index;
                            index++;
                            if (index % 10 == 0)
                            {
                                Update();
                            }
                        }
                    }
                    finally
                    {
                        translation.Sort();
                        _neutralTranslation[types.Key] = translation;
                    }
                }
            }
            finally
            {
                //Restore translation
                GitCommands.AppSettings.CurrentTranslation = null;
                progressBar.Visible = false;
            }
        }