Пример #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);
        }