Enumerating translated .resx resources at runtime in WPF application - wpf

I've been doing localization for my WPF application by storing strings in .resx files. My default (english) string resource is strings.resx. For other languages are called strings.fr-FR.resx for French, strings.es-ES.resx for Spanish and so on.
This method of localization has been great as my app will automatically load up the right string when I set the Globalization region to a matching locale, and defaults to English when there isn't.
Is it possible at runtime to enumerate which languages are in my Assembly?
I could get around this and hard code in which languages are included, but this can change from build to build as a build server is putting together the language resx's and building dynamically.

I see two options, none of which is ideal...
Enumerate all known cultures (CultureInfo.GetCultures), and try to get a given ressource for this culture => simple but slow
Look for satellite assemblies in your application's directory : for each subdirectory, check if it's name corresponds to a culture name (CultureInfo.GetCultureInfo), and if it contains a .resources.dll file

Related

Prevent WPFLocalizeExtension from trying to load resources for all possible languages

I am just beginning to use the WPFLocalizeExtension in a project. It works, but it has a serious impact on the startup performance of the app. It tries to load the resources for all possible languages, including many which we won't ever provide resources for. Normally that might happen without notice, but in this case we have a special folder structure for some of the loaded assemblies. Although the resource DLLs are still situated in language folders directly beneath the folder of the executable, but the app gets an AssemblyResolve event for every language.
Thanks for your help in advance.
We had the same problem and approached it by modifying the WPFLocalizeExtension source code.
When you have a look at the code, you will find a class called ResxLocalizationProviderBase. This class includes a method GetResourcemanager, which causes the massive amounts of AssemblyResolve events, because it tries to get the resource set of all cultures that ship with the .NET Framework (line 498):
var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (var c in cultures)
{
...
}
We modified the code by creating a list of CultureInfo objects, that includes only languages, we'd like to provide resources for.

using a resource dictionary in multiple applications

Is there a way to use a resource dictionary in multiple applications? What I have is a theme generator which uses merged dictionaries etc... works GREAT! I'm looking for a way to reference this project for the resource dictionaries into all my applications. (thus, having my theme engine in every File>New I decide to create) So far my research has led me to nothing.
Ok so I've found out that I can use the pack URI syntax to grab the resource dictionaries from application A and use them in application B
First I made a classlibrary and removed the default class1.cs
Then I added a new item (there was no option for a .xaml file so I added a .xml file and changed the extension)
Then moved the resource dictionary code into that file.
Referenced the new .dll as you would any other and now I can access the resource dictionary file using the below syntax.
<ResourceDictionary Source = "pack://application:,,,/App_A;Component/App_A_ResourceDictionary.xaml"/>
When swapping the files its the same syntax only omit the "pack://application,,," part.
Although this wasn't everything I wanted (so far) it has been the best solution I've found.
The part now that I want is the ability to house the swapping logic within the .dll. If I can do that... then my theme library can be PnP to any app with minimum fuss.

Accessing external static resources placed in different assembly and XAP

My prism based silveright application is divided into multiple xaps to reduce initial download size and support multi tenant application.
However, I cannot access the resource dictionaries defined in external assembly (i.e. the resource .xaml file is part of an assembly that complies/ is copied into a different xap)
Any suggestions ? because the standard syntax for accessing external resources files does not work
The book Pro Silverlight 2 in VB 2008 (p166) [MacDonald] says "Unfortunately, Silverlight doesn't currently allow you to merge resource dictionaries, which means there is no way to split your application resources into separate files and then merge them into your application (which is possible in WPF)." I don't know if things have changed since then, but I would suggest that is the reason.

What would be the easiest way to generate new localized resource files?

My windows forms application consists of one Visual Studio solution and several projects. The application is localized in English and French using resource files (each project has global resource files, e.g. fooResources.resx and fooResources.fr.resx, and each form/user control has its own resource files (e.g. fooForm.resx and fooForm.fr.resx) - so lets say for arguments sake I have about 30 sets of resource files.
I now have to extract all the strings to be sent for translation into German, then when I receive the translated strings create German resource files (e.g. fooResources.de.resx and fooForm.de.resx) which contain the new captions.
Obviously I could do all of this manually, but I am a developer and thus by nature lazy! No, just kidding - but I would appreciate some suggestions on the most painless way to do this as I am sure more languages will be coming in the future.
Thanks.
I'm the author of a translation product that makes the job very easy for both the developer and the translator. See http://www.hexadigm.com.
I've dealt with this a few different ways. I have worked with translators that are more than willing to work with .ResX files and will create the files as needed (though you may have to rename them to the proper locale code.
Otherwise, the contents of the resource files are purely XML. I wrote a little program that drops the xml data into a datagrid, and then imports the CSV or Excel file in using the key as a UID.

Change resource file on the fly

I woulld like to localize my WPF application with resource files. It good technics. But I have requirement to give ability to end user to change some localization information (for example some word traslation). It means change information in the resourse files on the fly (in run time). Is it possible ?
This would involve recompiling the resources on the fly; and reloading them will be quite difficult (as DLLs cannot be unloaded without unloading an AppDomain).
In such a configuration, you're better off using the database to store your translations.

Resources