using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.IO;

namespace PlayBackDemo
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            LoadLanguage();
        }

        /// <summary>
        /// load language
        /// </summary>
        private void LoadLanguage()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "Language";
            string fileNamePath = string.Empty;
            ResourceDictionary resourceDictionary = new ResourceDictionary();
            switch (System.Globalization.CultureInfo.CurrentCulture.LCID)
            {
                case 0x00804:
                    fileNamePath = path + "\\zh-cn.xaml";
                    if (!File.Exists(fileNamePath))
                    {
                        resourceDictionary.Source = new Uri("pack://application:,,,/language/zh-cn.xaml");
                    }
                    else
                    {
                        resourceDictionary.Source = new Uri(fileNamePath, UriKind.RelativeOrAbsolute);
                    }
                    break;
                default:
                    fileNamePath = path + "\\en-us.xaml";
                    if (!File.Exists(fileNamePath))
                    {
                        resourceDictionary.Source = new Uri("pack://application:,,,/language/en-us.xaml");
                    }
                    else
                    {
                        resourceDictionary.Source = new Uri(fileNamePath, UriKind.RelativeOrAbsolute);
                    }
                    break;
            }
            App.Current.Resources.MergedDictionaries.Add(resourceDictionary);
        }
    }
}
