예제 #1
0
        public void SetLanguage(string lang = "")
        {
            if (string.IsNullOrEmpty(lang))
            {
                lang = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
            }

            lock (syncLock)
            {
                var textResources = moduleLoader.GetAllInstancesOf <ITextResource>().Where(r => r.Lang == lang).ToList();
                if (textResources.Count < 1 && lang != "en")
                {
                    lang          = "en";
                    textResources = moduleLoader.GetAllInstancesOf <ITextResource>().Where(r => r.Lang == lang).ToList();
                }
                foreach (var r in textResources)
                {
                    if (resourcePaths.ContainsKey(r.ResourceKey))
                    {
                        resourcePaths[r.ResourceKey] = r.ResourcePath;
                    }
                    else
                    {
                        resourcePaths.Add(r.ResourceKey, r.ResourcePath);
                    }
                    LoadAndMerge(r.ResourcePath);
                }
                currentLanguage = lang;
                pbData.ChangeDefaultSetting("last_lang", currentLanguage);
                pbData.ChangeUserSetting("last_sync", null);
            }
            if (webAPI.CurrentLanguage != currentLanguage)
            {
                webAPI.SetLanguage(currentLanguage);
                ManualResetEvent evDone = new ManualResetEvent(false);
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        if (!sync.UpdateTranslations())
                        {
                            logger.Debug("UpdateTranslations failed");
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToString());
                    }
                    evDone.Set();
                });
                evDone.WaitOne();
            }
            //Updating text resources for tray menu
            SystemTray.SetLanguageForTrayMenuItems();

            //var m = FindWindow<MainWindow>();
            //if (m != null) m.Reload();
            Logout(true);
        }
예제 #2
0
        /// <summary>
        /// Language selection from combobox and binding dictionary based on selection
        /// </summary>
        /// <param name="sender"></param>
        private void LanguageSelectionChanged(object sender)
        {
            var languageComboBox = sender as ComboBox;

            if (languageComboBox == null)
            {
                return;
            }
            var selectedItem = (KeyValuePair <string, string>)languageComboBox.SelectedItem;

            Thread.CurrentThread.CurrentCulture   = new System.Globalization.CultureInfo(selectedItem.Key);
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(selectedItem.Key);

            //TODO save languag to DB
            Configuration config = new Configuration()
            {
                AccountEmail = DefaultProperties.Configuration_DefaultAccount, Key = "last_lang", Value = selectedItem.Key
            };

            pbData.AddOrUpdateConfiguration(config);
            pbData.ChangeDefaultSetting("last_selected_lang", selectedItem.Key);
            ((PBApp)System.Windows.Application.Current).SetLanguage(selectedItem.Key);

            //Disable Topmost property that is required only on Login language screen
            var _loginWindowInstance = _systemTray.CurrentWindow(CurrentLoginWindow);

            _loginWindowInstance.Topmost = false;

            inAppAnalyitics.Get <Events.AccountCreationFlow, AccountCreationFlowItem>().Log(new AccountCreationFlowItem(1, AccountCreationFlowSteps.LanguageSelection, selectedItem.Value, MarketingActionType.Continue));

            var loginWindow = ((PBApp)System.Windows.Application.Current).FindWindow <LoginWindow>();

            if (loginWindow == null)
            {
                throw new ApplicationException("Login language viewmodel, login window null");
            }

            //Navigator.NavigationService.Navigate(loginWindow.Login);
            loginWindow.NavigateloginScreens(!this.pbData.AnyAccountExists() ? "AccountCreation" : null);
        }