diff --git a/src/Providers/ResxLocalizationProviderBase.cs b/src/Providers/ResxLocalizationProviderBase.cs
index c96469ed..f76185e3 100644
--- a/src/Providers/ResxLocalizationProviderBase.cs
+++ b/src/Providers/ResxLocalizationProviderBase.cs
@@ -470,6 +470,13 @@ string TryGetNamespace(Type type)
// remove ".resources" from the end
foundResource = foundResource.Substring(0, foundResource.Length - ResourceFileExtension.Length);
+ if (TryCreateResourceManager(foundResource, assembly, out ResourceManager resourceManager))
+ {
+ CacheResourceManager(resManKey, resourceManager);
+
+ return resourceManager;
+ }
+
// First try the simple retrieval
Type resourceManagerType;
try
@@ -519,27 +526,46 @@ bool MatchesDictTypeName(Type type)
if (resManager == null)
throw new ArgumentException(string.Format("No resource manager for dictionary '{0}' in assembly '{1}' found! ({1}.{0})", resourceDictionary, resourceAssembly));
- // Add the ResourceManager to the cachelist
- Add(resManKey, resManager);
+ CacheResourceManager(resManKey, resManager);
+ }
- try
- {
- // Look in all cultures and check available ressources.
- foreach (var c in SearchCultures)
- {
- var rs = resManager.GetResourceSet(c, true, false);
- if (rs != null)
- AddCulture(c);
- }
- }
- catch
+ // return the found ResourceManager
+ return resManager;
+ }
+
+ private void CacheResourceManager(string resManKey, ResourceManager resManager)
+ {
+ // Add the ResourceManager to the cachelist
+ Add(resManKey, resManager);
+
+ try
+ {
+ // Look in all cultures and check available ressources.
+ foreach (var c in SearchCultures)
{
- // ignored
+ var rs = resManager.GetResourceSet(c, true, false);
+ if (rs != null)
+ AddCulture(c);
}
}
+ catch
+ {
+ // ignored
+ }
+ }
- // return the found ResourceManager
- return resManager;
+ private bool TryCreateResourceManager(string resourceManagerBaseName, Assembly resourceManagerAssembly, out ResourceManager resourceManager)
+ {
+ try
+ {
+ resourceManager = new ResourceManager(resourceManagerBaseName, resourceManagerAssembly);
+ }
+ catch
+ {
+ resourceManager = null;
+ }
+
+ return resourceManager != null;
}
private ResourceManager GetResourceManagerFromType(IReflect type)
@@ -561,9 +587,9 @@ private ResourceManager GetResourceManagerFromType(IReflect type)
return null;
}
}
- #endregion
+#endregion
- #region ILocalizationProvider implementation
+#region ILocalizationProvider implementation
///
/// Uses the key and target to build a fully qualified resource key (Assembly, Dictionary, Key)
///
@@ -711,6 +737,6 @@ public virtual object GetLocalizedObject(string key, DependencyObject target, Cu
/// An observable list of available cultures.
///
public ObservableCollection AvailableCultures { get; protected set; }
- #endregion
+#endregion
}
}
diff --git a/tests/HelloWorldWPF.NoDesignFiles.sln b/tests/HelloWorldWPF.NoDesignFiles.sln
new file mode 100644
index 00000000..699c6d81
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles.sln
@@ -0,0 +1,51 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30011.22
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WPFLocalizeExtension", "..\src\WPFLocalizeExtension.csproj", "{3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWorldWPF.NoDesignFiles", "HelloWorldWPF.NoDesignFiles\HelloWorldWPF.NoDesignFiles.csproj", "{585EA5B3-C6A5-4444-8890-4D06561B4914}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|Mixed Platforms = Debug|Mixed Platforms
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|Mixed Platforms = Release|Mixed Platforms
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Debug|x86.Build.0 = Debug|Any CPU
+ {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Release|x86.ActiveCfg = Release|Any CPU
+ {3B2FA6D1-6EC0-4C0F-BDF0-D90158904ED3}.Release|x86.Build.0 = Release|Any CPU
+ {585EA5B3-C6A5-4444-8890-4D06561B4914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {585EA5B3-C6A5-4444-8890-4D06561B4914}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {585EA5B3-C6A5-4444-8890-4D06561B4914}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {585EA5B3-C6A5-4444-8890-4D06561B4914}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {585EA5B3-C6A5-4444-8890-4D06561B4914}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {585EA5B3-C6A5-4444-8890-4D06561B4914}.Debug|x86.Build.0 = Debug|Any CPU
+ {585EA5B3-C6A5-4444-8890-4D06561B4914}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {585EA5B3-C6A5-4444-8890-4D06561B4914}.Release|Any CPU.Build.0 = Release|Any CPU
+ {585EA5B3-C6A5-4444-8890-4D06561B4914}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {585EA5B3-C6A5-4444-8890-4D06561B4914}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {585EA5B3-C6A5-4444-8890-4D06561B4914}.Release|x86.ActiveCfg = Release|Any CPU
+ {585EA5B3-C6A5-4444-8890-4D06561B4914}.Release|x86.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {F0544A03-17E3-4EFB-BB50-4EDEB145B721}
+ EndGlobalSection
+EndGlobal
diff --git a/tests/HelloWorldWPF.NoDesignFiles/App.xaml b/tests/HelloWorldWPF.NoDesignFiles/App.xaml
new file mode 100644
index 00000000..8da038e1
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles/App.xaml
@@ -0,0 +1,7 @@
+
+
+
diff --git a/tests/HelloWorldWPF.NoDesignFiles/App.xaml.cs b/tests/HelloWorldWPF.NoDesignFiles/App.xaml.cs
new file mode 100644
index 00000000..70be8cad
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles/App.xaml.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
+using System.Linq;
+using System.Windows;
+
+namespace HalloWeltWPF
+{
+ ///
+ /// Interaction logic for App.xaml
+ ///
+ public partial class App : Application
+ {
+ }
+}
diff --git a/tests/HelloWorldWPF.NoDesignFiles/HelloWorldWPF.NoDesignFiles.csproj b/tests/HelloWorldWPF.NoDesignFiles/HelloWorldWPF.NoDesignFiles.csproj
new file mode 100644
index 00000000..d33b0574
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles/HelloWorldWPF.NoDesignFiles.csproj
@@ -0,0 +1,42 @@
+
+
+
+
+ netcoreapp3.1
+ HalloWeltWPF
+ WinExe
+
+ True
+ true
+ HelloWorldWPF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/HelloWorldWPF.NoDesignFiles/MainWindow.xaml b/tests/HelloWorldWPF.NoDesignFiles/MainWindow.xaml
new file mode 100644
index 00000000..4c4fba01
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles/MainWindow.xaml
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/HelloWorldWPF.NoDesignFiles/MainWindow.xaml.cs b/tests/HelloWorldWPF.NoDesignFiles/MainWindow.xaml.cs
new file mode 100644
index 00000000..68d821be
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles/MainWindow.xaml.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Globalization;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using WPFLocalizeExtension.Engine;
+using WPFLocalizeExtension.Providers;
+
+namespace HalloWeltWPF
+{
+ ///
+ /// Interaction logic for MainWindow.xaml
+ ///
+ public partial class MainWindow : Window
+ {
+ TestVM vm = new TestVM();
+
+ public MainWindow()
+ {
+ vm.language = "de";
+ vm.color = "Background";
+ vm.Hours = 0;
+ this.DataContext = vm;
+
+ LocalizeDictionary.Instance.Culture = new System.Globalization.CultureInfo("de");
+ (LocalizeDictionary.Instance.DefaultProvider as ResxLocalizationProvider).SearchCultures =
+ new List()
+ {
+ System.Globalization.CultureInfo.GetCultureInfo("de-de"),
+ System.Globalization.CultureInfo.GetCultureInfo("en"),
+ System.Globalization.CultureInfo.GetCultureInfo("he"),
+ System.Globalization.CultureInfo.GetCultureInfo("ar"),
+ };
+ LocalizeDictionary.Instance.OutputMissingKeys = true;
+ LocalizeDictionary.Instance.MissingKeyEvent += Instance_MissingKeyEvent;
+ }
+
+ private void Instance_MissingKeyEvent(object sender, MissingKeyEventArgs e)
+ {
+ e.MissingKeyResult = "Hello World";
+ }
+
+ private void BindeTestButton_Click(object sender, RoutedEventArgs e)
+ {
+ vm.Hours = vm.Hours + 1;
+
+ vm.language = vm.language switch
+ {
+ "en" => "de",
+ "de" => "error",
+ _ => "en",
+ };
+ if (vm.tenum == TestVM.TestEnum.Test1)
+ vm.tenum = TestVM.TestEnum.Test2;
+ else
+ vm.tenum = TestVM.TestEnum.Test1;
+ }
+ }
+}
diff --git a/tests/HelloWorldWPF.NoDesignFiles/Properties/AssemblyInfo.cs b/tests/HelloWorldWPF.NoDesignFiles/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000..7a6e9d52
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles/Properties/AssemblyInfo.cs
@@ -0,0 +1,28 @@
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Windows;
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+//In order to begin building localizable applications, set
+//CultureYouAreCodingWith in your .csproj file
+//inside a . For example, if you are using US english
+//in your source files, set the to en-US. Then uncomment
+//the NeutralResourceLanguage attribute below. Update the "en-US" in
+//the line below to match the UICulture setting in the project file.
+
+//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
diff --git a/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.ar.resx b/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.ar.resx
new file mode 100644
index 00000000..d3f27cdb
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.ar.resx
@@ -0,0 +1,144 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ العربية
+
+
+ ألماني
+
+
+ الإنجليزية
+
+
+ RightToLeft
+
+
+ العبرية
+
+
+ مرحبا العالم!
+
+
+ مثال
+
+
+ Yellow
+
+
\ No newline at end of file
diff --git a/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.de.resx b/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.de.resx
new file mode 100644
index 00000000..e631bc59
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.de.resx
@@ -0,0 +1,144 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ Arabisch
+
+
+ Deutsch
+
+
+ Englisch
+
+
+ LeftToRight
+
+
+ Hebräisch
+
+
+ Hallo Welt!
+
+
+ Beispiel
+
+
+ White
+
+
\ No newline at end of file
diff --git a/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.en.resx b/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.en.resx
new file mode 100644
index 00000000..20ede2b6
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.en.resx
@@ -0,0 +1,159 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ Arabic
+
+
+ German
+
+
+ English
+
+
+ LeftToRight
+
+
+ Hebrew
+
+
+ Hello World!
+
+
+ Example
+
+
+ White
+
+
+ Hello Test 1
+
+
+ Hello Test 2
+
+
+ Hallo Test1
+
+
+ Hallo Test 2
+
+
+ Hello World! {0} {0:one|default}
+
+
\ No newline at end of file
diff --git a/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.he.resx b/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.he.resx
new file mode 100644
index 00000000..60830171
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.he.resx
@@ -0,0 +1,144 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ ערבית
+
+
+ גרמנית
+
+
+ אנגלית
+
+
+ RightToLeft
+
+
+ עברית
+
+
+ שלום עולם!
+
+
+ דוגמה
+
+
+ Blue
+
+
\ No newline at end of file
diff --git a/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.resx b/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.resx
new file mode 100644
index 00000000..401fa000
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles/Ressourcen.resx
@@ -0,0 +1,144 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ ar
+
+
+ de
+
+
+ en
+
+
+ FlowDirection
+
+
+ he
+
+
+ MyLabel_Text
+
+
+ Title
+
+
+ Background
+
+
\ No newline at end of file
diff --git a/tests/HelloWorldWPF.NoDesignFiles/TestVM.cs b/tests/HelloWorldWPF.NoDesignFiles/TestVM.cs
new file mode 100644
index 00000000..27c70797
--- /dev/null
+++ b/tests/HelloWorldWPF.NoDesignFiles/TestVM.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Navigation;
+
+namespace HalloWeltWPF
+{
+ public class TestVM : INotifyPropertyChanged
+ {
+ #region INotifyPropertyChanged Implementation
+ ///
+ /// Informiert über sich ändernde Eigenschaften.
+ ///
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ ///
+ /// Notify that a property has changed
+ ///
+ ///
+ /// The property that changed
+ ///
+ internal void RaisePropertyChanged(string property)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
+ }
+ #endregion
+
+ public enum TestEnum
+ {
+ Test1,
+ Test2
+ }
+
+ private TestEnum _tenum;
+ public TestEnum tenum {
+ get => _tenum;
+ set {
+ _tenum = value;
+ RaisePropertyChanged(nameof(tenum));
+ }
+ }
+
+ private int _hours;
+ public int Hours
+ {
+ get => _hours;
+ set
+ {
+ _hours = value;
+ RaisePropertyChanged(nameof(Hours));
+ }
+ }
+
+ private string _language;
+ public string language
+ {
+ get => _language;
+ set
+ {
+ _language = value;
+ RaisePropertyChanged(nameof(language));
+ }
+ }
+
+ private string _color;
+ public string color {
+ get => _color;
+ set {
+ _color = value;
+ RaisePropertyChanged(nameof(color));
+ }
+ }
+ }
+}