Cannot make pt-BR Localization work

Answered
0
0

Hi.

I have been trying to add pt-BR Localization into my application but haven’t had success. The Culture seems to change fine, meaning currency symbol, dates, etc.. However, the MessageBox don’t seem to replace their Button Labels. It works with the pt-PT which comes out of the box, but that doesn’t apply to our case. I have modified the Localization example that comes with Wisej and added the pt-BR Resource to the solution, it doesn’t work there either. I have attached it to here so maybe you guys could have a look and tell me what I am doing wrong.

Thanks in advance.

Ivan

Attachment
  • You must to post comments
Best Answer
0
0

Hi Ivan,

issue #2523 is fixed in our latest Wisej release (2.2.29)

Best regards
Frank

  • Ivan Borges
    Hi Frank. Working perfectly now. Thank you!
  • You must to post comments
Great Answer
0
0

Hi Levie.

Yes, it works for Italian or French, even for pt-PT, which is Portuguese from Portugal. And it works if I don’t set the Windows Culture “Format” to Portuguese (Brazil), which is weird.

Have you tried changing one of your server’s Format to Portuguese (Brazil) and tested the sample to see the results?

  • Levie (ITG)
    Hi Ivan, with your suggestion I was able to replicate the issue and we have logged it as #2523. We’ll release a new build in the next day or two with the fix! Please let me know if it works for you. Best regards, Levie
  • Ivan Borges
    You guys are the best. Thank you!
  • You must to post comments
0
0

Sure!



using System;
using System.Globalization;
using System.Resources;
using System.Threading;
using Wisej.Web;

namespace Localization
{
	public partial class Window1 : Form
	{
		public Window1()
		{
			InitializeComponent();
		}

		private void Window1_Load(object sender, EventArgs e)
		{
			SetValues();

			// get notified when the browser is refreshed.
			Application.ApplicationRefresh += Application_ApplicationRefresh;
		}

		void Application_ApplicationRefresh(object sender, EventArgs e)
		{
			SetValues();
		}

		private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
		{
			// refresh the browser using the new language.
			string[] languages = {"auto","en","de", "it", "fr", "es", "pt-BR"};
			Application.Navigate(Application.StartupUri.ToString() + "?lang=" + languages[this.comboBox1.SelectedIndex]);
		}

		private void SetValues()
		{
			this.labelNumber.Text = 12345678.ToString("c");
			this.labelCurrency.Text = 12345678.ToString("c");
			this.labelDateTime.Text = DateTime.Now.ToString("F");

			var loAssembly = this.GetType().Assembly;

			var RS1 = new ResourceManager("Localization.Resources", this.GetType().Assembly);
			this.Text = RS1.GetString("Title");
			this.button1.Text = RS1.GetString("ShowMessageBox");

			var lcCancel = RS1.GetString("$Cancel");
			var lcShowMessageBox = RS1.GetString("ShowMessageBox");

			var lcCulture = Application.CurrentCulture;

			MessageBox.Show("The buttons are localized", buttons: MessageBoxButtons.YesNoCancel, modal: false);
		}

		private void button1_Click(object sender, EventArgs e)
		{
			CultureInfo ci = new CultureInfo("pt-BR");
			var RS2 = new ResourceManager("Localization.Resources", this.GetType().Assembly);
			var lcCancel = RS2.GetString("$Cancel", ci);
			var lcShowMessageBox = RS2.GetString("ShowMessageBox", ci);

			var lcCulture = Application.CurrentCulture;

			MessageBox.Show("The buttons are localized", buttons: MessageBoxButtons.YesNoCancel, modal: false);
		}
	}
}

The MessageBox in the SetValues shows the Message Buttons properly localized.
On the other hand, the MessageBox in the button1_Click doesn’t. Using the ResourceManager within this Click works properly if I force the CultureInfo, otherwise, it doesn’t.
I tested the Thread.CurrentThread.CurrentCulture inside it and it was properly set as “pt-BR”.

The default language in my Dev machine and in the Google Server is English already.

But, I have a feeling you are on the right track here… In the Control Panel Region, I had (and have to have it) Portuguese (Brazil) as the “Format”, which gives us the right Currency, numbers, dates formats. The Google Servers are also set for this Format. I changed my Dev machine to English (United States) and all worked fine. So, maybe the ResourceManager is not really using the Thread.CurrentThread to get this setting, I would bet.

  • Levie (ITG)
    Hi Ivan, it looks like the ResourceManager gets it’s culture from CurrentUICulture (not CurrentCulture). check out this post under “Difference between CurrentCulture and CurrentUICulture”. https://support.microsoft.com/en-us/help/893663/globalization-issues-in-asp-and-asp-net.
  • Levie (ITG)
    Does the MessageBox work for other languages other than pt-PT (try italian or french)? The CurrentCulture and CurrentUICulture should always be in sync in Wisej unless one of them gets changed manually.
  • You must to post comments
0
0

ResourceManager uses the Thread.CurrentThread.CultureInfo. All of .NET localization uses the thread’s culture.

The question is why it fails for you and not for any other machine we tried including azure servers.

Can you check or change the default language on your server to en-US? However I guess that google’s vm is already en-US. In which case it must be a deployment issue.

Can you send the code you just tried and loaded the wrong resource for you?

 

  • You must to post comments
0
0

Some more info.

If I force the CultureInfo to be used by the ResourceManager GetString method inside the button click, it finds the strings properly, but still shows the MessageBox with the generic/wrong content.


			CultureInfo ci = new CultureInfo("pt-BR");
			var RS2 = new ResourceManager("Localization.Resources", this.GetType().Assembly);
			var lcCancel = RS2.GetString("$Cancel", ci);
			var lcShowMessageBox = RS2.GetString("ShowMessageBox", ci);

If I don’t mention the CultureInfo and let the ResourceManager use what it considers to be the current culture, it fails. But Application.CurrentCulture shows pt-BR inside the button click properly. So, I guess ResourceManager is getting the CultureInfo from somewhere that is not set after the trip to the server.

  • You must to post comments
0
0

Thanks Luca, here are the results:

1 – I removed the bin/pt, but as soon as I run the sample, it gets automatically created back.

2 – Added the code. the ResourceManager doesn’t seem to be able to find the strings in the pt-BR resource file. However, the Application.CurrentCulture still returns pt-BR as the current culture.

I have also tried renaming pt-BR to pt, no luck.

Then, I thought of putting a MessageBox inside the SetValues method, which runs whenever ApplicationRefresh is triggered. And it works fine from there. (!)

Right after I see it working there, once I click on the button to show the MessageBox that is coded in it, it doesn’t work anymore, and Application.CurrentCulture still returns pt-BR properly, but the strings from its resource file are not correct, apparently coming from a generic resource as if it didn’t find the pt-BR resource file.

  • You must to post comments
0
0

Try this on a dev machine:

 

1. Remove the bin/pt directory and leave only the bin/pt-BR

2. Add code in the button click that shows the message box that uses a ResourceManager to read the localized strings you added: $ok, etc. and check the name of Application.CurrentCulture.

 

I will send you a different test app to check what is loaded.

The ResourceManager class in .NET is the one loading the resources. Wisej is not doing anything other than using it to read the localized strings. It’s all part of standard .NET.

 

There may be a collision between /pt and /pt-BR.

You can also try to rename your localized assembly to be pt instead of pt-BR.

  • You must to post comments
0
0

Hi Luca.

There is something really weird from my side, I am sure. Just can’t think of what could be.
Yes, the DLL is deployed to the Google Cloud server, I have attached a picture.

Attachment
  • You must to post comments
0
0

The warnings are normal.

I simply clicked Publish in VS and published this:

https://wisejlocalization.azurewebsites.net/

Make sure that /bin/pt-BR/Localization.resources.dll is deployed.

Attachment
  • You must to post comments
0
0

Hey Levie.

Happy New Year!

So, I turned all Common Language Runtime Exceptions on but nothing was thrown when I changed the Localization.
Yes, I have tried on a completely different environment, you might have missed it, but I deployed it to a Google Cloud VM where you can try yourself (http://pfnwj.test.profilme.net), also had the MessageBox labels not translated.
I had a look at the Console on Chrome and noticed the warnings once I clicked on the button to show the MessageBox. I have attached a picture. However, I am not setting any theme to this test application.
Any thoughts?

Attachment
  • You must to post comments
0
0

Hi Levie.

This is really strange. I might have a haunted machine on my desk. 😀
I’m on Wisej 2.2.25.0. I have attached a picture and you can see the buttons. Also, I have a different icon for the message, is it a different Theme you are using? I have also restarted my machine, just in case… I am drawing a blank here.

Attachment
  • Ivan Borges
    Just to let you know, I have deployed the sample to a different server (Google Cloud) and got the same results. The culture is set, but the Message Buttons don’t get translated. By the way, I noticed you tested under the Blue-2 theme and run my test on it too, just to make sure… got the same results.
  • Levie (ITG)
    Hi Ivan, I tried it with Blue-1 and 2.2.25 and it worked fine. Can you try to enable “Common Language Runtime Exceptions” under the Exception Settings window and then change the localization? I would also recommend trying it on another machine to be safe :-). Let me know! -Levie
  • You must to post comments
0
0

Hi Ivan,

I just ran the sample you provided using the latest version of Wisej and it seems to be working ok. It uses the localization file you created and placed in the root directory. I attached an image of the outcome.

What version of Wisej are you using?

Best,

Levie

Attachment
  • You must to post comments
Showing 12 results
Your Answer

Please first to submit.