Пример #1
0
        public void CreateInstanceOfClass()
        {
            // just reference to GitUI
            MouseWheelRedirector.Active = true;

            var translatableTypes = TranslationUtil.GetTranslatableTypes();

            var testTranslation = new Dictionary <string, TranslationFile>();

            foreach (var(key, types) in translatableTypes)
            {
                var translation = new TranslationFile();
                foreach (Type type in types)
                {
                    try
                    {
                        var obj = (ITranslate)TranslationUtil.CreateInstanceOfClass(type);

                        obj.AddTranslationItems(translation);
                        obj.TranslateItems(translation);
                    }
                    catch
                    {
                        Trace.WriteLine("Problem with class: " + type.FullName);
                        throw;
                    }
                }

                testTranslation[key] = translation;
            }
        }
Пример #2
0
        public void CreateInstanceOfClass()
        {
            UserEnvironmentInformation.Initialise("", false);
            var translatableTypes = TranslationUtil.GetTranslatableTypes();

            var problems = new List <(string typeName, Exception exception)>();

            foreach (var types in translatableTypes.Values)
            {
                var translation = new TranslationFile();

                foreach (var type in types)
                {
                    try
                    {
                        var obj = (ITranslate)TranslationUtil.CreateInstanceOfClass(type);

                        obj.AddTranslationItems(translation);
                        obj.TranslateItems(translation);
                    }
                    catch (Exception ex)
                    {
                        problems.Add((type.FullName, ex));
                    }
                }
            }

            if (problems.Count != 0)
            {
                Assert.Fail(string.Join(
                                "\n\n--------\n\n",
                                problems.Select(p => $"Problem with type {p.typeName}\n\n{p.exception}")));
            }
        }
        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)
                {
                    TranslationFile translation = new();
                    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));
        }
Пример #4
0
        private void FillNeutralTranslation()
        {
            try
            {
                // Set language to neutral to get neutral translations
                GitCommands.AppSettings.CurrentTranslation = "";

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

                int index = 0;
                foreach (var(key, types) in translatableTypes)
                {
                    var translation = new TranslationFile();
                    try
                    {
                        foreach (Type type in types)
                        {
                            if (TranslationUtil.CreateInstanceOfClass(type) is ITranslate obj)
                            {
                                obj.AddTranslationItems(translation);
                            }

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