コード例 #1
0
        /// <summary>
        /// Load language files
        /// </summary>
        public static List <MultiLangEngine> LoadLanguages()
        {
            List <MultiLangEngine> languages = new List <MultiLangEngine>();

            /* Check if language dir exists
             * 1. If it does, scan it
             * 2. If it doesn't, skip it
             */
            string langPath = Environment.CurrentDirectory + @"\lang\";

            if (Directory.Exists(langPath))
            {
                // 1
                languages = MultiLangEngine.ScanDirectory(langPath);
            }

            /*
             * Load built-in language files
             */
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml(Properties.Resources.dwas2_en_US);
                languages.Add(new MultiLangEngine(xmldoc));
                xmldoc.LoadXml(Properties.Resources.dwas2_zh_CN);
                languages.Add(new MultiLangEngine(xmldoc));
            }
            catch (Exception ex)
            {
                // skip
            }

            return(languages);
        }
コード例 #2
0
        /// <summary>
        /// Apply MLE on some UI elements of a dependency object
        /// </summary>
        /// <param name="lang">the MLE</param>
        /// <param name="depObj">the dependency object</param>
        public static void ApplyUILanguage(MultiLangEngine lang, DependencyObject depObj)
        {
            Type[] types = { typeof(TextBlock), typeof(Button), typeof(Label) };

            foreach (Type T in types)
            {
                ApplyLanguageOfOneType(lang, T, "Text", depObj);
            }
        }
コード例 #3
0
        /// <summary>
        /// Apply MLE on a type of UI elements of a dependency object
        /// </summary>
        /// <param name="lang">the MLE</param>
        /// <param name="T">the type of UI element</param>
        /// <param name="propertyName">the property consisting the string to set</param>
        /// <param name="depObj">the dependency object</param>
        public static void ApplyLanguageOfOneType(MultiLangEngine lang, Type T, string propertyName, DependencyObject depObj)
        {
            MethodInfo m = typeof(WPFHelper).GetMethod("FindVisualChildren", BindingFlags.Public | BindingFlags.Static);

            m = m.MakeGenericMethod(T);
            foreach (object obj in (IEnumerable)m.Invoke(null, new Object[] { depObj }))
            {
                PropertyInfo theProperty = obj.GetType().GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);
                if (theProperty != null)
                {
                    theProperty.SetValue(obj, theProperty.GetValue(obj, null).ToString().t(lang), null);
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Select a language (MLE)
 /// </summary>
 /// <param name="languages">the list of MLEs</param>
 /// <param name="preferred">a preferred language</param>
 /// <returns>selected MLE</returns>
 public static MultiLangEngine SelectLanguage(List <MultiLangEngine> languages, string preferred)
 {
     /* Determine the UI language
      * 1. Try to use preferred language
      * 2. Try to use system language
      * 3. Use languages[0]
      */
     if (languages.Count < 1)
     {
         return(new MultiLangEngine());
     }
     else
     {
         MultiLangEngine theLang = null;
         languages.ForEach(l =>
         {
             if (string.Compare(l.Language, preferred) == 0)
             {
                 theLang = l;
             }
         });
         if (theLang != null)
         {
             // 1
             return(theLang);
         }
         else
         {
             // 2
             string sysLang = System.Globalization.CultureInfo.CurrentUICulture.Name;
             languages.ForEach(l =>
             {
                 if (l.Language.ToLower().Contains(sysLang.ToLower()))
                 {
                     theLang = l;
                 }
             });
             if (theLang != null)
             {
                 return(theLang);
             }
             else
             {
                 // 3
                 return(languages[0]);
             }
         }
     }
 }
コード例 #5
0
        public MainWindow()
        {
            InitializeComponent();

            // init logger
            string logpath = System.AppDomain.CurrentDomain.BaseDirectory + @"\DWAS2.log";

            GeneralLogger.Initialize(logpath);

            // read and process configuration
            config.ReadConfig();
            ProcessConfig();

            // check hiding
            if (File.Exists(config.wpLandscape) && File.Exists(config.wpPortrait) && File.Exists(config.lcLandscape) && File.Exists(config.lcPortrait))
            {
                this.shouldHideAtStartup = true;
            }

            // read language
            languages = DWAS2LanguageManager.LoadLanguages();
            lang      = DWAS2LanguageManager.SelectLanguage(languages, config.language);
            if (lang.Language.CompareTo(config.language) != 0)
            {
                config.language = lang.Language;
                config.SaveConfig();
            }
            // LANGUAGE IS PROCESSED IN WINDOW_LOADED EVENT HANDLER

            // read orientation
            lastOrientation = DWAS2Interop.GetDesktopOrientation(config.reverse);

            // notify icon
            InitNotifyIcon();

            // initial set
            UpdateDetection();

            // start timer
            InitTimer();
        }