コード例 #1
0
 void Load(string filePath, string key, DependencyObject target)
 {
     try
     {
         var json = File.ReadAllText(filePath);
         _applicationLocalize         = Newtonsoft.Json.JsonConvert.DeserializeObject <ApplicationLocalize>(json);
         _applicationLocalize.Culture = LocalizeDictionary.Instance.Culture;
     }
     catch (Exception ex)
     {
         var message = $"Provider IO exception: {ex.InnerException?.Message ?? ex.Message ?? "Unknown error"}";
         ProviderError?.Invoke(this, new ProviderErrorEventArgs(target, key, message));
     }
 }
コード例 #2
0
        ApplicationLocalize GetApplicationLocalize(string key, DependencyObject target, CultureInfo culture)
        {
            if (target is EnumComboBox)
            {
                var a = 1;
            }
            if (_applicationLocalize == null || _applicationLocalize.Culture != LocalizeDictionary.Instance.Culture)
            {
                var applicationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Localize\";
                var filePath        = string.Empty;

                while (culture != CultureInfo.InvariantCulture)
                {
                    filePath = Path.Combine(applicationPath, _localizeFileName + (String.IsNullOrWhiteSpace(culture.Name) ? "" : "." + culture.Name) + ".json");

                    if (File.Exists(filePath))
                    {
                        break;
                    }
                    culture = culture.Parent;
                }


                if (File.Exists(filePath) == false)
                {
                    filePath = Path.Combine(applicationPath, _localizeFileName + ".json");

                    if (!File.Exists(filePath))
                    {
                        _applicationLocalize         = new ApplicationLocalize();
                        _applicationLocalize.Culture = LocalizeDictionary.Instance.Culture;
                    }
                    else
                    {
                        Load(filePath, key, target);
                    }
                }
                else
                {
                    Load(filePath, key, target);
                }
            }
            return(_applicationLocalize);
        }