public void TranslateUIComponent(DependencyObject UIComponent)
        {
            LangIdEnum NewLang = GetLangId();

            if (NewLang == LangIdEnum.LangIdEnglish || NewLang == LangIdEnum.LangIdUnk)
            {
                return;
            }

            long StartTime = Environment.TickCount;

            //maybe this is a root object and does not have children
            if (UIComponent is DependencyObject)
            {
                TranslateOneElement(UIComponent, NewLang);
            }

            foreach (DependencyObject innerChild in FindLogicalChildren <Label, Button, CheckBox, GroupBox, RadioButton, HeaderedItemsControl, TextBlock>(UIComponent))
            {
                TranslateOneElement(innerChild, NewLang);
            }

            long Endtime = Environment.TickCount;

            if (Endtime - StartTime > 10)
            {
                Globals.Logger.LogString(LogManager.LogLevels.LogLevelDebug, "Translation of component took strangely long " + (Endtime - StartTime) + " ms for " + UIComponent.ToString());
            }
        }
        public string GetTranslation(string what, long Context = 0, LangIdEnum ToLang = LangIdEnum.LangIdUnk)
        {
            if (ToLang == LangIdEnum.LangIdUnk)
            {
                ToLang = GetLangId();
            }
            if (ToLang == LangIdEnum.LangIdUnk)
            {
                return(what);
            }
            long SearchedStrId = -1;

            //search for the ID of this string
            foreach (LangStringStore t in LangStrings)
            {
                if (t.LangId == LangIdEnum.LangIdEnglish && t.Str == what)
                {
                    SearchedStrId = t.StringId;
                    break;
                }
            }
            //could not find this string in our DB
            if (SearchedStrId == -1)
            {
                Globals.Logger.LogString(LogManager.LogLevels.LogFlagError, "No english match. Could not translate string : " + what);
                return(what);
            }
            // search the string with ID and lang we need
            foreach (LangStringStore t in LangStrings)
            {
                if (t.StringId == SearchedStrId && t.LangId == ToLang && (Context <= 0 || t.Context == Context))
                {
                    return(t.Str);
                }
            }
            //could not find the translation
            Globals.Logger.LogString(LogManager.LogLevels.LogFlagError, "No " + ToLang.ToString() + " match. Could not translate string : " + what);
            return(what);
        }
        private void TranslateOneElement(DependencyObject innerChild, LangIdEnum NewLang)
        {
            Label childTypeLabel = innerChild as Label;

            if (childTypeLabel != null && childTypeLabel.Content != null)
            {
                childTypeLabel.Content = GetTranslation(childTypeLabel.Content.ToString(), -1, NewLang);
                return;
            }
            Button childButton = innerChild as Button;

            if (childButton != null && childButton.Content != null)
            {
                childButton.Content = GetTranslation(childButton.Content.ToString(), -1, NewLang);
                return;
            }
            CheckBox childTypeCheckBox = innerChild as CheckBox;

            if (childTypeCheckBox != null && childTypeCheckBox.Content != null)
            {
                childTypeCheckBox.Content = GetTranslation(childTypeCheckBox.Content.ToString(), -1, NewLang);
                return;
            }
            RadioButton childTypeRadio = innerChild as RadioButton;

            if (childTypeRadio != null && childTypeRadio.Content != null)
            {
                childTypeRadio.Content = GetTranslation(childTypeRadio.Content.ToString(), -1, NewLang);
                return;
            }
            TextBlock childTypeTextBlock = innerChild as TextBlock;

            if (childTypeTextBlock != null && childTypeTextBlock.Text != null)
            {
                childTypeTextBlock.Text = GetTranslation(childTypeTextBlock.Text.ToString(), -1, NewLang);
                return;
            }

/*            TextBox childTypeTextbox = innerChild as TextBox;
 *          if (childTypeTextbox != null)
 *          {
 *              childTypeTextbox.Text = GetTranslation(childTypeTextbox.Text.ToString(), -1, NewLang);
 *              return;
 *          }*/
            HeaderedItemsControl childMenu = innerChild as HeaderedItemsControl;

            if (childMenu != null && childMenu.Header != null)
            {
                childMenu.Header = GetTranslation(childMenu.Header.ToString(), -1, NewLang);
                return;
            }
            GroupBox childGroup = innerChild as GroupBox;

            if (childGroup != null && childGroup.Header != null)
            {
                childGroup.Header = GetTranslation(childGroup.Header.ToString(), -1, NewLang);
                return;
            }
            Window childWindow = innerChild as Window;

            if (childWindow != null && childWindow.Title != null)
            {
                childWindow.Title = GetTranslation(childWindow.Title.ToString(), -1, NewLang);
                return;
            }
        }