How to name localized "Files" for binding in Windows Phone 8? - c#

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.

Related

Load localized resources from custom location

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.

Add resx to cab file

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.

Proper procedure to import existing RESX files into a C#/WPF project

I have my auto generated Resource.resx file set up with keys and strings. I also have three other resx files for German, French and Spanish given to me from translators. I'm not able to get the localization functioning and I suspect that the resx files aren't being called correctly. I added them to the project by dragging them into the solution explorer under "Properties". I have a nagging suspicion that just dragging them in isn't creating the proper connections behind the scene.
Now It's totally possible my issue lies somewhere else. If anyone can tell me whether it's ok to add resource files this way or if not, what the correct way is, it would save me tons of time spent chasing my tail. Thanks!
Resx files in Visual Studio include a special tool which is run at build time and translates them into embedded resources. Right-click your original VS-created resx file and click Properties. You should see Build Tool or something similar. Also note the resource type (Embedded, etc.). Make sure that you match these settings for your manually added files.
Once this is set up, you will need to use the CurrentUICulture property to tell .NET to pick up the appropriate resources. You can choose to change the culture/language at install-time or run-time. Here is a comprehensive tutorial which describes the various options available to you:
WPF Localization Using RESX Files
That said, as a best practice, translated Resx files are generally deployed as satellite assemblies. The main application DLL/EXE contains only the language neutral resources file. Other resource files are compiled into separate assemblies and deployed side-by-side with specific naming conventions. This allows you to dynamically add translations, localizations, etc. even after the application is deployed. Here's an introduction: Packaging and Deploying Resources in Desktop Apps

Text into a html file thats placed in a resx file

My question is this I have a console app that sends out emails and i have a html email template setup thats placed into a resx file, now i want to be able to update the html or add text to the html file at runtime how can i do this???
As the resx file is compiled into a dll or exe it is not easily possible to change its contents. You could offer a configuration gui or use some xml configuration files like the app.xml.
If you want to offer updates to the template file like localization you could create multiple resx files File.resx for default language, File.en.resx for english, File.de.resx,...
Visual Studio then creates multiple dll files en\Resources.dll, de\Resources.dll. Whenever a user starts your application it will autmatically search the installation path for these files und use the one best suited for the language selected in the user's operating system.
I think you would have a much easier time if you moved the template from a direct resource string into a project-level file that is stored as Content or an Embedded Resource.

.NET Projects: Where do I put .resx files?

Where do I put .resx files? Sometimes I see these files under Properties folder. Is there any design guideline about it?
Thank you!
Depends on what you are doing.
For example a web Application they go in App_GlobalResources or App_LocalResources folder.
For other projects I would create a Resource folder and put them there.
In a WinForms app, the .resx file associated ot a class (form, user-control,...) is stored side-by-side with the source code (e.g. C#) file. In addition, a global .resx file is created in the properties to let you store global stuff such as messages, pictures,...
If you right click your project in VS solution explorer you should have an option "Create folder" this will then have a list of folder you can create. App_GlobalResources and App_LocalResources is another.
For project wide strings and resources add the contents to the App_Global forlder. for form specific resources add the content to the App_Local folder instead.
Have a look here for more information

Categories

Resources