Tech Off Thread

16 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Localisation of UI with .Net

Back to Forum: Tech Off
  • User profile image
    Rossj

    I'm hoping someone here can help with a quick question.

    I am writing a UI to learn a bit more about how it's done, and I want to localise my mini-application.  I've set up the string resources and currently I am pulling the text using GetString() in a ResourceManager instance - all very straightforward so far.

    Is there anyway that I can bind the Text property (in the 'Properties' window) of my controls to the resource file so that I don't have to manually add calls to GetString() for every control in my application?

    TIA for any help/suggestions.

  • User profile image
    PeterF

    You could inherit standard controls and override them so they will get the proper value based on the name of the control...

    The page http://www.openmymind.net/localization/ shows how it's done for ASP.NET, in a better way than compiled resources.

    Good luck,
    Peter

  • User profile image
    Gravy

    Hmm, this is an interesting one.

    The standard way of localising a form in VS 2003 is to set the local of the form class to the specific local you're targeting (this can be done in the designer). However, I've never been a great fan of having one resx file for every form / control in the app, I though it would make it hard to identify all the strings for the controls.

    In the past I too have had one resx file for strings and after the call to InitializeComponents in a form derived class I reset the form controls text. Sorry, I don't know of any way of doing this binding automatically appart from the above (changing the local on the form).

    I can see the advantage of localising the form class as all the control positions are also localised, thus if a German version of the product requires a slightly different layout it is all handled for you. But what I'm not sure on is how practical it is to find all the different resx's when it is time to change the UI language?

    Perhaps someone out there has experience of this and they could share it with us?

    Regards

    Graham

  • User profile image
    Sk4rlath
  • User profile image
    Rossj


    Thanks guys. It's not that I don't know how to do it - I have my app working fine in 4 languages (the only ones I could translate using family members Wink ) it's that I really wanted design time support for binding the Text property of Control directly to a localisation key.

    Maybe it's possible to write an Add-in that could do this, even if it's generating the same code behind the scenes. - I'll have a look see Smiley

  • User profile image
    Sk4rlath

    Did you look at the link? =)

    Set the Localizable property of the form to true, then set the language you want to localize for. Set all your properties (including sizing if needed). Then change the language to another one you need to localize for and change the properties again. Repeat this until you've got it localized for all the languages you want. VS.NET will save .resx files in the format formname.xx-XX.resx for your form and compile satellite assemblies in the right places for you.

    There is designer support for this - no need to write an add-in.

  • User profile image
    Rossj

    Umm. Yeah. I sort of skimmed it, but I apparently skimmed to well Sad  Thanks for that.

    I think I just like making more work for myself Wink

  • User profile image
    Gravy

    Out of interest how many large scale projects are localized like this, i.e. using the VS.NET method of creating one resx file per form?

    Typically, if I wanted my application localizing and I didn't have the language expertise inhouse what would 3rd party 'localizing' companies require? Would they need all my resx files?

    In interested in hearing anyones real world experiences.

    Graham

  • User profile image
    kjetilk

    Using VS 2003, it seems to be a problem when using the designer for adding localized languages. Whenever you switch between languages, VS is updating the resource file and removing all values that are not related to the components in the designer view. That is; if you add a value manually in the resx file for a specific language, this value will be removed by VS when changing language in form -> properties -> language.

    To reproduce this behaviour, try the following:
    - Add a windows form Form1.cs
    - Add a button Button1 to this form
    - Set Localizable = true and change language to e.g. Norwegian (Bokmål)(Norway). VS then adds a resource file named Form1.nb-NO.resx.
    - Set Button1's text property to 'Knapp1'
    - Go to the Form1.nb-NO.resx file and add a value, e.g. myString = test
    - Go back to the designer for Form1 and set Language = (default). Voilá! The string manually added to the resource file is gone!

    I don't know if this is "by design" (as microsoft like to call it when none-logical-and-annoying-things-happends), but it's pretty darn irritating. Anyone knows why this is happening? Is this meant to be?

    Haven't tested this in Whidbey yet, but hopefully this strange and undesirable effect is changed Smiley


  • User profile image
    Sk4rlath

    I'm no MS rep, so this is all conjecture.

    Maybe because it's too costly to track changes to new/deleted controls on the form at design time in order to properly add/remove the keys from the .resx file?

    Also, "by design" also connotates a Microsoft practice (i.e. if product X does Y "by design", then they meant it to be that way and you should consider why that is if you're doing something similar).

    And if you need custom values, can't you make yor own resource.xx-XX.resx file and do it there? Correct me if I'm wrong, I usually don't localize my apps (I only speak en-US).

  • User profile image
    Gravy

    This doesn't supprise me really, I would have thought the forms resx files are tightly linked to the designer serialization code. much like InitializeComponents() is.

    If you want none designer localized strings then use a new resx file that you add to your project manually, like sk4rlath said.

  • User profile image
    kjetilk

    Yes, there are several workarounds for this problem (satelite assemblies, resource manager wrapper, etc). My point is, that even if VS likes to point out that "we have great localization support in our product", this is not what real-life programmers who actually are using this feature, are experiencing. If you would like localization on other objects than those you can actually see in the designer, then you're on your own (e.g. setting localized text on a messagebox). And what about the generousity of a little warning before erasing values from the resource file?

    What I'm really saying is, I guess, that hopefully there will be a better tool for handling localization in Whidbey, than there is in VS 2003. Cause don't take this the wrong way; I really enjoy working with .Net and VS is a great tool - but there are always room for improvement Smiley

  • User profile image
    Gravy

    kjetilk wrote:
    ... this is not what real-life programmers who actually are using this feature, are experiencing...


    This is what I'm keen to find out. just what are people experience with this feature and is it really what enterprise development localization needs. Does anyone else have experience of localizing a large .NET windows forms project?

  • User profile image
    Gravy

    kjetilk wrote:
    What I'm really saying is, I guess, that hopefully there will be a better tool for handling localization in Whidbey, than there is in VS 2003.


    I'm no expert but I know the resource editor is much improved, you can actually add things other than text to the resx file now in IDE for example Images, Icons or Audio.

  • User profile image
    sn1p3t

    ASP.net 2.0 has built in support for this Big Smile

    I'd go with the extending server controls method (e.g. LocalizedLabel)

    Good luck.

  • User profile image
    Rossj

    sn1p3t wrote:
    ASP.net 2.0 has built in support for this Big Smile

    I'd go with the extending server controls method (e.g. LocalizedLabel)

    Good luck.


    Extending all of the controls I will need will be horribly horribly inelegant - all those new tiny derived classes {shiver}.  One resource file per form is also too just unwieldy to pass on to translators, who are often non-technical people.

    When I get back to work on Monday I'll try iterating all the controls on a Form and checking their Text property (similar in a way to the Visitor pattern I guess), using that as the key for the localisation - just to see how much of a performance hit it is, if it's not too painful I'll try that.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.