In a c# application I have a resource file with English strings (strings.resx) and several localized versions of that (strings.es.resx, strings.fr.resx, etc.). When compiling, the base strings are included in the assembly, each extra localized resource file is compiled into a .dll file that is put in a folder named like the language code (e.g. es/<appname>.resource.dll).
So far I bundled all the localized dll files with the app. I guess most users only need at most one extra localized resource file, so I want to ship the app without the extra localized files and only download them if needed. Assuming the user installed the app in program files or another protected folder, I want to save the localized files in a folder in %localAppData%.
How do I load the localized resource file if they are not in the app folder? Currently they're all in the source folder local/strings.resx, local/strings.es.resx, etc. and I can load them with
var rm = new ResourceManager("MyApplication.local.strings", typeof(Form1).Assembly);
to have the strings with the current CultureInfo.
I'd like to tell the app: load the strings but also check this specific folder (e.g. %localAppData%/MyApplication/local) for localized versions of that resource file.
Related
I have an app on Windows Embedded which uses .resx files to translate the app to different languages.
Also I create an installation .cab file but I can't include the resx file to this cab.
How can I achieve this?
Thanks for any tip
A few things:
You'd not told us how you're trying to add the file. Are you using a custom INF file and just calling CABWIZ or are you using a Visual Studio Installer Project?
What have you done to try to include the file?
Most importantly, a RESX file does not contain the run-time resources and you rarely would deploy it. The RESX resources get compiled into a *.resource.dll assembly, that is typically in a subfolder with a name for the locale (e.g. en-us or fr-ca). You need to deploy those files/folders which is challenging because CABWIZ doesn't allow duplicate file names (and all resources have the same file name, just different folders). That scenario is handled by this SO question.
I have a file localized for some languages. I mean Countries_fr.xml, Countries_en.xml, Countries_de.xml and so on.
I want each culture load its own file, when I do something like this:
App.ViewModel.LoadData(MyApp.Resources.AppResources.Countries);
(Is this correct?)
Then if the user's culture is french the french file get loaded.
My Question is: what should the name of these files be? is there an specific pattern?
And what is the way of adding these files, should I add them directly to References folder in designer or I should Open AppResources.resx and add these as a file to it?
You don't need to add localization files manually. Just go to your project properties and tick the languages you want to support in your app. Visual Studio will automatically add the resource files for the languages you chose under the Resources folder.
I am localizing a WPF application using .resx files. I created copies of main Resources files like Resources.en-US.resx or Resources.cs-CZ.resx. Works well for strings. However, I can't figure out how to localize other files like images or documents in resource files.
When I add a new image to Resources file (either Resources.en-US.resx or Resources.cs-CZ.resx), a copy of the file is always copied to /Resources directory. So there cannot be multiple versions of one file for multiple languages, because in one directory there can be only one file with same name.
Ideal solution would be if images from localized resources would be copied in subdirectories like /Resources/en-Us. In current conditions, I am unable to localize images and documents using .resx files. Any ideas how I can achieve this? Thank you.
The following MSDN post Resources and Localization in ASP.NET 2.0 - Displaying Localized Images states:
While ASP.NET 2.0 doesn't directly support localizing image files, it doesn't require too much custom code to achieve the desired effect.
And provides the following work around:
You can start by adding the localized versions of an image file to localized versions of a global resource file. For example, the English version of LitwareSlogan.png has been added to the global resource file named Litware.resx while the French version of LitwareSlogan.fr.png has been added to Litware.fr.resx. The resources in both resource files have been given the same name of LitwareSlogan.
Complete sample code is provided at the site.
I have a C# application that is being internationalized. I want to keep all of my language resource directories (en-US, es-SP, etc...) in a single directory called "languages" within the installation directory, so that the file path would be something like C:\application\
languages\en-US\resource.dll for each compiled resource file.
Unfortunately, the .dll that references the language resource file is in the C:\application\mainprogram.dll location. What do I need to set in Visual Studio so that mainprogram.dll can correctly access all of my language resource dll files?
Also of note is that the language resource files work fine if all of their folders are on the same level as the mainprogram.dll file.
You can specify additional private paths using the Probing Element in your configuration.
Alternatively and probably more than you would need:
You can hook in to the AppDomains Assembly resolve event which gets called every time it fails to find an assembly via standard probing.
I know I can add resources to Resources.resx file and then use it like properties.resources.MyFile.dat.
But what is the difference when I simply add file to Resources folder (setting it to embedded) and Copy to output dir to Always copy and access it like "\Resources\Data\file.dat"?
Also this is another way how to add resources?
There are two core differences:
When you have your resources inside a .resources file, they are normally embedded on your assembly (the .exe or .dll file) instead of having their own file.
When the resource is embedded on your assembly, you can rely on the .Net Framework's localization infrastructure to have localized versions of it if the need arises.
In summary:
For resources you'll need to localize, embed.
For resources you'll need to change from the program, use stand-alone files.
For everything else, it's just a matter of taste.