Loading...
 
Multi-Language Add-In for Visual Studio

Multi-Language Add-In for Visual Studio


LinkButton OnClientClick should be localized ?

Hi there,

We finaly decided to go for a full translation of our ASP.NET applikation.

I just found out that LinkButton OnClientClick isn't localizeable.
What is best practice to localize this attribute? Do I really need to set this in codebehind?

BTW, we are frequently using th OnClientClick with the jacascript confirm function:

OnClientClick="return confirm('Are you sure you want to...')"
Germany

Hi Nick,

I'm on vacation at present and will be back in one weeks time. I will look at this problem when I return.

I would like to add support for localizing Javascript, but there are some serious difficulties. The greatest problem is that it runs on the client, so I would have to download the localized texts using some sort of ajax technique.

Best regards
Phil


Thank you for the answer!

I think we will have to make it manually for now then (moving it to codebehind).

But it would really make a difference to have the support (now I have to manually search i files for javascript and then place it in pageload or something like that..

Hope you enjoy your vacation!

/Nick


Germany

Hi Nick,

the reason that you cannot localize the OnClientClick property, is that it does not have the Localizable attribute. Here is a screenshot from the Reflector showing the attributes:
Image
The only property with the Localizable attribute is "Text".

Given that it doesn't have the Localizable attribute, I would not expect it to be loaded from a resource string, even if one was present.

However, this is not true! This property can in fact be localized. I have just tried it out and was very surprised that it worked.

To translate this property, open the options dialog and select the option "Show all text properties" on the Web tab, as shown below.
Image

After rescanning, the OnClientClick property will be shown and can be translated.

I am not really happy with this option. It may show all kinds of properties which you are not really interested in, and I do not know whether they can all be translated or not. It might be better if I defined a list of additional properties to show.

In the future, it would be better to localize the javascript, something like:

OnClientClick="return confirm(ml_string(1,'Are you sure you want to...'))"

just like in the source code.

There are a bunch of problems in doing this, in particular:

  • I would have to write a scanner for javascript code
  • I would have to implement a version of the ml_script function in javascript

but both of these seem possible. I figure I could probably handle javascript in script tags.

In the case of the OnClientClick property, there are no script tags, so it is not obvious that it contains javascript code. I can't see any generic way to determine that it contains javascript.

The only simple approach that I can see, is to hard code the property name OnClientClick (or even to assume that any property starting with "On" contains javascript).

I'll let you know if I make any progress on this issue.

Phil

Germany

Hi Nick,

I have now added some JavaScript support as described in Javascript support in ASP.NET pages, which turned out to be easier than I expected.

However, I haven't yet added support for the OnClientClick property

I hope to add this soon, but I have a few other things to look at first.

Phil


As always: thank you for looking at our issues!
Looking forward to the OnClientClick support as well at some point.. ;-)