I have this C# code for example
DateTime.Now.ToString("MMMM dd, yyyy");
Now the current thread is loading the Arabic culture. So the result is like this
???? 19, 2010
But i don't want the '2010' and the '19' to be in English (also known as Latin or West Arabic digits) - I want East Arabic numbers like "٢".
I tried
DateTime.Now.ToString("MMMM dd, yyyy", CultureInfo.GetCultureInfo("ar-lb"));
gave the same result. So any idea?
Open an Office program file, such as a Word document. On the File tab, choose Options > Language. In the Set the Office Language Preferences dialog box, in the Editing Language list, choose the Arabic dialect you want, and then choose Add.
The numbers English speakers use every day, known as Arabic numerals, were developed in the Maghreb during the 10th century. They made their way into Europe through Arab scholars in Al-Andalus (modern-day Andalusia in Spain), hence they are called Arabic numerals.
Arabic numbering rules Digits from zero to nine are specific words, namely sifr (صِفْرٌ) [0], wahid (وَاحِدٌ) [1], ithnan (اِثْنَانِ) [2], thalatha (ثَلَاثَةٌ) [3], arba'a (أَرْبَعٌ) [4], khamsa (خَمْسَةٌ) [5], sitta (سِتَّةٌ) [6], sab'a (سَبْعَةٌ) [7], thamaniya (ثَمَانِيَةٌ) [8], and tis'a (تِسْعَةٌ) [9].
Go to Tools > Options > click on the "Complex scripts" tab, then under General: Numeral select "Context". That way, numbers will appear Hindi (i.e. Arabic) when you're writing Arabic and Arabic (i.e. English) when you're writing English (as you probably know these numbers "1,2,3" are called Arabic numerals).
I've taken @Marcel B approach/workaround as I'm facing the same issue as the original question states.
In my case, it is for "ar-KW" Culture. The only difference is that I'm using the NumberFormat.NativeDigits which is already part of the CultureInfo.
You can check that like this (based on your current thread scenario):
Thread.CurrentThread.CurrentCulture.NumberFormat.NativeDigits
So, the code will look like this:
private static class ArabicNumeralHelper
{
public static string ConvertNumerals(this string input)
{
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
if (new string[] { "ar-lb", "ar-SA" }
.Contains(cultureInfo.Name))
{
return input.Replace('0', cultureInfo.NumberFormat.NativeDigits[0])
.Replace('1', cultureInfo.NumberFormat.NativeDigits[1])
.Replace('2', cultureInfo.NumberFormat.NativeDigits[2])
.Replace('3', cultureInfo.NumberFormat.NativeDigits[3])
.Replace('4', cultureInfo.NumberFormat.NativeDigits[4])
.Replace('5', cultureInfo.NumberFormat.NativeDigits[5])
.Replace('6', cultureInfo.NumberFormat.NativeDigits[6])
.Replace('7', cultureInfo.NumberFormat.NativeDigits[7])
.Replace('8', cultureInfo.NumberFormat.NativeDigits[8])
.Replace('9', cultureInfo.NumberFormat.NativeDigits[9]);
}
else return input;
}
}
I hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With