Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net localization: coexistence of old-school .resx and new-school wpf .baml

I know all about the old-school way: use a resource file with the .resx extension, provide a NeutralResourcesLanguage attribute, the neutral resource is compiled in the assembly, and you can compile satellite assemblies from other localized resources (blahblah.de-DE.resx). Visual Studio also generates a strongly typed .cs from the resources so it's easy to use from code (Properties.Resources.Default.WhateverStringResource).

I just learned the new WPF way: put the resources inside the .xaml file, use the UICulture tag in the .csproj to put the .baml resource in a satellite assembly, or not, and put the .baml resource in the main assembly. These resources are easy to use inside the .xaml but AFAIK, not from code, since no .cs file is auto-generated.

So maybe I'm very mistaken, but I have several questions. "Seriously, what the hell now?" being the first. To make my ranting valid, just create a new WPF application in Visual Studio 2010: you'll get .xaml files and it will also put an empty Properties\Resources.resx there. There you have it, so they do need to coexist.

First of all, do I need both new and old-school anyway? I can't see an easy way to use strongly typed .xaml resources from the code-behind. Why not? Maybe there's a way to generate them into .cs files and I just don't know about it.

Now the bigger problem is that I can't use .resx resources from .xaml either. WHY?! Visual Studio 2010's designer sure doesn't see them, but again, it may be my bad.

MSDN suggests to use the UICulture tag. It does put the .baml resource in a satellite assembly, so that the assembly doesn't even contain the neutral one. But it doesn't work for an old-school neutral resource, AFAIK, a non-localized .resx needs to go into the main assembly. So if I want to use new and old-school in the same project, I can't use the UICulture tag, I need all neutral resources in the main assembly. Am I the only one who's bothered by this?

So the questions:

  • can I use resources from .xaml in code in a strongly named way as with .resx files?
  • is there a way to use .resx resources in .xaml that doesn't break with SilverLight?
  • is it just me or is .baml localization a lot more complex than .resx localization? (dll parse, recompile, csv editing, vs. only editing a .resx file)
  • can I compile a neutral .resx into a satellite assembly just like with UICulture in wpf?
like image 513
fejesjoco Avatar asked Apr 02 '11 14:04

fejesjoco


1 Answers

You can actually work with RESX files rather easily in WPF, and for localization it's the way to go.

Look at: http://www.codeproject.com/KB/WPF/WPF_Resx_Localization.aspx and Get values from *.resx files in XAML

like image 171
Elad Katz Avatar answered Nov 17 '22 22:11

Elad Katz