Xamarin forms project getting incorrect native digits from framework

Raihan Iqbal 121 Reputation points
2021-04-01T02:51:36.497+00:00

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

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,273 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. jelle vreeker 6 Reputation points
    2021-04-06T13:44:11.56+00:00

    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-RU::0,1,2,3,4,5,6,7,8,9
    rw-RW::0,1,2,3,4,5,6,7,8,9
    gd-GB::0,1,2,3,4,5,6,7,8,9
    ar-IQ::0,1,2,3,4,5,6,7,8,9
    ca-ES-valencia::0,1,2,3,4,5,6,7,8,9
    zh-CN::0,1,2,3,4,5,6,7,8,9
    de-CH::0,1,2,3,4,5,6,7,8,9
    en-GB::0,1,2,3,4,5,6,7,8,9
    es-MX::0,1,2,3,4,5,6,7,8,9
    fr-BE::0,1,2,3,4,5,6,7,8,9
    it-CH::0,1,2,3,4,5,6,7,8,9
    nl-BE::0,1,2,3,4,5,6,7,8,9
    nn-NO::0,1,2,3,4,5,6,7,8,9
    pt-PT::0,1,2,3,4,5,6,7,8,9
    ro-MD::0,1,2,3,4,5,6,7,8,9
    ru-MD::0,1,2,3,4,5,6,7,8,9
    sv-FI::0,1,2,3,4,5,6,7,8,9
    ur-IN::0,1,2,3,4,5,6,7,8,9
    az-Cyrl-AZ::0,1,2,3,4,5,6,7,8,9
    dsb-DE::0,1,2,3,4,5,6,7,8,9
    tn-BW::0,1,2,3,4,5,6,7,8,9
    se-SE::0,1,2,3,4,5,6,7,8,9
    ga-IE::0,1,2,3,4,5,6,7,8,9
    ms-BN::0,1,2,3,4,5,6,7,8,9
    uz-Cyrl-UZ::0,1,2,3,4,5,6,7,8,9
    bn-BD::0,1,2,3,4,5,6,7,8,9
    pa-Arab-PK::0,1,2,3,4,5,6,7,8,9
    ta-LK::0,1,2,3,4,5,6,7,8,9
    ne-IN::0,1,2,3,4,5,6,7,8,9
    ti-ER::0,1,2,3,4,5,6,7,8,9
    ar-EG::0,1,2,3,4,5,6,7,8,9
    zh-HK::0,1,2,3,4,5,6,7,8,9
    de-AT::0,1,2,3,4,5,6,7,8,9
    en-AU::0,1,2,3,4,5,6,7,8,9
    es-ES::0,1,2,3,4,5,6,7,8,9
    fr-CA::0,1,2,3,4,5,6,7,8,9
    se-FI::0,1,2,3,4,5,6,7,8,9
    ar-LY::0,1,2,3,4,5,6,7,8,9
    zh-SG::0,1,2,3,4,5,6,7,8,9
    de-LU::0,1,2,3,4,5,6,7,8,9
    en-CA::0,1,2,3,4,5,6,7,8,9
    es-GT::0,1,2,3,4,5,6,7,8,9
    fr-CH::0,1,2,3,4,5,6,7,8,9
    hr-BA::0,1,2,3,4,5,6,7,8,9
    ar-DZ::0,1,2,3,4,5,6,7,8,9
    zh-MO::0,1,2,3,4,5,6,7,8,9
    de-LI::0,1,2,3,4,5,6,7,8,9
    en-NZ::0,1,2,3,4,5,6,7,8,9
    es-CR::0,1,2,3,4,5,6,7,8,9
    fr-LU::0,1,2,3,4,5,6,7,8,9
    bs-Latn-BA::0,1,2,3,4,5,6,7,8,9
    ar-MA::0,1,2,3,4,5,6,7,8,9
    en-IE::0,1,2,3,4,5,6,7,8,9
    es-PA::0,1,2,3,4,5,6,7,8,9
    fr-MC::0,1,2,3,4,5,6,7,8,9
    sr-Latn-BA::0,1,2,3,4,5,6,7,8,9
    ar-TN::0,1,2,3,4,5,6,7,8,9
    en-ZA::0,1,2,3,4,5,6,7,8,9
    es-DO::0,1,2,3,4,5,6,7,8,9
    sr-Cyrl-BA::0,1,2,3,4,5,6,7,8,9
    ar-OM::0,1,2,3,4,5,6,7,8,9
    en-JM::0,1,2,3,4,5,6,7,8,9
    es-VE::0,1,2,3,4,5,6,7,8,9
    fr-RE::0,1,2,3,4,5,6,7,8,9
    bs-Cyrl-BA::0,1,2,3,4,5,6,7,8,9
    ar-YE::0,1,2,3,4,5,6,7,8,9
    es-CO::0,1,2,3,4,5,6,7,8,9
    fr-CD::0,1,2,3,4,5,6,7,8,9
    sr-Latn-RS::0,1,2,3,4,5,6,7,8,9
    smn-FI::0,1,2,3,4,5,6,7,8,9
    ar-SY::0,1,2,3,4,5,6,7,8,9
    en-BZ::0,1,2,3,4,5,6,7,8,9
    es-PE::0,1,2,3,4,5,6,7,8,9
    fr-SN::0,1,2,3,4,5,6,7,8,9
    sr-Cyrl-RS::0,1,2,3,4,5,6,7,8,9
    ar-JO::0,1,2,3,4,5,6,7,8,9
    en-TT::0,1,2,3,4,5,6,7,8,9
    es-AR::0,1,2,3,4,5,6,7,8,9
    fr-CM::0,1,2,3,4,5,6,7,8,9
    sr-Latn-ME::0,1,2,3,4,5,6,7,8,9
    ar-LB::0,1,2,3,4,5,6,7,8,9
    en-ZW::0,1,2,3,4,5,6,7,8,9
    es-EC::0,1,2,3,4,5,6,7,8,9
    fr-CI::0,1,2,3,4,5,6,7,8,9
    sr-Cyrl-ME::0,1,2,3,4,5,6,7,8,9
    ar-KW::0,1,2,3,4,5,6,7,8,9
    en-PH::0,1,2,3,4,5,6,7,8,9
    es-CL::0,1,2,3,4,5,6,7,8,9
    fr-ML::0,1,2,3,4,5,6,7,8,9
    ar-AE::0,1,2,3,4,5,6,7,8,9
    es-UY::0,1,2,3,4,5,6,7,8,9
    fr-MA::0,1,2,3,4,5,6,7,8,9
    ar-BH::0,1,2,3,4,5,6,7,8,9
    en-HK::0,1,2,3,4,5,6,7,8,9
    es-PY::0,1,2,3,4,5,6,7,8,9
    fr-HT::0,1,2,3,4,5,6,7,8,9
    ar-QA::0,1,2,3,4,5,6,7,8,9
    en-IN::0,1,2,3,4,5,6,7,8,9
    es-BO::0,1,2,3,4,5,6,7,8,9
    en-MY::0,1,2,3,4,5,6,7,8,9
    es-SV::0,1,2,3,4,5,6,7,8,9
    en-SG::0,1,2,3,4,5,6,7,8,9
    es-HN::0,1,2,3,4,5,6,7,8,9
    es-NI::0,1,2,3,4,5,6,7,8,9
    es-PR::0,1,2,3,4,5,6,7,8,9
    es-US::0,1,2,3,4,5,6,7,8,9
    es-CU::0,1,2,3,4,5,6,7,8,9
    bs-Cyrl::0,1,2,3,4,5,6,7,8,9
    bs-Latn::0,1,2,3,4,5,6,7,8,9
    sr-Cyrl::0,1,2,3,4,5,6,7,8,9
    sr-Latn::0,1,2,3,4,5,6,7,8,9
    smn::0,1,2,3,4,5,6,7,8,9
    zh::0,1,2,3,4,5,6,7,8,9
    nn::0,1,2,3,4,5,6,7,8,9
    bs::0,1,2,3,4,5,6,7,8,9
    az-Latn::0,1,2,3,4,5,6,7,8,9
    uz-Cyrl::0,1,2,3,4,5,6,7,8,9
    mn-Cyrl::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 person found this answer helpful.

  2. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 66,561 Reputation points Microsoft Vendor
    2021-04-01T07:35:38.707+00:00

    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.