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.
Related
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.
Looking at the silverlight business application, it seems to add a number of libraries specific to Input Forms and the like.
Am I right in saying that creating Complex classes results in these forms being generated automatically?
Looking at the file size of the basic Silverlight business application XAP file, it's around 412Kb. Is there a way to reduce that size?
Regards,
Jacques
You can re-zip the XAP file, but that is only a 20% saving generally at best.
Using the PRISM pattern and a modular approach, we managed to get our initial page load down to around 150Kb (the entire app is over 4Mb). The rest of the modules continue to stream down in the background so we get something on-screen very fast.
If you intend to build a large application, PRISM and/or MEF is the way to go. It has an additional learning curve but it results in very modular apps (great for team development/maintenance).
Here are some tips and tricks to try to make your XAP smaller. Like removing references you don't really use and re-zipping the XAP. Hope it helps!
http://forums.silverlight.net/t/21548.aspx
Is it possible to share viewmodels across platforms - WPF/Silverlight? I started down the path of putting my VMs in a separate assembly and soon came to ICommand - which then led me to ask this question? Is this possible, and if so is it good to do so? We have a possibility in the future of having a client application for WPF and Silverlight, so I would like to not have to duplicate VMs for both.
You can potentially do this using the Portable Library Tools CTP. This allows you to target the full framework as well as Silverlight in a single library project.
Otherwise, it is possible, sort of. You still need two separate projects (for practical purposes), but can typically use a single source file. Have each project using the same source files keeps the reuse in place - but does require manual synchronization of the files. You can also add platform-specific functionality easily in this case via partial classes or defines, which does help to keep some of the workarounds for missing Silverlight functionality easy to maintain.
[Almost] whatever is possible in Silverlight, is possible in WPF, too. So if you have a VM working in Silverlight, it will [mostly] work with WPF.
From the other point of view, WPF offers richer possibilities, so you might want to use them in your WPF part of code. You can use the usual #ifdef Silverlight-like tricks.
Also, this question might be useful.
I am planning to make a web application, using silverlight for frontend. requirement is: this frontend will be just an empty shell, and it must be language independent. it will get everything it needs to display and use from server, therefore making it language independent.
i tried to find tutorials, but there is nothing.
as far as i understand, silverlight uses xaml for all its data, so just generating it with whatever language i want shouldn't be a problem. but i don't have any silverlight experience or knowledge, so i'm not sure what is the best way to do this. for example, i don't know how will new content be generated, and what kind of structure silverlight requires.
can anyone give me some starting points?
Your requirements are rather demanding. If i can summarise:
silverlight will be the front end (or container)
you don't know what it will be showing
the content may be dynamically generated
everything, including the visual content, will be retrieved from the server
If i have misunderstood then by all means correct me or adjust your question.
Those requirements are not trivial, especially when you have no prior experience in Silverlight. Fetching data from the server is a normal behaviour in Silverlight, but fetching any generated UI content will be a slow and inefficient use of the technology platform. Silverlight is delivered via the browser, and runs on the client. If you are going to have generated UI, then you may want to consider using straight HTML instead (you can generate the contents using ASP.Net or a scripting language such as PHP). Alternatively, you can generate your required UI views from within the Silverlight app itself by either swapping in and out the appropriate pre-built piece of UI (or controls), programmatically adding new controls into the visual tree, or by loading XAML using the XamlReader class.
This answer may or may not help you much, but like i said before - put some more specific details into your question and you will get more specific answers (either add comments under your question, or post a new more specific question if you cannot edit your current one).
Edit: i have just come across this blog article from Jeff Prosise explaining the use of the INavigationContentLoader interface in Silverlight 4 to dynamically load pages from either remotely or locally. It is a detailed write-up, with a lot of code samples, it may be of use to you.
I would suggest you start at http://Silverlight.net
The "Learn" section has lots of videos that can get you started. http://www.silverlight.net/learn/
Having just found out that you can use Ruby or Python inside a SilverLight application..
link here
..I wonder if its possible to bypass some of the SilverLight limitations with use of these languages instead of C#.
I know that the Ruby Engine inside the SilverLight application is trimmed down, just as the .NET CLR is, so I would like to know that even without all the functionality of a full Ruby or Python Engine:
Can I still be able to do something
with the use of these dynamic
languages that I wouldn't be able to do
in C# SilverLight?
.
If we need to download something built
by the community to extend the cut
down Ruby implementation (to support
Interop calls for instance?), what's
the impact on deployment?
.
If not, if you cannot do anything
you wouldn't be able to with c#, with these engines, besides
the typical benefit of a dynamic
language, and not really circumventing
some of the restrictions of the
SilverLight's CLR, why would one
choose to use Ruby in a SilverLight
application?
One of my interest points is use of sockets, socket usage in SilverLight is improving in each version, but it can still be troublesome because of the xml authorization file required on the server side..would ruby be able to make this unnecessary?
Thanks,
Ric
I suspect you won't be able to work around that. Keep in mind that it's not the language imposing the limitations here but the runtime. TO be precise, it's Silverlight itself. Since both C# and Ruby are compiled to CIL in this case you're left with more or less the exact same capabilities (except some differences in the typing system).
I'm not sure what you're getting at. Regardless of language you are still running inside the same "sandbox", security model and limited with the same cutdown libraries in Silverlight. You can extend the bits that you feel are "limited", assuming your code doesn't violate the security model, with any language.
You might be able to do things differently using another language, but the same basic constraints still apply.
You need to make sure the files are included in the xap or use the silverlight 3 slvx system to stream the assemblies defined in C# or VB etc.
The ruby language should be a complete ruby implementation so you can use all the language features ruby offers like metaprogramming etc.
All source files need to be included in the xap to work.
If you're using ruby then you get gestalt too and you can include ruby source files in the same way as you include javascript files in an html page today.
One of the best scenario for the usage of dynamic languages in .NET is to let the users extend the application with their own code, so that's the main reason I use IronPython in my Silverlight application. It's so nice to have that available in the limited .NET runtime of Silverlight. It's really easy to integrate (although I had a hard time making C# extension methods visible to Python) and it can be very powerful for the users.