Is there any built in local number to int converter?

Emon Haque 3,176 Reputation points

This is the first time I'm using my language in WPF and it actually is very easy to use and looks nice:


For date and numbers in the listbox/datepicker I don't have to do anything, it's automatically converted from/to the Thread Culture BUT for number in the TextBox I've to convert since I use avro phonetic keyboard. I've found this function on the web:

bool gotEnglish(string value) {  
    var nativeDigits = CultureInfo.CurrentCulture.NumberFormat.NativeDigits;  
    var text = value.ToString()  
                .Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, ".")  
                .Replace(nativeDigits[0], "0")  
                .Replace(nativeDigits[1], "1")  
                .Replace(nativeDigits[2], "2")  
                .Replace(nativeDigits[3], "3")  
                .Replace(nativeDigits[4], "4")  
                .Replace(nativeDigits[5], "5")  
                .Replace(nativeDigits[6], "6")  
                .Replace(nativeDigits[7], "7")  
                .Replace(nativeDigits[8], "8")  
                .Replace(nativeDigits[9], "9");  
    int num;  
    var result = int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out num);  
    if (result) NewRegion.Quantity = num;  
    return result;  

and it works fine. Is there any built in converter like BooleanToVisibilityConverter or some other way to convert local number input into int?

One more issue with Date format. In the ListBox on the right, I've specified StringFormat='dd MMM yyyy' for the date column in the middle and the first two months January (জানু) and February (ফেব) are shortened but rest are actually full name.

I've only one language on the machine:


and when I type numbers in TextBoxes, it automatically converts those numbers into my language and when I click চালু Button, those numbers and date are converted into Enlish so I don't need any phonetic keyboard for numbers or function for int conversion BUT when I type non-numeric characters, it doesn't get converted into my locale automatically:


Producing local number without that language installed on the machine is kind of inconsistent. I've tried the bn-BD language pack provided by MS:


BUT it doesn't have any phonetic keyboard, who knows what that INSCRIPT keyboard is! With that in my machine now when I switch language by hitting Windows + Space, it produces Bangla in all TextBoxes and I don't have to convert those numbers manually with that conversion function:


Phonetic keyboard for bn-BD is required. Most of us, nowadays, don't use Bijoy, Ekushe, etc. or the cryptic INSCRIPT you provide with the language pack. I use Avro in windows and also used OpenBangla in Linux, those are same, that's what I/we use.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,686 questions
0 comments No comments
{count} votes