Problems when writing software for the international market taking into account Globalization, CultureInfo and Regional settings - and a possible solution how to resolve said problems.
I have searched the forum for this topic but I have found very little information about it. This is strange since Basic4PPC is a forum with many international users/developers. Maybe this is because Erel was already aware about these kind of problems and somehow he has already adapted Basic4PPC to handle them all. I admit that what I am describing below has not been tested in Basic4PPC since my library is being written in VB.Net but nevertheless Basic4PPC is based upon the CompactNet.framework and maybe these problems occur in Basic4PPC as well.
While adding support for other languages than English in my SpellChecking-library, I was informed by some beta-testers about some strange problems. For instance, when running the spellchecker on a Swedish device and using spellchecking in English then certain words, for instance "was", would be indicated by the spellchecker as not correct i.e. not found in the English dictionary. I decided to look further into this issue and at the end I narrowed it down to the regional settings of the device which in above case was set to Swedish. The problem is due to sorting.
The English dictionary furnished with my spellchecking-library has been sorted using English regional settings but when used on a Swedish device with Swedish regional settings, then the binarysearch would not work as expected and the word "was" was not found in the dictionary. This is because the binarysearch takes into consideration the "sorting-order" of the loaded regional-settings and since the Swedish language consider the letter "w" the same as "v", somehow the binarysearch would not work. In the Swedish alphabet, "w" is mixed with "v" as follows:
So binarysearch using Swedish regional settings does not distinguish between "w" and "v". When it read the supplied English dictionary (pre-sorted using English sorting-rules), it considered the following sort-order:
This is the reason, I believe, binarysearch would not find "was".
Now, how can I solve this problem? Well, I added simply an Array.sort(Dict) when loading the English dictionary and now the English dictionary was sorted using Swedish sorting-rules and out of sudden binarysearch worked and the word "was" was considered as a correct word i.e. it was found in the dictionary. However, Array.sort(Dict) on the device using a dictionary with more than 70'000 words took ages to load and I could not consider this is as an acceptable "solution".
I could of course supply the end user with an external program to be run on a desktop which would sort the English dictionary in accordance with his/her regional settings and which most likely would correspond with his/her device Regional settings. Then the user copied the sorted dictionary to his/her device and the problem was resolved. Also in this case, I did not consider this an acceptable solution.
Of course, I could tell the end-user to change the Regional settings into English or I could change the Registry-settings but this would mean that the device would need to be reset (restarted). Also this was not an acceptable solution.
Well, I did some research to see if one could change the regional-settings programatically on the device. If this was possible, I could keep the English-dictionary sorted as it was and I could change the regional settings of the device into English momentarily and then binarysearch would work. I found out that one could use:
only to find out later that this is not possible in the CF.NET.
I gave up but after a few days I began searching again for the solution and I found some code, considered actually a hack and risky but which resolved the problem. :sign0060: Here it is in VB.Net:
Fortunately, most devices these days have most regional settings already preloaded and as long as the regional setting you wish to use is present on the device, then above code should work. To see which regional settings are supported by the device one could use the code (here in C#) which I found here Compact Framework - Retrieve a list of countries and regions - Stack Overflow.
For the time being, I have implemented the VB.Net-code shown above in my library and I have resolved my problem or at least so it seems. Of course, by inserting another language-code which corresponds to a regional setting supported by the device, you can for instance have Swedish-sorting ("se") on a device with Italian settings.
If above problems are present also in Basic4PPC (I have not tested as I mentioned earlier on), one could perhaps write a library of the cited code for use in Basic4PPC. Example:
1) a function to see if the desired language (Regional setting) is supported by the device
2) If the function returns true, then call the SetDefaultLocale-sub.
3) A sub to reset the original Regional Settings.
Agraham or Erel: If needed, could this work in Basic4PPC?
Above solution could also resolve other problems related to regional settings such a currencies, dates etc.
See also this very interesting article User Interface bug tests, especially the part at "6. Change regional and language settings". Of course, not everything mentioned in this article is applicable to Windows Mobile.
I know that I have written a lot, hopefully not rubbish, but maybe some of it was interesting for you and I hope that I haven't wasted your time.
Take care!
I have searched the forum for this topic but I have found very little information about it. This is strange since Basic4PPC is a forum with many international users/developers. Maybe this is because Erel was already aware about these kind of problems and somehow he has already adapted Basic4PPC to handle them all. I admit that what I am describing below has not been tested in Basic4PPC since my library is being written in VB.Net but nevertheless Basic4PPC is based upon the CompactNet.framework and maybe these problems occur in Basic4PPC as well.
While adding support for other languages than English in my SpellChecking-library, I was informed by some beta-testers about some strange problems. For instance, when running the spellchecker on a Swedish device and using spellchecking in English then certain words, for instance "was", would be indicated by the spellchecker as not correct i.e. not found in the English dictionary. I decided to look further into this issue and at the end I narrowed it down to the regional settings of the device which in above case was set to Swedish. The problem is due to sorting.
The English dictionary furnished with my spellchecking-library has been sorted using English regional settings but when used on a Swedish device with Swedish regional settings, then the binarysearch would not work as expected and the word "was" was not found in the dictionary. This is because the binarysearch takes into consideration the "sorting-order" of the loaded regional-settings and since the Swedish language consider the letter "w" the same as "v", somehow the binarysearch would not work. In the Swedish alphabet, "w" is mixed with "v" as follows:
var
wassenius
vem
........
So binarysearch using Swedish regional settings does not distinguish between "w" and "v". When it read the supplied English dictionary (pre-sorted using English sorting-rules), it considered the following sort-order:
vase
was
verify
when
......
This is the reason, I believe, binarysearch would not find "was".
Now, how can I solve this problem? Well, I added simply an Array.sort(Dict) when loading the English dictionary and now the English dictionary was sorted using Swedish sorting-rules and out of sudden binarysearch worked and the word "was" was considered as a correct word i.e. it was found in the dictionary. However, Array.sort(Dict) on the device using a dictionary with more than 70'000 words took ages to load and I could not consider this is as an acceptable "solution".
I could of course supply the end user with an external program to be run on a desktop which would sort the English dictionary in accordance with his/her regional settings and which most likely would correspond with his/her device Regional settings. Then the user copied the sorted dictionary to his/her device and the problem was resolved. Also in this case, I did not consider this an acceptable solution.
Of course, I could tell the end-user to change the Regional settings into English or I could change the Registry-settings but this would mean that the device would need to be reset (restarted). Also this was not an acceptable solution.
Well, I did some research to see if one could change the regional-settings programatically on the device. If this was possible, I could keep the English-dictionary sorted as it was and I could change the regional settings of the device into English momentarily and then binarysearch would work. I found out that one could use:
B4X:
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en")
'en=English
only to find out later that this is not possible in the CF.NET.
I gave up but after a few days I began searching again for the solution and I found some code, considered actually a hack and risky but which resolved the problem. :sign0060: Here it is in VB.Net:
B4X:
'I declare the following statement
Dim myCIintl As New Globalization.CultureInfo("en") 'where "en" is for 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
Fortunately, most devices these days have most regional settings already preloaded and as long as the regional setting you wish to use is present on the device, then above code should work. To see which regional settings are supported by the device one could use the code (here in C#) which I found here Compact Framework - Retrieve a list of countries and regions - Stack Overflow.
For the time being, I have implemented the VB.Net-code shown above in my library and I have resolved my problem or at least so it seems. Of course, by inserting another language-code which corresponds to a regional setting supported by the device, you can for instance have Swedish-sorting ("se") on a device with Italian settings.
If above problems are present also in Basic4PPC (I have not tested as I mentioned earlier on), one could perhaps write a library of the cited code for use in Basic4PPC. Example:
1) a function to see if the desired language (Regional setting) is supported by the device
2) If the function returns true, then call the SetDefaultLocale-sub.
3) A sub to reset the original Regional Settings.
Agraham or Erel: If needed, could this work in Basic4PPC?
Above solution could also resolve other problems related to regional settings such a currencies, dates etc.
See also this very interesting article User Interface bug tests, especially the part at "6. Change regional and language settings". Of course, not everything mentioned in this article is applicable to Windows Mobile.
I know that I have written a lot, hopefully not rubbish, but maybe some of it was interesting for you and I hope that I haven't wasted your time.
Take care!
Last edited: