How can I localize a resource in WPF? - wpf

I am learning about how to localize a project and using a book as a tutorial. I've added the UICulture to the .csproj and assembly files:
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
But now the book says to update the elements with the UID and I don't know where to do it.
I have to invoke the msbuild (not sure form where) and need to use
msbuild/t:updateuid ProjectName.csproj.
How do I do this?

If I may suggest an alternative approach. I never liked the "default" Microsoft approach to localization in WPF, so way back in 2008 I started looking for alternatives. I eventually settled on a solution described in an article named "Simple WPF Localization" on CodeProject. It's a XAML markup extension and it also allows you to change languages on the fly, etc. Very simple to use.
The author now has a more capable, "advanced" version: Advanced WPF Localization that allows you to localize images, brushes, margins, etc. (it's all at the top of the article).
There are a few other such "libraries" available (some are on CodeProject as well), but I've been using this one for 3.5 years with no issues whatsoever. Might be worth looking into if the approach fits what you're doing.

Related

Is there a tool for helping the extraction of localizable text from Xaml?

I am tasked with the localization of a Windows Phone 7 application. The first step is to replace the actual visible text with an ID and put the ID and the text in a resource file.
This is a very tedious work and I was wondering if there are tools for this to automate?
I am thinking along the lines of the gettext package and .po files used in the linux world.
Here is a codeplex project that may help you some. http://xlocalization.codeplex.com/. To use this method, each control that is to be localized must have the name property assigned.
I tried it with my existing project, and got results that were mixed, but in the long run, I decided to do it by hand. I don't remember specifically what the problems were that I had, but if you want to try it on a copy of your project, it won't take much time. If it works for you (and if your controls to be localized all have names), it could save you time.
Also, I don't know how familiar you are with localizing, but I wrote a blog on the subject that takes you from start to finish. It's at http://www.hopnet.mobi, click Blogs.
Hope this helps.
I know this will get a lot of traditional answers, but I would also like to put forward something completely original we tried (and succeeded) doing ourselves for more efficient localisation of Silverlight using Attached Properties instead of binding:
Localisation of Silverlight projects after completion
To pre-populate the database we wrote a XML parser to find our markers in all our project's XAML files (XAML is just a subset of XML after all). We could not find any existing tools to do what you suggested, but our requirements were simplified by our new method of localisation (no resource files and no horrid bindings).
(yes, this is almost the same answer as a previous one of mine today, but it seems to fit again).
Also for future reference keep an eye out for this tool: http://www.neovelop.com/ This tool will go in private beta soon and looks very promising. Judging from their preview movie this will do exactly what you asked for.

WPF - XAML - C# - C++ - So Confused

I hope someone can assist, I am a beginner in computer programming and had purchased a book (Visual Basic - Step by Step), I was making good progress until I read an article on the internet about Windows Presentation Foundation (WPF) - apparently this the future.
I read up on Xaml and I find the syntax extremely difficult to understand, for instance I have been coding using the following format:
texbox1.text = "Hello World!"
However the guides I read on Xaml show that the coding in the .cs file are as follows:
<Grid>
<TextBlock Text="Hello World!" />
</Grid>
I am confused on which 'language' I should be learning!
I hope someone can shed some light into this.
Many thanks
There are many aspects to programming, and it can certainly become overwhelming for a beginner quickly. For starters, let's clear up a few terms:
VB (Visual Basic), C#, and C++ (mentioned in your title) are all high-level programming languages. Assuming that when you say Visual Basic you are referring to VB.NET (which is likely, unless the book you're reading is a decade old...), VB and C# are both languages that can be used with Microsoft's .NET Framework, a set of libraries and tools for building (primarily Windows) applications.
(C++, meanwhile, is a slightly lower-level language not directly connected to .NET. It requires an understanding of certain concepts that the .NET languages hide from you, such as pointers and memory management.)
Now, the programming languages mentioned above are not tied to a specific presentation technology - there are many ways to create interactive programs that display output to users and accept input regardless of the the language you use. The .NET languages, however, are typically used alongside a couple of powerful tools that the .NET Framework provides for creating graphical applications:
Among the simplest user interface methods, you can create a console program which takes typed input and produces text output on the system console. Nothing fancy here.
Windows Forms - originally provided with the pre-.NET versions of Visual Basic, this is a venerable API to the native Windows user interface. It is driven primarily by Form objects that contain Controls and are driven by user Events. Here is a primer.
WPF (Windows Presentation Foundation) is a newer technology than Windows Forms. It is used alongside an XML-like file format, which you've shown above, called XAML (eXtensible Application Markup Language) that lets you build user interfaces by quickly declaring a hierarchy of visual objects. The learning curve for building WPF applications is slightly higher (in my opinion) than that for Windows Forms, but it is a more versatile technology that better supports several good design patterns (that's hand-wavy, I know, but take my word for it for now).
So, to clear up a few points of confusion:
The programming language you use and the framework for building graphical user interfaces are two separate choices.
Both VB.NET and C# can be used to write the underlying logic for Windows Forms or WPF applications
WPF, the graphical subsystem, and XAML, the declarative markup language, are not the same thing, but they are used hand-in-hand with each other.
When creating WPF controls, you will have a file containing XAML (suffixed with .xaml) that is attached to a "code-behind" file containing C# (with a .cs extension) or VB (with a .vb extension), depending on which language you choose.
In general, a .NET programmer (which is an easy example for me to give, as I happen to be one) will use either VB or C# depending on what s/he is most comfortable with (or what's mandated by their team!) From a beginner's perspective especially, the two have different syntaxes but are functionally equivalent. I personally prefer C# for its similarity to the languages (Java and C) in which I learned to program.
Now, whatever the language, a programmer then selects the appropriate user interface technology for the project at hand. For graphical applications running on Windows, I believe that WPF is the tech to beat (especially because it's very similar to Silverlight, which can be used to target the web and Windows Phone).
I hope that at least begins the process of clearing up what is a very complex but navigable topic! I've already linked to it once above, but check out Microsoft's Beginner Developer Center as another resource to get you on your feet. Good luck!
The way you were coding and the xaml markup code does the same thing. The primary reason of XAML existence is to let the UI designers work on the UI using XAML and later programmers would tie up the business functionality using C# or XAML. XAML is primarily used in WPF but languages like C#, VB can be used to do a lot more things. Regarding what languages to learn, it all depends on your interest areas and your job.
djacobson's answer hits 90% of what I was about to write... so this is just a little supplement to that answer giving my personal advice.
If you're just starting out learning programming... it doesn't really matter too much where you start with which 'language' you choose. It looks like you've started out with learning Visual Basic. I write mostly in C#... but for the most part... they can do the same things, and are both good options to start learning about programming.
For your first couple of projects, simply create console applications that don't really have a user interface besides the command prompt (console).
As you move forward and want to start creating applications with a GUI (Graphical User Interface), then you can look into XAML (WPF if you're creating a desktop app, Silverlight if it's a web based app).
You'll still write your business logic code using Visual Basic or C#, the XAML is simply a way to define how your GUI will look and behave using the familiarity of XML rather than an older technology such as Windows Forms.
I'll be the first to say that I absolutely love WPF and XAML, but I truly feel that you're best off learning the basics of the language of your choice first, then work your way into the UI technologies later.
Since from last 2 years I am working on WPF and even I was like blank when it came to WPF. I would prefer C# over C++ and still you can find solutions for every language. But it depends on you what you are comfortable.

Recommendation for skinning library for Windows forms

I'm looking for a skinning library for Windows Forms.
I see this question asked a few times on StackOverflow, but always people looking for free/open source solutions. I don't mind paying for a skinning library. Googling around I see DevExpress's controls support some kind of skinning, and there's also skincrafter.com (though I'm unclear if that supports Windows Forms). Anyone familiar with either of these products or can recommend something better?
I'd like "full" skinning support, but I might be happy with something simple like Firefox Personas/Chrome Themes.
I'm used to using the DotNetBar controls but they don't seem to support skinning, other than basic color themes.
I use DevExpress WinForms and I'm very happy with them.
However, developing custom controls that look good in all of their included skins can be quite challenging.

Recommendations on a WPF Docking Library

We are implementing an application that needs dockable windows, similar to Visual Studio 2005/2008, but with multiple "docking sites", unlike VS's single one. Does anyone have a recommendation on a good library for this - either OSS or commercial? I am aware that Infragistics has one, as well as Divelement's SandDock and WPF-Dock from DevComponents, as well as ActiPro's Docking & MDI product. There is also one on CodeProject. Has anyone used any of these libraries? Was the experience good or bad? If you have experience with one of them, does it support multiple "docking sites"?
The one from Codeproject is the AvalonDock - we use it for more then half a year now, but we're far from release yet so we have the flexibility. Before ending up with AvalonDock we tried Infragistix, ActiPro, SandDock and may be some others.
Even though AvalonDock is not 100% bug free (well what is?) there are no major ones, it is very stable, fast and has all the functionality. It does support multiple docking sites.
Its an open source project and is in active development, so bugs are beeing found and fixed. Good experience so far.
I've been using the ActiPro library for several months and it's done me well. It does support multiple docking sites. The support is outstanding and you get some other controls (date picker, etc) that are missing from WPF. To me, for $150 it's money well spent. It worked out of the box, no fuss.
We used to use Divelements for WinForm controls but we think Actipro has better support, so we switched for WPF.
Just my two cents.
Don't forget AvalonDock on GitHub (part of WPF Toolkit). I've seen it mentioned in other places.
Initially I was going to use the ActiPro library (mostly because I am already using their ribbon), but I might give AvalonDock a chance since it is open source.
Anybody have any feedback/comments on AvalonDock?
I use DotNetBar, because it has ribbon/dock and more controls, and it's inexpensive. It's great.
http://www.devcomponents.com/dotnetbar-wpf/
SandDock is alright. We used it for a POC phase of a project. I found some pretty bad bugs in their layout saving mechanism. It generated XML, but then couldn't load this XML back; it threw an exception! I actually read through all the generated XML and had to write code to modify the XML slightly after each time it was generated. It did not seem like it was a well thought out design; I was hoping for common WPF base types like
Infragistics is a bit better but buggy. In fact, if you try running it on a machine that only has .Net 3.0 and no .Net 3.5, it doesn't work correctly. Have an outstanding dev issue with Infragistics and I don't know if they've made any progress on a fix for this. I've also had it crash a few times when floating a window and dragging it around (suspect this has to do with the .Net 3.0/3.5 issue above). I've found styling this control to be pretty un-intuitive.
I tried all the libraries listed here and they're all buggy to some extent. Although they are pricy I would recommend Telerik and Infragistics. Nevron merits a mention because their library is the best I've seen but it's for WinForms.
1 year later ...
AvalonDock is now stable and robust.
There's also an "AvalonDock wrapper" that simplifies working with it without reducing its possibilities.
See http://sofawpf.codeplex.com/
Here is another one:
http://www.essentialobjects.com/Products/EOWpf/DockView.aspx
This one has a number of built-in skins that you can switch dynamically. It also has many individual controls (such as a "Splitter" control) that you can use independently.

What is the best way to localize a WPF application, sans LocBAML?

There seems to be no good way to localize a WPF application. MSDN seems to think that littering my XAML with x:Uid's, generating CSV files, and then generating new assemblies (using their sample code!) is the answer. Worse, this process doesn't address how to localize images, binary blobs (say, PDF files), or strings that are embedded in code.
So, how might you localize an application that:
Contains several assemblies
Contains images and other binary blobs (eg: PDF docs) that need to be localized
Has string data that isn't in XAML (eg: MessageBox.Show("Hello World");)
You should have a look at the article and code available here. It describes different ways of localizing WPF apps, using LocBaml, custom markup extensions, or attached properties. IMHO the best solution is to use the markup extensions and Resx resources. The code contains a localization framework for doing that.
Not an expert here, but "littering" your xaml with x:Uids is not worse than "littering" your Windows Forms code with all the string table nonsense you have to do for localizing them.
As far as I understand, WPF apps still support "all the Framework CLR resources including string tables, images, and so forth." which means you can have localized resources.
Of course, it would be much simpler if you created a markup extension that handled much of this nonsense for you. You can find an example of someone doing this here. And there was another, similar solution at http://blog.taggersoft.com/2008/07/wpf-application-localization-pattern_29.html, but that link no longer works.
You can use the old "ResX" files which support all of your mentioned scenarios. How this can be accomplished in a WPF application is explained here:
WPF Application Framework (WAF) => See Localization Sample
try the Gnu GetText utilities, and supporting applications. It does generate C# classes based around ResourceManager and ResourceSets, and of course you can reuse the translations for other parts of your application - eg web pages, native code, or iphone etc.

Resources