locked
Problem localizing WinForm application RRS feed

  • Question

  • Hello there,

     

    I'm developing a WinForm application in Visual Studio 2008:

    • Version 9.0.30729.1 SP
    • Microsoft .NET Framework
    • Version 3.5 SP1
    • Installed Edition: Enterprise
    • OS: Windows XP Professional SP 3

     

    I'm localizing the application, because I need it in pt-PT and en-US. I've followed the steps written in here: http://msdn.microsoft.com/en-us/library/y99d1cd3%28VS.71%29.aspx

    ...and here: http://msdn.microsoft.com/en-us/library/b28bx3bh%28VS.80%29.aspx

     

    And when I run the application (debugging) it just don't get localized.

    My main form have the properties Language= (Default) and Localizable=true.

    Initially, I've written the labels in English, and after following the steps written in the articles (see the links above), my pt-PT resource have been created automatically as expected.

    Then, I added:

     

    Thread.CurrentThread.CurrentCulture = new
     CultureInfo("pt-PT"
    );
    Thread.CurrentThread.CurrentUICulture = new CultureInfo("pt-PT" );

     

    ...in the constructor of my main form, before the InitializeComponent() method.

     

     

    And run the app...and nothing. I'm getting nuts.

    What can it be?

     

    Feel free to ask for more information if it can help you to help me out.

     

    Thanks in advance! :)

     

    Hug from Portugal,

    -- --

    R. Saraiva

    • Moved by edhickey Friday, May 7, 2010 5:04 PM (From:.NET 3.0/3.5 Windows Workflow Foundation)
    Friday, May 7, 2010 2:53 PM

Answers

  • Hello everyone!

     

    I found the source of my problems.

     

    The Assembly Native Culture was "pt-PT", and I realized that I was generating the wrong language resource  file.

    What I had:

    - Forms in English;

    - Localizable = True

    - Language = (Default)

     

    ...and whenever I changed to: Language = Portuguese (Portugal), the designer changed the labels as well and even created the x.pt-PT.resx file.

     

    The solution (After realized my Assemble Native Culture):

    - Rewrote the forms in Portuguese;

    - Localizable = True

    - Language = (Default)

     

    ...and after that changed the Language = English (Unites States);

    The new resource file was generated x.en-US.resx ...

     

    ...And Voilá!!!

    Everything's working fine!

     

    Thanks everyone for your replies.

     

    Best Regards,

    -- --

    R. Saraiva

    • Marked as answer by RSaraiva Thursday, May 13, 2010 11:51 AM
    Thursday, May 13, 2010 11:51 AM

All replies

  • Hello RSaraiva,

    I can't reproduce the issue ... those a pretty basic steps and I got no idea what you could have done wrong.

    Does your form behave correctly in design time when you change Language property ... does it get localized ... can you verify that strings in your FormName.pt-PT.resx file are correct ?

    If so, could you upload test project so we can reproduce the issue and check if anything is wrong there.

    Best regards, 
    Vladimir

    Friday, May 7, 2010 8:58 PM
  • Hello there Vladimir,

     

    fisrt of all, thanks for the fast reply. :)

    The answer is yes: in design mode, the labels get all right localized.

    I've created a 'Test Project' with the code Copy-Pasted from the previous project...and guess what?! The problem just don't happens in this new project. It gets right localized.

     

    I'm wondering if it is some kind of assembly/project property or attribute.

     

    Where I can I check if this kind of behavior is a known issue?

     

    Thanks again.

     

    Cheers,

    -- --

    R. Saraiva

    Monday, May 10, 2010 10:28 AM
  • Hmm, I don't know of any project properties or attributes that would stop form localization.

    Can you check FormName.designer.cs file that doesn't work and compare it with the one in the new project, the one which works.

     

    You can report issue on microsoft connect (http://connect.microsoft.com/) but stick around, maybe someone here has a better idea.

    Best regards,
    Vladimir

    Monday, May 10, 2010 6:21 PM
  • Sorry, I am also not able to reproduce your issue on my side.

     

    I set Form’s Localizable property to true, and change the Language property to Portuguese (Portugal).

    Change the Lable.text to AAAA.

    Then I change the form’s Language property back to (default).

    Change the form constructor to;

    C#:

            public Form1()

            {

                Thread.CurrentThread.CurrentUICulture = new CultureInfo("pt-PT");

     

                InitializeComponent();

            }

     

    VB.NET

    Imports System.Globalization

    Imports System.Threading

     

    Public Class Form1

     

        Sub New()

     

            Thread.CurrentThread.CurrentUICulture = New CultureInfo("pt-PT")

     

            ' This call is required by the Windows Form Designer.

            InitializeComponent()

     

            ' Add any initialization after the InitializeComponent() call.

     

        End Sub

     

    End Class

    When form showing, the label shows “AAAA”. It works fine.

     

    Hope this helps. If this not helps, could you please give us a project to reproduce your issue?

     

    Best regards,

    Ling Wang


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Thursday, May 13, 2010 4:11 AM
  • By the way, you provided document link is: http://msdn.microsoft.com/en-us/library/y99d1cd3(v=VS.71).aspx

    If you use Visual studio 2008, you’d better change it the http://msdn.microsoft.com/en-us/library/y99d1cd3(v=VS.9).aspx or http://msdn.microsoft.com/en-us/library/y99d1cd3.aspx (The latest one)

     

    Sometimes the documents for different versions of visual studio are different. But this time, they are the same. J


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Thursday, May 13, 2010 4:17 AM
  • Hi,

    Just write following line of code before thisInitializeComponent();

    Thread.CurrentThread.CurrentUICulture = CultureInfo("pt-PT")

    Thanks

    Amit

    • Proposed as answer by Amit Bansal Thursday, May 13, 2010 10:33 AM
    Thursday, May 13, 2010 6:16 AM
  • Hello everyone!

     

    I found the source of my problems.

     

    The Assembly Native Culture was "pt-PT", and I realized that I was generating the wrong language resource  file.

    What I had:

    - Forms in English;

    - Localizable = True

    - Language = (Default)

     

    ...and whenever I changed to: Language = Portuguese (Portugal), the designer changed the labels as well and even created the x.pt-PT.resx file.

     

    The solution (After realized my Assemble Native Culture):

    - Rewrote the forms in Portuguese;

    - Localizable = True

    - Language = (Default)

     

    ...and after that changed the Language = English (Unites States);

    The new resource file was generated x.en-US.resx ...

     

    ...And Voilá!!!

    Everything's working fine!

     

    Thanks everyone for your replies.

     

    Best Regards,

    -- --

    R. Saraiva

    • Marked as answer by RSaraiva Thursday, May 13, 2010 11:51 AM
    Thursday, May 13, 2010 11:51 AM