views:

326

answers:

1

Has anyone successfully localized a Mobile app that uses Orientation Aware controls to support multiple resolutions. The CultureInfo needs to be settable at runtime and not read from the system. Not sure if this is supported. Please help.

Plamen

A: 

I have never used the controls you are mentioning nor do I know the the reason why you have to set CultureInfo at runtime for said controls. Therefore, my reply is based upon your question how to set CultureInfo at runtime. If this is not what you wanted, just disregard my reply.

If we were programming a desktop-application, the CultureInfo could be changed by using:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US")
'en-US = American English

Unfortunately, this is not possible in CF.NET.

As a matter of fact, as far as I know, there is no official or supported way you can change the CultureInfo (and Regional Settings) of the device in CF.NET during runtime. One could, perhaps, change the Regional Settings in the registry but this would mean that the device must be rebooted.

In my code-library, however, I have a code-snippet which I found some time ago and which I have only tested in an emulator where it worked great. It is considered a "hack" and may be risky but while testing it in the emulator, I never ran into any problems. Here it is in VB.Net:

'I declare the following statement

Dim myCIintl As New Globalization.CultureInfo("en-US") 'where en-US is for Ame-English

'Then I call the following sub

SetDefaultLocale(myCIintl)

'Here is the code of the sub

Public Shared Sub SetDefaultLocale(ByVal locale As System.Globalization.CultureInfo)
        If Nothing Is locale Then
            Throw New ArgumentNullException("locale")
        End If

        Dim fi As System.Reflection.FieldInfo = GetType(System.Globalization.CultureInfo).GetField _
        ("m_userDefaultCulture", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Static)
        If Nothing Is fi Then
            Throw New NotSupportedException("Setting locale is not supported in this version of the framework.")
        End If
        fi.SetValue(Nothing, locale)
End Sub

Note: Please be aware of the fact that if the private variable *m_userDefaultCulture* will change its name in a future version, then above code may break. Also the name of the variable might have another name in a localized version of Windows Mobile - maybe in the Spanish version it is called something else. I don't know so I guess you must try it for yourselves.

Besides above mentioned note, above code should work (crossing my fingers) as long as the regional settings you wish to use is present on the device. To see which regional settings are supported by the device, you could use the excellent code which Ctacke showed here.

Good luck!

moster67