Lucky me! I got a new project: the new company's website. Such sites need to have two features:
- an impressive presentation layer
- a few languages versions
There are a few catches. First, there is no easy way to do that as in asp.net (there should be!). Microsoft published an article on localizing Silverlight applications and it's no fun to read. But, we're big boys, let's add our resources files by ourselves, rename them and stuff.
Second catch is coming: the constructor in the resourse.designer.cs file is protected instead of public. Two workarounds here:
- change it yourself everytime you modify the resource
- get a tool for that: Dmytro Kryvko’s Extended Strongly Typed Resource Generator 2.3
I don't know... you might have more luck than me. If you wanna localize, start with reading "Silverlight and International Thoughts". There's a fully detailed instruction on creating a localized application in 43 steps.
As much as I like Silverlight, localization is a nightmare and that disappoints me a lot, as it's something that's been done in asp.net already - I feel like reinventing the mouse wheel here!
Sorry to hear, you had problems with this as well. I'm currently in the process of building an enterprise application with Silverlight 2 as a UI and I've cracked the localization issue a slightly different way. You can read about it here:
ReplyDeletehttp://jvdveen.blogspot.com/2009/01/adventures-while-building-silverlight_12.html
If you have any questions, please let me know. I'm always happy to help.
Greets,
Jonathan van de Veen
I found that if use loc namespace that inherits from your parent namespace, VS can sometimes give vailadtion errors. Try a different namespace altogether from your local project in your custom tool namespace property in strings.resx
ReplyDeleteSee sample on http://wpf-e.spaces.live.com/Blog/cns!2B248D261D0E0035!407.entry
Thanks slyi, your tip helped.
ReplyDeleteBut, on my custom control that has a string "Text" property, I get a
AG_E_PARSER_BAD_PROPERTY_VALUE when I try biding it (it might be my bad).
On a textblock, however, the first binding works. But I want to be able to switch languages at runtime:
private void btnFR_Click(object sender, RoutedEventArgs e)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr");
...
And that code didn't change the textblocks text to a different language version.
To change the culture you can use that in your event handler:
ReplyDeleteSystem.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-fr");
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-fr");
Page page1 = new Page();
LayoutRoot.Children.Clear();
LayoutRoot.Children.Add(page1);
You mean regenerate my whole app? Isn't reassigning all the strings more efficient?
ReplyDeleteThe longer I dig this subject, the happier I am with my solution. ;)
to avoid AG_E_PARSER_BAD_PROPERTY_VALUE, you have to set the resx to public and manualy change the constructor from internal to public
ReplyDeleteYou're right, but I had to do it each time I modified the ressources, which was unpleasing.
ReplyDeleteThat post must be pretty outdated now that SL 3 and 4 Beta are out, but thatnks for contributing anyway.