Console doesn’t display Arabic


The command prompt doesn’t have support of bidi languages. Therefore the components that run from the command line need not support Bidi languages. This is a limitation of Windows, which doesn’t support Bidi code pages in the console. So what should we do? Basically we have to fallback to another locale that is supported in the console. Basically we need to use GetConsoleFallbackUICulture and set this culture for our console application.


The code:


using System.Globalization;


 


        static void Main(string[] args)


        {


            // Set the Current


            System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(“ar-EG”);


            // Show the Culture Info


            Console.WriteLine(“Culture native name: {0}”, CultureInfo.CurrentUICulture.NativeName);


            Console.WriteLine(“Console fallback UI: {0}”, CultureInfo.CurrentUICulture.GetConsoleFallbackUICulture().Name);


            // Change the UI Culture to the Console Fallback UI


            System.Threading.Thread.CurrentThread.CurrentUICulture =


                                  CultureInfo.CurrentUICulture.GetConsoleFallbackUICulture();


            Console.WriteLine(“New UI Culture: {0}”, CultureInfo.CurrentUICulture.NativeName);


 


        }


The expected output:


Culture native name: ??????? (???)


Console fallback UI: en


New UI Culture: English


 


The important line is to set the UI Culture properly at the beginning to load the correct resources:


System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture.GetConsoleFallbackUICulture();


 

Comments (6)

  1. Sameh says:

    What benefit I gained after using "GetConsoleFallbackUICulture()" if I still unable to display Arabic characters?

    Best regards

  2. Dina Lasheen says:

    The benefit is that your application wouldn’t display ??? or high ansi on the command prompt and be broken. Instead it will default to some readable text.

    Thanks

  3. Sameh says:

    Unfortunately, characters still unreadable, although in both cases I can copy these unreadable characters and they are pasted correctly.

    Best regards..

  4. michkap says:

    My thoughts on the problem (i.e. The real problem(s) with all of these console "fallback" discussions):

    http://blogs.msdn.com/9963784.aspx

  5. Hossam Katory says:

    Comman prompt used to support Bidi text in older versions of windows ( Win Me and earlier ) why the support has been discontinued ? I understand that the code pages are supported ( CP 1256 and 1255 ) but the fonts are not provided.

  6. Hi Hossam,

    I don't have an official statement, as this was before my time at MS… but my personal thought is that if we carry old featurescode for each release of Windows, we won't have space for new and advanced features.

    There maybe third party solutions.