question

raihaniqbal avatar image
0 Votes"
raihaniqbal asked LeonLu-MSFT commented

Xamarin forms project getting incorrect native digits from framework



I'm trying to localize my Xamarin forms app and I noticed that my datetimes were not being localized. When I inspected the culture info object, I noticed the NativeDigits array was populated with English digits.

This is what I get in my Xamarin project:

83491-screenshot-1.png

This is what it should look like (screenshot taken from a Console project):

83501-screenshot-2.png


dotnet-xamarin
screenshot-1.png (28.4 KiB)
screenshot-2.png (39.5 KiB)
5 |1600 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.

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered LeonLu-MSFT commented

Hello,​

Welcome to our Microsoft Q&A platform!

You can use the following method to convert from Arabic numbers to the Persian Format

public string getPersianNumber(string data)

        {

            for (int i = 48; i < 58; i++)

            {
                data = data.Replace(System.Convert.ToChar(i), System.Convert.ToChar(1728 + i));
            }

            return data;

        }


==============Update===============

If you use LocalizedDateTime.Text = $"Current Time: {DateTime.Now.ToShortTimeString()}"; When you change the Localization, the number will be english format, it will not change the Numbers to Arabic Or Persian Format. If you want to change the number format, you should define the string in the resx file

84845-image.png

Then we can use it in the xaml.

<Label Text="{x:Static resource:AppResources.Three}"
               FontSize="Large"/>


Here is running screenshot.

84872-image.png

84787-image.png



Best Regards,

Leon Lu



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (14.6 KiB)
image.png (20.4 KiB)
image.png (17.5 KiB)
· 8
5 |1600 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.

That doesn't answer my question. First, my question has nothing to do with Persian and in fact it doesn't matter what language it is. I'm just trying to understand why within a Xamarin forms project the NativeDigits array would contain English digits whereas when I run the same code in a Console app I can see the native digits.

0 Votes 0 ·

Could you share a demo that could reproduce this issue?

0 Votes 0 ·

I have uploaded the sample here:

https://github.com/raihaniqbal/MultilingualXFSample

The current time in the MainPage is always displayed in English irrespective of what language I select.

0 Votes 0 ·
Show more comments
jellevreeker-1317 avatar image
1 Vote"
jellevreeker-1317 answered raihaniqbal commented

I have the same problem but only on Xamarin.Android. If I print all NativeDigist from different cultures. I get this, All language contain english digits

or-IN::0,1,2,3,4,5,6,7,8,9
ta-IN::0,1,2,3,4,5,6,7,8,9
te-IN::0,1,2,3,4,5,6,7,8,9
kn-IN::0,1,2,3,4,5,6,7,8,9
ml-IN::0,1,2,3,4,5,6,7,8,9
as-IN::0,1,2,3,4,5,6,7,8,9
mr-IN::0,1,2,3,4,5,6,7,8,9
mn-MN::0,1,2,3,4,5,6,7,8,9
cy-GB::0,1,2,3,4,5,6,7,8,9
km-KH::0,1,2,3,4,5,6,7,8,9
lo-LA::0,1,2,3,4,5,6,7,8,9
my-MM::0,1,2,3,4,5,6,7,8,9
gl-ES::0,1,2,3,4,5,6,7,8,9
kok-IN::0,1,2,3,4,5,6,7,8,9
si-LK::0,1,2,3,4,5,6,7,8,9
am-ET::0,1,2,3,4,5,6,7,8,9
ne-NP::0,1,2,3,4,5,6,7,8,9
fy-NL::0,1,2,3,4,5,6,7,8,9
ps-AF::0,1,2,3,4,5,6,7,8,9
fil-PH::0,1,2,3,4,5,6,7,8,9
ha-Latn-NG::0,1,2,3,4,5,6,7,8,9
yo-NG::0,1,2,3,4,5,6,7,8,9
nso-ZA::0,1,2,3,4,5,6,7,8,9
lb-LU::0,1,2,3,4,5,6,7,8,9
kl-GL::0,1,2,3,4,5,6,7,8,9
ig-NG::0,1,2,3,4,5,6,7,8,9
om-ET::0,1,2,3,4,5,6,7,8,9
ti-ET::0,1,2,3,4,5,6,7,8,9
haw-US::0,1,2,3,4,5,6,7,8,9
so-SO::0,1,2,3,4,5,6,7,8,9
ii-CN::0,1,2,3,4,5,6,7,8,9
br-FR::0,1,2,3,4,5,6,7,8,9
ug-CN::0,1,2,3,4,5,6,7,8,9
gsw-FR::0,1,2,3,4,5,6,7,8,9
sah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0,1,2,3,4,5,6,7,8,9
zh-Hant::0,1,2,3,4,5,6,7,8,9
zh-CHT::0,1,2,3,4,5,6,7,8,9
nb::0,1,2,3,4,5,6,7,8,9
sr::0,1,2,3,4,5,6,7,8,9
tg-Cyrl::0,1,2,3,4,5,6,7,8,9
dsb::0,1,2,3,4,5,6,7,8,9
uz-Latn::0,1,2,3,4,5,6,7,8,9
pa-Arab::0,1,2,3,4,5,6,7,8,9
tzm-Latn::0,1,2,3,4,5,6,7,8,9
ha-Latn::0,1,2,3,4,5,6,7,8,9

· 1
5 |1600 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.

Yep you're right. So you get native digits in an iOS emulator?

0 Votes 0 ·