question

winprofessional avatar image
0 Votes"
winprofessional asked ·

FlowDirectio

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://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/bidirectional-features-in-wpf-overview?redirectedfrom=MSDN

Is there anything similar to NumberSubstitution in UWP?



windows-uwp-xaml
· 4
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The Windows.Globalization.NumberFormatting namespace provides number formatting and parsing APIs that generate strings for display that respect either the current user's preferences, or a caller-specified language(s) and region, so I tried to use it to convert Arabic numbers into English style. I first changed the target numeral system of the translator using NumeralSystemTranslator.NumeralSystem but didn't work. Then I found NumeralSystemTranslator.TranslateNumerals method mentions characters in value that are not Latin digits are not converted, it will pass through unchanged.


0 Votes 0 · ·

So this method may not convert Arabic numbers into English style. But I'm not sure if there is another way to achieve this, I will ask team about it.

0 Votes 0 · ·

Thank you FayWang. Any new updates on this?

0 Votes 0 · ·

Hi, here is an API about IDWriteTextAnalysisSink::SetNumberSubstitution, it can set the number substitution on the text range affected by the text analysis for a specified locale. You can try this method to convert your digits.


0 Votes 0 · ·
winprofessional avatar image
0 Votes"
winprofessional answered ·

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))
             {
                    
             }
         }
     }
 }
· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

FayWang-MSFT avatar image
0 Votes"
FayWang-MSFT answered ·

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;
 }


· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.