First time here?

You are looking at the most recent posts. You may also want to check out older archives. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS or email. Thank you for visiting!

While I was at the Silverlight Atlanta Firestarter event I had a chance to meet some great people.  One of them was Sergey Barskiy.  Sergey was doing a session on deployment and while in the speaker area we were chatting about overall feedback on Silverlight.  One of the things he mentioned was what he thought was a bug in Visual Studio Tools for Silverlight.  It was around RESX files and the modifier setting (Internal, Public, etc.).  More on that later.  Sergey was using RESX files for localization.  While investigating the bug for him, I realized how many people might not know how to do some simple string localization/binding in their Silverlight applications.  It’s relatively simple and I thought I’d outline the steps.  I must admit that I’ve never had to develop a full-fledged internationalized application before, and I applaud those who have and have tackled both the obvious of the language localization challenges as well as cultural and display challenges with various technologies.

The Sample Application

For this experiement we’ll keep it simple and we’re talking about String localization.  We are going to work with a Silverlight 3 application in simple form which will have a TextBlock and a Button control which will have their respective Text and Content settings.  Here’s the English-US (en-US) version of the app:

Sample application image

If we were like most applications we’d be done…but this post will try not to be so US-centric :-).

Step 1: Adding default String resources

As a best practice for String resource localization, in your Silverlight application structure, organize your resource files accordingly.  We’re going to use the RESX file approach and let the framework do most of the work for us.  To that regard in my application I have created a folder called Resources and will be placing my RESX files there.  I’ll first add the default set of data, adding a new RESX file named Strings.resx.

When you add this you’ll notice you get a Strings.resx and a designer (cs or vb) file.  By default the Resource Designer will open and we’ll add two values: WelcomeMessage and ButtonMessage.  Our surface looks like this:

Visual Studio resource designer

Notice the Access Modifier section in the designer.  We need to set this to Public in order to use it in binding we will do later, so set it now.  We save this and step one is done.  Let’s test it out and use it.

Step 2: Binding our RESX files to our XAML

Now that we have a Strings.resx file (which is marked as Embedded Resource by default) in our Resources folder, we can use it as a resource in our XAML.  We need to do a few things to enable this.  First, we need to add an XML namespace to our XAML page.  I’ve chosen local for mine, but choose whatever.  We will have this namespace point to our Resources namespace in our application.  Mine looks something like this:

   1: xmlns:local="clr-namespace:StringLocalization.Resources"

Now I can use that assembly classes in my XAML.  I’ll add the Strings class to my UserControl’s Resources section giving it a key of LocStrings like this:

   1: <UserControl.Resources>
   2:     <local:Strings x:Key="LocStrings" />
   3: </UserControl.Resources>

And now I have a XAML resource I can bind to.  Let’s do that.

Step 3: Binding to the resx file data

My XAML has a TextBlock and a Button I want to bind to the string values.  Because I have a XAML resource this is simple and I just create a binding using the the XAML binding syntax to that resource.  here’s what my TextBlock and Button look like (relevant portions):

   1: <TextBlock Text="{Binding Source={StaticResource LocStrings}, Path=WelcomeMessage}" />
   2: <Button Content="{Binding Source={StaticResource LocStrings}, Path=ButtonMessage}" />

Notice that I’m using a Path that points to the String name in the RESX file.  Let’s run the application now and we should see what we’re looking for right?

WRONG.  Here’s the bug that Sergey was talking about.  It turns out that there does seem to be a bug in Visual Studio with regard to the modifier, and more specifically the PublicResXFileCodeGenerator custom tool that is used to generate the code.  It turns everything in the resource to public except the constructor.  Not having the constructor public (it is still marked internal) is what is causing our problem. 

NOTE: This is not a bug in Silverlight or in the Silverlight tools, but more widely in Visual Studio.  The same thing reproduces on any VS project type.  It’s been noted and is being tracked to address.  See this topic:

What we have to do as a workaround is to go into the Strings.designer.cs file manually and change the constructor from internal to public.  I will note that each time you open up the designer for that main resource file that it may get reset to internal, so remember that. 

After changing to public you can run the application and get the desired output.  There is actually a way to still use the resources and keep the constructor internal, but it involves using another class you have to create and instantiate…more on that later.

Step 4: Adding additional localized resources

Now that we have our base working, we simply need to provide the localized resources for our application.  I’m choosing to localize in Spanish (es-es), French (fr-FR), German (de-DE) and Japanese (ja-JP). 

I solicited some help on Twitter to get some “human” translation to double-check my translated text with Windows Live Translator.  To my surprise, Windows Live Translator actually did a great job.  I think with short sentences it is fine, but longer conversational text may lose context.

Thanks to: Ken Azuma, Othmane Rahmouni, Talya, Misael Ntirushwa, Hannes Preishuber, and others who jumped in to offer help for my little sample.

To do this we simply add more resource files into our project following a specific naming scheme.  Since we have Strings.resx when we add additional languages we’ll add them as Strings.<locale>.resx.  So adding German would be Strings.de-DE.resx and so forth.  It really is best to use the xx-xx locale settings versus just the two character (i.e., de) ones.  Note when you add these files to the project that your modifier section in the resource designer should say No Code Generation automatically.  If it doesn’t, choose that option.  We only need the code for our default language choice.  When I’m done my structure looks like this:

Project structure with localized string resx files

Obviously the contents of the file contains the localized string information.  Note that the string parameter names still have to match.  So even though I’m localizing the contents of WelcomeMessage, in the German resource the parameter is WelcomeMessage and not Wilkommen or something like that.

UPDATE: Forgot one critical step – oops.  You have to manually edit your **proj (csproj/vbproj) file for your Silverlight project to add the locales in the SupportedCultures node of the proj file.  This is a manual step (and sucks), but don’t forget it or nothing will work as you suspect.

Step 5: Testing it out.

Because we used our declarative binding in Steps 2-3, we don’t have to change our code.  We should test it out to make sure it works though.  There are two good ways I have found to test this out.  First, the Silverlight plugin supports forcing a UICulture and we could do it that way.  Let’s test German.  In our plugin instantiation on our hosting page we’ll add these two parameters to the <object> tag (relevant portions):

   1: <object ...>
   2:     ...
   3:     <param name="culture" value="de-de" />
   4:     <param name="uiculture" value="de-de" />
   5:     ...
   6: </object>

That tells the plugin to load with those cultures set.  You can change them without recompiling your application and the language will change.

A second option would be to actually change the display language of your Windows environment.  For some this may be a little frightening as your screen suddenly may change to a language you don’t understand natively.  I recommend if you go this route to keep a translation dictionary handy find your way back (you have to logoff/logon to change a display language)!

Either way when you run the application using either of these methods you should get what you expect.  Here’s my German output:

German localized sample application

Obviously it is easier to test using the <param> approach (changing display languages in Windows requires a logoff), but ultimately I recommend doing actual OS display language for verification.  If a user is on a language culture that you have not localized, it will use the default values provided in our initial Strings.resx file.

Another option for testing is that you can actually change the culture and UICulture values using the Thread namespace APIs in Silverlight.  Keep in mind though changing these values on the CurrentThread does *not* reload the default resource, so you’d have to do some additional code to get the resource to load using that new culture setting.

Caveats and cultural differences

One thing to note is that while your application may now have an easy ability to display localized string data with simple bindings, it may not always be appropriate.  Take for instance Japanese language translation (I’ll assume it is roughly translated correctly, but for the sake of this discussion this serves a purpose) of “Click here” for the button.  In English it fits fine in our lovely world of fixed width button sizes.  But look at the Japanese translation of the text:


And here’s how it looks in the button:

Japanese localized sample output

Notice that we don’t see all of the characters?!  These are things that you’ll have to understand when things seem simple enough.  Sometimes translated strings will be longer/shorter than your intended design.  Designing around a localized approach will have to consider these in advance.  In fact, for some languages you may have an alternate placement of controls even to accommodate the culture.

As I noted that I used machine translation for my sample here, but I do want to stress that I think respecting cultural differences is important in customer facing applications.  Using something like Windows Live Translator seems simple enough and might work in simple instances, but I would recommend hiring true localization resources/people to help you differentiate the subtle differences in languages.

Public modifier workaround and dynamically setting the culture

As I mentioned above there is a workaround to the internal/public modifier bug.  It is easy enough to change of course, but you may want to look at this approach as well…and in some implementations this may fit within your model better.  The idea is to provide your own class implementation access to the Strings resource.  Here’s an example of what my custom class implementation might look like:

   1: public class CustomResources : INotifyPropertyChanged
   2: {
   3:     private static StringLocalization.Resources.Strings _strings = new StringLocalization.Resources.Strings();
   4:     public StringLocalization.Resources.Strings LocalizedStrings
   5:     {
   6:         get { return _strings; }
   7:         set { OnPropertyChanged("LocalizedStrings"); }
   8:     }
  10:     #region INotifyPropertyChanged Members
  12:     public event PropertyChangedEventHandler PropertyChanged;
  14:     private void OnPropertyChanged(string propertyName)
  15:     {
  16:         if (PropertyChanged != null)
  17:         {
  18:             PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  19:         }
  20:     }
  21:     #endregion
  22: }

And then my resource section would look like this:

   1: <UserControl.Resources>
   2:     <localCustom:CustomResources x:Key="CustomLocStrings" />
   3: </UserControl.Resources>

And my binding would look like:

   1: <TextBlock Text="{Binding Source={StaticResource CustomLocStrings}, Path=LocalizedStrings.WelcomeMessage}" />
   2: <Button Content="{Binding Source={StaticResource CustomLocStrings}, Path=LocalizedStrings.ButtonMessage}" />

Now that I have this in place like this I get around the internal modifier issue because I’m actually binding to an instance of my own class (which has a static instance to the Strings resource class).  Using this method I could dynamically change the culture on the fly as well by resetting the culture settings in the thread and resetting the resource.

   1: ComboBoxItem item = ChangeLog.SelectedItem as ComboBoxItem;
   2: Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(item.Content.ToString());
   3: Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(item.Content.ToString());
   4: ((CustomResources)this.Resources["CustomLocStrings"]).LocalizedStrings = new StringLocalization.Resources.Strings();

A bit of a workaround for most scenarios I think.  I think probably remembering to change the modifier may work best for most cases, but this custom instance class might actually fit better into some model implementations.


Hopefully you can see that for simple string resources the technical implementation is fairly simple.  The real challenge is to you, the developer, to ensure the cultural integrity of the message is being displayed appropriately.  Localization is not an overall easy task and I’m simplifying it to simple strings here.  As I stated above, I applaud those who have successfully implemented fully localized applications.  It can be as simple as a button label or as complex as alternate screen layouts for different cultures!

You can download the code for this post here: StringLocalization.zip

Hope this helps!

This work is licensed under a Creative Commons Attribution By license.

8/26/2009 11:44 AM | # re: Silverlight and localizing string data
Thank you for the post. This is a timely for post for me. I follow Guy Smith-Ferrier who I've found to be an invaluable resource in all things localization in .NET. He's got a post that covers this as well as 2 custom Resx generators that solve the internal ctor issue.

One problem I have with the bind to the strongly typed resx is I don't see a way in Blend to modify any of the localized Content when it's been pulled into the resx. Am I missing something?

To resolve this I thought I'd bind to a StaticResource in a resource dictionary. This allows editing the content in Blend and keeps the strings in a file that can be localized. Because we don't have DynamicResource support, it does mean you can't switch locales on the fly. I believe I would need the localizable content for all pages to be in one dictionary and merged when the app loads. These are just ideas I'm kicking around. I look forward to more comments on this.

Ah for the days of Localizable=True :)
8/26/2009 12:47 PM | # re: Silverlight and localizing string data
Good article! I wish I had had this last year when I was trying to figure all this out. I recently wrote up a little of what I had learned, including a way to change languages on the fly here: esmithy.net/2009/07/08/silverlight-localization/.

8/26/2009 12:47 PM | # re: Silverlight and localizing string data
Thanks Tim.
Perhaps can you just add a short code sample about the critical step (SupportedRuntime node). I looket at some of my Silverlight projects, I even created a fresh new one, and I can't find any SupportedRuntime node...
thanks in advance.
8/26/2009 1:07 PM | # re: Silverlight and localizing string data
My approach is exactly the same blogged by Eric: I expose resources as a property of my Viewmodel, this not only allows me to switch languages on the fly without reloading view contents but it also give me a better Blend experience. Unfortunately being members of Resources class exposed as static they're not listed on Blend's DataBinding dialog but wiring is a lot easier than editing xaml manually.
8/26/2009 1:17 PM | # re: Silverlight and localizing string data
Olivier - oops, my brain wasn't working. It is SupportedCultures, not SupportedRuntime (too used to typing that). I've corrected the above.
8/26/2009 2:29 PM | # re: Silverlight and localizing string data
Thanks Tim.
Great post. I see why you needed the translations.

8/26/2009 7:23 PM | # re: Silverlight and localizing string data
8/26/2009 9:26 PM | # re: Silverlight and localizing string data
Hi, Tim

Your StringLocalization application might not be able to display Japanese characters correctly for following reason.

The first important point is that a default value of FrameworkEntity.Language is always "en-US" without any relation to UICulture or Culture.

In this situation, the Portable UI Font might be use Chinese font for Unicode CJK characters because it is uncertain whether current language is Japanese or Chinese or Korean.

If you want to reproduce this issue, please add U+9AA8 (骨) or U+76F4 (直) or U+4E0E(与) to Strings.ja-jp.resx and check the result with Mac OS X.

These characters will be displayed by not Hiragino Kaku Gothic Pro(Japanese font) but STHeiti (Chinese Font)

I think that your application should select the appropriate language name string and set it to Language property of TextBlock.
8/28/2009 12:29 AM | # re: Silverlight and localizing string data
Thanks Tim for this sharing this with us.
You know Silverlight now is half supported localization because it does not support bidirectional yet. Therefore languages which are right to left such as Persian, Hebrew and Arabic can not be used in silverlight normally. However we hoped that Microsoft would add Bidi support for Silverlight 3.0, we were disappointed. Does Microsoft has any plan to add Bidi support to Silverlight?
8/28/2009 3:16 AM | # re: Silverlight and localizing string data
Hi Tim,

Thanks for this post. This article came a bit too late for us. We had to figure it out ourselves but didn't find the time to make a blogpost on it.
Because of the bugs in Visual Studio it makes implementing this a real pain.
If you have 5 resx files and have to add or change a string, you have to go into the designer code each time. This issue already existed and was reported a while ago so I hope it'll be addressed in the first available Service Pack.
And changing the project file from notepad isn't my idea of a fairly simple implementation.

Although I really really love Silverlight and we've just created an awesome LOB application, which I will hopefully share in a while, I think because of the way developers need to workaround the bugs in VS2008 and the lack of documentation on this subject makes it hard to figure out. So fixing the VS2008 bugs and creating some more documentation on the subject will be more than welcome.

Kind regards,

Rob Houweling.
8/28/2009 6:55 AM | # re: Silverlight and localizing string data
Ali - yes we're looking at bidi support

Rob - I agree, can't figure out why this bug has been there for a while in the custom tool. probably not fixed until VS10.
8/30/2009 3:06 AM | # re: Silverlight and localizing string data
Rob: People get around this by running a pre build command in their project, to sync the resx http://www.screwturn.eu/Default.aspx?Page=ResxSync but your correct, it should be on by default in VS.
9/3/2009 9:03 AM | # re: Silverlight and localizing string data
Thanks for the article Tim.

I tried this with a simple example and it worked out great but when I tried it with some additional editing in the Textblock, ran into a problem which I've narrowed down to the <Run />, e.g.

<TextBlock HorizontalAlignment="Left"
<Run FontWeight="Normal"
Text="{Binding Path=Resources.Text1, Source={StaticResource LocalizedStrings }}" />
<Run FontWeight="Bold"
Text="{Binding Path=Resources.Text2, Source={StaticResource LocalizedStrings }}" />
<Run FontWeight="Normal"
Text="{Binding Path=Resources.Text3, Source={StaticResource LocalizedStrings }}" />

There seems to be a problem parsing the XML, the stack trace shows:
System.Windows.Markup.XamlParseException occurred
Message="AG_E_RUNTIME_MANAGED_UNKNOWN_ERROR [Line: 15 Position: 23]"
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at SilverlightLoclTest.MainPage.InitializeComponent()
at SilverlightLoclTest.MainPage..ctor()

Remove the <Run /> and its fine.

Trying to figure this out at the moment
9/3/2009 9:20 AM | # re: Silverlight and localizing string data
I may have found the answer to the above on MSDN, it seems Rich Text needs some additional work: msdn.microsoft.com/.../dd894487%28VS.95%29.aspx
9/4/2009 11:36 AM | # re: Silverlight and localizing string data
We have been localizing our app in the exact way you have mentioned. One of the issues we ran into for changing cultures in real-time is not the actual Textblock themselves (you're handling it with INotifyPropertyChanged). The problem lies in the various controls like DatePicker that are also localized i.e. in Spanish dates are dd/mm/yyyy. We have not yet figured a way to change these controls on the fly. We had to dispose of every control and re-instantiate them with the new culture.
Do you know of a way that we can change the culture and have it applied across all types of controls without reinstantiating them? From a LOB point of view, closing every control when a user changes the culture is not visually appealing.
9/6/2009 8:31 AM | # re: Silverlight and localizing string data
Thanks Tim
Is there an issue to use database table for localisation instead of resource file ?
9/9/2009 11:55 AM | # re: Silverlight and localizing string data
Great post! I've created a small Silverlight app to test localization. I'm able to successfully display Russian, Greek, French etc. But when I try to display Japanese (using either ja, or ja-JP) I get this error:

An unhandled exception ('Unhandled Error in Silverlight Application Culture name 'ja-JP' is not supported. Parameter name: name at System.Globalization.CultureInfo..ctor(String name, Boolean userUserOverride) at System.Globalization.CultureInfo..ctor(String name)

Thinking that it may be just something in my code I downloaded your StringLocalization.zip and I'm getting the same error when I select 'ja-JP' in the drop down list.

What am I missing?

Thx! :)
9/9/2009 11:59 AM | # re: Silverlight and localizing string data
Leslie - I'm not sure. I don't get that error on my end. I'm curious if you look at the SupportedCultures in the csproj to make sure it is there? If anything it should default to the english version.
9/9/2009 1:00 PM | # re: Silverlight and localizing string data

Yes, "ja" is in the SupportedCultures list of the silverlight csproj file. Hmmmmm perhaps I have something amiss in my system configuration. I'll try to investigate a bit further. Thanks for your help :)
10/20/2009 1:07 PM | # re: Silverlight and localizing string data
Tim, I figured this might be the best place to put something I found using your test application that might save someone a few hours.

I followed the steps 1-5 just like you said and set my localized text in the resx file. However when I ran my application, none of the strings were resolved. Instead I just saw the number '1' instead of the intended string ie. "Status"

The problem turned out to be the actual placement of the
<Local:Strings x:Key="LocStrings"/> in the <UserControl.Resources> section.
I had a <DataTemplate... > section in the UserControl.Resources> that was referencing a local resource:

<TextBlock Text="{Binding Source={StaticResource LocStrings}, Path=Status}" FontSize="{StaticResource SmallFont}" HorizontalAlignment="Left" Foreground="{StaticResource WhiteBrush}" Margin="5,0,5,0" ></TextBlock>

The <Local:Strings x:Key="LocStrings"/> was placed below the <DataTemplate... > in my <UserControl.Resources>.
When I moved that tag before the <DataTemplate.. /> section in <UserControl.Resources>, the localized strings were resolved and showed up.
10/30/2009 12:53 PM | # re: Silverlight and localizing string data
Hi all,

I just want to add that I was able to port Tim's localisation code into WPF and it works. I was also able to setup both WPF and Silverlight to use the same shared xaml and resource files thru link files in Visual Studio. Thanks you Tim :)


11/16/2009 4:26 AM | # re: Silverlight and localizing string data
I am facing issue at step 2
When adding XML namespace at XAML page I can see using intellisense "MyProject.My.Resources in assembly MyProject" and it adds it as follows
But it gives me Clr namespace not found:
"Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace MyProject.My.Resources' that is not included in the assembly."

What am I missing?
11/24/2009 1:38 AM | # re: Silverlight and localizing string data
Hi Tim,
Hope you can help me out on this:

I have a localization problem in SL3 when creating a number of TextBlocks dynamically from cs-code.
In XAML I have created a collection which is initially empty:
<StackPanel x:Name="TextBlockCollection"/>
In cs-code I create a number of TextBlock depending on user input/selection (i= any number 0 to x in a loop iterating through the same code below depending on value of i):
dynamicTextBlock.Name = string.Format("childAgeTextBlock{0}:", i);
dynamicTextBlock.Text = string.Format("Age child no {0}:", i); //This text must be localizable.
Then these TextBlocks are added to the collection from cs-code:

The information from these x number of TextBlock are then stored in isolated storage as user specific data.
I need these strings to be localized the same way as if they were made directly in XAML.

Any idea how to solve this?
11/26/2009 3:24 PM | # re: Silverlight and localizing string data
Hey Tim, nice post but...
I downloaded your code and tried it (in Silverlight 3). No luck so far. I always get a null reference when I change the language in the combo. The null reference occurs here :

if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

Any thoughts?

11/26/2009 11:14 PM | # re: Silverlight and localizing string data
Jos - did you make sure to implement INotifyPropertyChanged? Are you seeing any compile errors?
11/27/2009 3:09 PM | # re: Silverlight and localizing string data
Hey Tim,
thank you for your quick response. I didn't change anything to your code.
In your class CustomResources.cs in the method
private void OnPropertyChanged(string propertyName) the PropertyChanged always returns null.
Further down in this method, the line :
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
alwyas returns null for Culture and ResourceCulture when I drill down on (this, ...).

So I'm actually wondering why the code works for some people and not for me...

Bits and bytes go in mysterious ways :)


PS: sorry for being a pain :)
11/27/2009 3:14 PM | # re: Silverlight and localizing string data
Oh yes, forgot this : It compiles without errors.
12/6/2009 1:44 PM | # re: Silverlight and localizing string data
Hi Tim,

Your code works great, I do however have a problem using the technique to set the error messages for the silverlight inputcontrols from codeplex.
I have a validator service for which I want to bind the errormessage:

<IC:RequiredValidator ErrorMessage="{Binding Resource1.BreedteError, Source={StaticResource CustomLocStrings}}" />

In initializeComponent I get: AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 60 Position: 64] {System.Windows.Markup.XamlParseException}

I guess it has something to do with the different namespaces:
and my app but I lack the knowledge to fix it..

Hope you can help, keep up the good work!

Mike Dole
The Netherlands
12/29/2009 7:50 AM | # re: Silverlight and localizing string data
Hi Tim,

Just wanted to say that I used your example, and it works like a charm :)
The internal constructor in the resources...it's still internal in VS2010 :(

Marc Vanhoecke
1/25/2010 6:09 AM | # re: Silverlight and localizing string data
Hi Tim,
Great post!
But I have the same problem as Jos.
I HAVE NOT CHANGED anything in your sample, and nothing happens when changing in the combo box.
In the function
private void OnPropertyChanged(string propertyName)
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
PropertyChanged always null.
Im in XP sp3, VS2008 sp1, Silverlight 3, RIA services July, Country: Hungary, language: hungarian

When I modify your code, the culture in default.html eg. to fr-fr the french appers

Can you help me?
Thanks in advance,

1/26/2010 4:35 AM | # re: Silverlight and localizing string data

jaime ba has written in Silverlight forum, ad these modifications solved the problem
You are right ... there is something wrong with that code -.-. My guess . nobody has reported the error, so Tim has no realized the mistake. you should tell him -.-

any way..

you can bind the textbox like this :
{Binding LocalizedStrings.WelcomeMessage, Source={StaticResource CustomLocStrings}}

you can also remove the reference named local (xmlns:local="clr-namespace:StringLocalization.Resources")

and remove the resource named LocString (<local:Strings x:Key="LocStrings" />)
1/26/2010 6:22 PM | # re: Silverlight and localizing string data

Nice post and thanks. I'm happy to see this is the default way in the new Templates in VS10, we still have the internal constructor and static properties, but we get the ResourceWrapper Out of the Box, making it more of a "standard" way.

My issue however is that the package can get really big when we add support for many languages. There's a way to create different packags each targetting a different Culture, however, that require us to include the full app code on each of those packages, which means that when we change languages we'll have to download all the app assemblies again. Do you know if we have something like satellite XAPs? I'm doing a POC around that topic, but I don't want to reinvent the wheel and I would like to do it in a more "standard" way.

2/9/2010 12:53 AM | # re: Silverlight and localizing string data
Thanks for your hint.
Without that, the sample source didn't work.
2/26/2010 2:16 AM | # re: Silverlight and localizing string data
The strongly typed .regx class, which is generated, is still internal in VS2010 RC.
4/13/2010 8:21 AM | # re: Silverlight and localizing string data
Tim, VS2010 is released, but bug with internal constructor on resources is still there...
4/17/2010 9:33 AM | # re: Silverlight and localizing string data
Hey Tim, thanks for the info, I was in a bad need of using this resources files :) !
4/20/2010 7:56 AM | # re: Silverlight and localizing string data
this is sure a great post, i am new to silverlight development and you've been my reference

according to this case i get an error :( it says "The tag 'Strings' does not exist in XML namespace 'clr-namespace:StringLocalization.Resources"

i did the public change in strings.cs but sill, donno why is that
4/22/2010 11:23 AM | # re: Silverlight and localizing string data
@Kpe, i am able to get it working (get the Combobox Changed Event works!) but the Text is not getting updated on the page. Keep showing everything in English, here is what my MainPage.xaml looks like:

<TextBlock Margin="10" Text="{Binding LocalizedStrings.WelcomeMessage, Source={StaticResource CustomLocStrings}}"
VerticalAlignment="Center" Width="400" Foreground="White"
TextAlignment="Center" FontSize="32" TextWrapping="Wrap" />

<Button Content="{Binding LocalizedStrings.ButtonMessage, Source={StaticResource CustomLocStrings}}" Style="{StaticResource ButtonStyle}" Height="75" Width="250" FontSize="24" Foreground="White"/>
6/2/2010 2:25 PM | # re: Silverlight and localizing string data
It's too bad this is still broken in VS2010.
6/6/2010 10:33 PM | # re: Silverlight and localizing string data
thanx tim this is really a helpful post..its working so cool. thnx a lot.
6/13/2010 1:17 PM | # Blend crashes if using custom localizer
Hi Tim,

I really love your articles. I implemented your custom localizer that allows changing language on-the-fly. But: Whenever I try to use Blend for editing the DataBinding, it crashes (by clicking on the yellow dot, click DataBinding...). Any suggestions from anyone?
7/26/2010 12:50 PM | # re: Silverlight and localizing string data
AG_E_PARSER_UNKNOWN_TYPE - seem to get this error with the downloaded sample, and a very simular error when try working though the example to implement it in my own project.

in my implementation i get the error - No matching constructor found on type 'bizdna.Resources.Strings'.

but seems to break in trhe same place on the ...ctor()
7/26/2010 1:09 PM | # re: Silverlight and localizing string data
ah never mind, - of course I found the answer straight after posting - hadnt change the codes internal constructr to public.
8/5/2010 2:32 AM | # re: Silverlight and localizing string data
Hi, I tried this localizing sample and it works fine. One problem I have: I can get access to the language strings in every usercontrol code behind like LanguageStrings.MyNameInResxFile and the translated text in the current language occurs. If I make a using to the namespace where the languagestrings.resx is placed in a class (not usercontrol) I can't access to the translated text with LanguageStrings.MyNameInResxFile. The text is always in english. What is missing or why it works in a usercontrol but not in a simple class with the correct using?
8/31/2010 7:47 AM | # re: Silverlight and localizing string data
kpe and lexius: Thanks! You both saved me a lot of time. For those who wants to use the code in VS 2010, follow the advise of kpe and lexius.
9/2/2010 11:35 PM | # re: Silverlight and localizing string data
Thank you for the article!
Althogh some variables are not quite clear to me at first, I understand them after going through your project. Some comments might help a rookie to understand it.

9/3/2010 2:24 AM | # re: Silverlight and localizing string data

I have some questions relating to the resourcemanager, could somebody shed some light on me?

I notice before the following statement is excuted, the value of LocalizedStrings already changed, why do we have to generate a new Strings object and assign it to LocalizedStrings? Can we just refresh it?

((CustomResources)this.Resources["CustomLocStrings"]).LocalizedStrings = new StringLocalization.Resources.Strings();

Also, I'm not sure if the following variable _strings referencing the same object as ((CustomResources)this.Resources["CustomLocStrings"]).LocalizedStrings does.

Thanks and Best Regards,
private static StringLocalization.Resources.Strings _strings
9/6/2010 6:09 PM | # re: Silverlight and localizing string data
never mind. I know what's going on.
9/15/2010 8:58 PM | # re: Silverlight and localizing string data
I did all steps according to your article and changed culture and language on aspx page. But I still have default language strings. When I added this code to check resources it threw an exception

CultureInfo currentUi = Thread.CurrentThread.CurrentUICulture;

ResourceManager rm = null;
rm = new ResourceManager("Sl_local", Assembly.GetExecutingAssembly());
string greeting = rm.GetString("button1", currentUi);

System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Sl_local.resources" was correctly embedded or linked into assembly "Sl_local" at compile time, or that all the satellite assemblies required are loadable and fully signed
10/27/2010 1:17 PM | # re: Silverlight and localizing string data
There is free VS addin http://wpflocalizeaddin.codeplex.com/ that helps extracting strings into resources.
11/10/2010 6:43 AM | # re: Silverlight and localizing string data
thats very interesting.

12/19/2010 10:11 AM | # re: Silverlight and localizing string data
I have a problem, when i try to modify the localization with the combo, the lenguage don't change. I'm using VS2010 and Silverlight 4.0.
1/27/2011 6:35 PM | # re: Silverlight and localizing string data
Ебанна хуйня - ничего не работает ! половина статьи недописанно ! пиздец короче ! кто знал тому нахуй ненадо кто незнал тот нихуя и не поймет!

This is fucking shit ! Nothing doesn't work! It's not complete ! Half part of code you need to quess ! fuck fuck fuck ! I HATE IT!! sample doesn't work too ! I'm using VS2010 SL4.0 Thanks and Sorry for my bad english and russian too =)
2/21/2011 2:50 AM | # re: Silverlight and localizing string data
I approved this localizing sample and it works fine. One botheration, pass4sure 70-400 I can get admission to the accent strings in every usercontrol cipher abaft like Language strings my nameInResxFile and the translated argument in the accepted accent occurs. pass4sure 70-647 If I accomplish a application to the namespace area the languagestrings is placed in a chic (not usercontrol) pass4sure 70-297 I can't admission to the translated argument with Language strings my nameInResxFile.
3/2/2011 6:13 AM | # re: Silverlight and localizing string data
Somehow the sample doesn't work for me in SL4 and VS2010... it doesn't switch the language on-the-fly... :/

any ideas?
3/2/2011 6:20 AM | # re: Silverlight and localizing string data
forgot to mention that the PropertyChangedEventHandler PropertyChanged is NULL in my case...

like Jos stated in some comments above...
what is/was the solution to this problem? any ideas?
3/2/2011 6:33 AM | # re: Silverlight and localizing string data
AHHHHH, KPE's comment about the binding was the solution... now it works! (:

you can bind the textbox like this :
{Binding LocalizedStrings.WelcomeMessage, Source={StaticResource CustomLocStrings}}

you can also remove the reference named local (xmlns:local="clr-namespace:StringLocalization.Resources")

and remove the resource named LocString (<local:Strings x:Key="LocStrings" />)
3/18/2011 12:45 AM | # re: Silverlight and localizing string data
Its a very good article, I downloaded your code and Implemented the same logic with new Sl4 app and it worked like a charm.

But i have one problem. I am developing an application with Localization on the fly. I have a dropdown on Main Page with all the supported Languages User will select the required language (culture) from the dropdown and whole application should get change to the selected culture.

Now Only all controls in Main Page are getting changed to selected language controls in other Pages are not getting changed.

Can any one show a light on this issue.

3/25/2011 12:10 PM | # re: Silverlight and localizing string data
Hello Tim.
I really thank you for all your tutorials.

The thing that I don't understand and don't know how to do, is when I have to change the text from code behind(c#).
Let's say I have a textblock named txtWelcome. From xaml I'm saying text="Welcome".I have two resx, one for greek and one for english. They both have the txtWelcome parameter inside and each of them has the analogous text. What if I change the txtWelcome from the c# code? I mean will I write txtWelcome.text="WELCOME2" or txtWelcome.text="ΓΕΙΑΣΟΥ2"?

I have some messageboxes also. How could I know which text to put? There are also some textblocks, that don't have their text filled in the beginning. The text is filled from code-behind.

Can you help me please??

4/12/2011 11:07 PM | # re: Silverlight and localizing string data
Perhaps can you just add a short code sample about the critical step (SupportedRuntime node). I looket at some of my Silverlight projects, I even created a fresh new one, and I can't find any SupportedRuntime node...
thanks in advance.
famous funny quotes
4/14/2011 8:41 AM | # re: Silverlight and localizing string data
Is there a way around having to declare the resource on EVERY user control?
(i.e. like this)
<local:Strings x:Key="LocStrings" />

I would like to set this at the application level and not have to include this on every user control where I want to consume the resources.

4/18/2011 9:06 AM | # re: Silverlight and localizing string data
I have been successful in implementing your code. But, I have a question. How do you get access to the resources from code-behind? For example, using your resource dictionary, how would you access the resource "WelcomeMessage"?
4/20/2011 3:07 PM | # re: Silverlight and localizing string data
thank you! very nice example. I made some change in the example to make it work with sl 4.
For the binding, i use this expression Text="{Binding Source={StaticResource CustomLocStrings}, Path=LocalizedStrings.Test}"

also, move the resource <local:CustomResources x:Key="CustomLocStrings" /> to App.xaml helps to update the whole UI, not just the control holds the combobox. Accordingly, the event handler has this line changed:
((CustomResources) App.Current.Resources["CustomLocStrings"]).LocalizedStrings = new Cultures.Resources();
7/24/2011 12:15 AM | # re: Silverlight and localizing string data
It's too bad that this bug is still around even in VS2010 SP1 :(
8/21/2011 9:34 PM | # re: Silverlight and localizing string data
Nice Blog. The post is written in a very good and does a lot of useful information for me. Testking 642-357 Glad to find a way to distinguish the wording of the post. Testking 642-654 Now that make it easy for me to understand and implement the concept. Thank you for the position.
1/17/2012 4:22 AM | # re: Silverlight and localizing string data
I've implemented this to the letter and can't seem to get it to pass the new culture in.

Are there any updates I have missed.

I downloaded the example and it's not changing the default culture either?

Running VS2010 - any ideas?
10/22/2012 12:49 AM | # Cheap flights to Kinshasa
Very important when creating lan in the workplace are inner and external cheap flights to zimbabwe harare or Protection activities that would create sure security of all zazzle organization and information.
Cheap flights to Kinshasa
3/7/2014 3:14 PM | # re: Silverlight and localizing string data
In these days i want developer a silverlight application with localization engine. I already imlement de resx file and so on how the tutorial show, but i can't refresh the UI for all label localization...have any idea?

Please add 6 and 4 and type the answer here:


The opinions/content expressed on this blog are provided "ASIS" with no warranties and are my own personal opinions/content (unless otherwise noted) and do not represent my employer's view in any way.