Main Site Documentation

Localization (CurrentUICulture)


#1

Hi all,

I am trying to internationalize my interface (running out a G120, netmf 4.3.4.0), and I guess I am missing something.

Here is what I did:

  • I created a “resources.resx” with all the menu strings in French (default language)
  • I created a “resources.en.resx” with the same string names, and the values in English
  • I created a “resources.es.resx” with the same thing, for Spanish.

The a rebuild the whole solution.

I implemented this little piece of code that is supposed to tell me all the available cultures:

 cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (CultureInfo culture in cultures) 
    Debug.Print("Available culture = " + culture.Name);

As a result, it shows:

… and no Spanish (“es”) …

However, I tried to switch between default (French) and English, and it only work a couple of time out of dozen…

I created a menu updating an enum-typed value, whose value is store into a SDCard storage. When the device boots, the value is read, and the following code is executed:

 switch (Configuration.Language)
            {
                case Languages.English:
                    ResourceUtility.SetCurrentUICulture(new CultureInfo("en"));
                    break;
                case Languages.French:
                    ResourceUtility.SetCurrentUICulture(new CultureInfo(""));
                    break;
                case Languages.Spanish:
                    ResourceUtility.SetCurrentUICulture(new CultureInfo("es"));
                    break;
                default:
                    ResourceUtility.SetCurrentUICulture(new CultureInfo(""));
                    break;
            }
            Debug.Print("Current UI Culture='" + CultureInfo.CurrentUICulture.Name + "'");

Of course, Configuration.Language is correct, and even CurrentUICulture.Name printed out shows the Culture value has been switched properly (between ‘en’ and ‘’ though…)… However, the UI is not translated, in most of case.

The “most of case” is important, because if it would never be translated, I’d assume something was missing in my code. The fact I see my screen translated from time to time tells me I must be close, and I must have a little something missing.

Does anyone have any suggestion of documentation to read, because everything I found is meant for Windows applications, and does not apply to netmf.

FYI, I used the resources’ string as follows:



I am open to any idea...

Thx,

Thomas

#2

Hi,

I found a pattern to be able to switch from one language to the othert, I need to “reboot CLR” using FEZ Config.

  • When I change the language in my menu (when the actual call toResourceUtility.SetCurrentUICulture() occurs), and then if I “reboot CLR” in FEZ config, it works

  • When I change the language in my menu (when the actual call toResourceUtility.SetCurrentUICulture() occurs), and the I turn it off and on, and never works.

How come ?


#3

Perhaps this is expected - i.e. perhaps localisation only takes effect when the system restarts. You may actually have to look at the actual netmf code to find the reasoning behind this as I cant see any detail in the netmf reference https://msdn.microsoft.com/en-us/library/microsoft.spot.resourceutility.setcurrentuiculture(v=vs.102).aspx


#4

Do you see the same results in the emulator?


#5

Brett -> When the device reboots, it does not work. I have to make a “Reboot CLR” with FEZ Config to see the changes

Gus -> I did not try the emulator, but it would be very painful because my code does not really support it (too many reference to the hardware, with no flags to switch from emulation to normal operations)


#6

It will be a good idea to run a small program on the emulator and on your device to demonstrate the issue. Do not use your full program.