FlowDirectio

winprofessional 41 Reputation points
2020-01-22T19:00:20.883+00:00

I have a C++ UWP app that supports localization. The app has a textbox that shows digits. I have set the FlowDirection at the root frame level of the app to be right to left for Arabic locale and left to right for the other language depending on the current locale. In Arabic locale, the digits are automatically converted to Arabic instead of English ie European. How can I prevent this? ie. the digits need to be shown in English style in Arabic locale. I see that there is NumberSubstitution property in WPF where NumberSubstitution.Substitution can be specified as European like in the below link section Defining Substitution Rules.

https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/bidirectional-features-in-wpf-overview?redirectedfrom=MSDN

Is there anything similar to NumberSubstitution in UWP?

Universal Windows Platform (UWP)
{count} votes

2 answers

Sort by: Most helpful
  1. winprofessional 41 Reputation points
    2020-02-24T13:08:36.96+00:00

    Hi FayWang, thanks for th reply. I tried out the API but the API DWriteCreateFactory() fails for the IDWriteTextAnalysisSink interface. The HRESULT error is "Not an interface". Below is the code I have used. Could you please check and point out where I have possibly gone wrong?

    IDWriteNumberSubstitution* sub;  
    IDWriteFactory* fact;  
    HRESULT hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast<IUnknown**>(&fact));  
    if (SUCCEEDED(hr))  
    {  
    	  
    	hr = fact->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_CONTEXTUAL, strLocale.c_str(), TRUE, &sub); //  strLocale contains say "en-us" for eg:  
    	if (SUCCEEDED(hr))  
    	{  
    		  
    		IDWriteTextAnalysisSink* sink;  
    		hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,__uuidof(IDWriteTextAnalysisSink), reinterpret_cast<IUnknown**>(&sink)); // Fails  
    		if (SUCCEEDED(hr))  
    		{  
    			  
    			hr = sink->SetNumberSubstitution(0, m_myStringVal.GetLength(), sub); // m_myStringVal is CString  
    			if (SUCCEEDED(hr))  
    			{  
    				  
    			}  
    		}  
    	}  
    }  
    
    0 comments No comments

  2. Fay Wang - MSFT 5,191 Reputation points
    2020-04-01T08:04:50.45+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    The only workarounds that may help achieve your end goal to listen for text input and manually change numbers typed in Arabic to English. This means you can implement a TextChanging event handler and transform the national digits produced by the Arabic keyboard to Latin digits. You can try the following method to detect Arabic numerals to convert them to English.

    private string toEnglishNumber(string input)
    {
        string EnglishNumbers = "";
    
        for (int i = 0; i < input.Length; i++)
        {
            if (Char.IsDigit(input[i]))
            {
                EnglishNumbers += char.GetNumericValue(input, i);
            }
            else
            {
                EnglishNumbers += input[i].ToString();
            }
        }
        return EnglishNumbers;
    }
    
    0 comments No comments