Пример #1
0
        public void Cleanup()
        {
            if (string.IsNullOrEmpty(ParentLocale))
            {
                return;
            }

            var manager = new LocaleManager();

            foreach (var collection in StringCollections.Values)
            {
                var deleteList = new List <string>();
                foreach (var key in collection.StringsTable.Keys)
                {
                    try
                    {
                        var translation = manager.Locales[ParentLocale].GetString(collection.Key, key);
                        if (translation.AliasedKey)
                        {
                            deleteList.Add(key);
                        }
                    }
                    catch (KeyNotFoundException)
                    {
                        deleteList.Add(key);
                    }
                }

                foreach (var key in deleteList)
                {
                    collection.StringsTable.Remove(key);
                }
            }
        }
Пример #2
0
        public Translator(LocaleManager localeManager, Locale parentLocale = null)
        {
            _localeManager = localeManager;
            _parentLocale = parentLocale;
            InitializeComponent();

            imageList1.Images.Add(@"red", Properties.Resources.red);
            imageList1.Images.Add(@"orange", Properties.Resources.orange);
            imageList1.Images.Add(@"green", Properties.Resources.green);
        }
Пример #3
0
        public void Cleanup()
        {
            bool rootLocale = string.IsNullOrEmpty(ParentLocale);

            //Operations on root locale only
            if (rootLocale)
            {
                foreach (var collection in StringCollections.Values)
                {
                    foreach (var key in collection.StringsTable.Keys)
                    {
                        var st = GetString(collection.Key, key);

                        //No version 0 allowed, except for special strings
                        if (st.Key == "MinimumHeight" || st.Key == "MinimumWidth")
                        {
                            st.Version = 0;
                        }
                        else if (st.Version == 0)
                        {
                            st.Version = 1;
                        }
                    }
                }
            }

            //Operations based on presence of parent locale
            if (!rootLocale)
            {
                var manager = new LocaleManager();
                foreach (var collection in StringCollections.Values)
                {
                    var deleteList = new List <string>();
                    foreach (var key in collection.StringsTable.Keys)
                    {
                        try
                        {
                            var st = GetString(collection.Key, key);                               //stringTranslation
                            var pt = manager.Locales[ParentLocale].GetString(collection.Key, key); //parentTranslation

                            //If the translation is an exact match of the parent, derive it from the parent
                            if (!(st.DeriveFromParent || st.AliasedKey) &&
                                string.Compare(st.Value, pt.Value, StringComparison.InvariantCulture) == 0)
                            {
                                st.DeriveFromParent = true;
                                st.Value            = null;
                            }

                            //Remove existing key if the *parent* is now a derived key of another object
                            if (pt.AliasedKey)
                            {
                                deleteList.Add(key);
                            }
                        }
                        catch (KeyNotFoundException)
                        {
                            //If this key isn't in the parent dictionary, don't include it (it's an orphaned key)
                            deleteList.Add(key);
                        }
                    }

                    foreach (var key in deleteList)
                    {
                        if (collection.StringsTable.ContainsKey(key))
                        {
                            collection.StringsTable.Remove(key);
                        }
                    }
                }
            }
        }
Пример #4
0
        private LoadFolderResult OpenFolder(string localeFolder)
        {
            _localeManager = new LocaleManager
                             	{
                             		LocaleRoot = localeFolder
                             	};
            _localeManager.LoadLocales();

            if(_localeManager.Locales.Count == 0)
            {
                var result =
                    MessageBox.Show(
                        "No valid locales were detected in the selected folder. This is either an empty project, or the wrong folder was selected.\r\n\r\nDo you want to continue loading this project?",
                        "No Locales Found", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

                if(result == DialogResult.Yes)
                    return LoadFolderResult.Success;

                _localeManager = null;

                if(result == DialogResult.No)
                    return LoadFolderResult.Retry;

                if(result == DialogResult.Cancel)
                    return LoadFolderResult.Cancel;
            }

            return LoadFolderResult.Success;
        }