4

i am working to globalize items using C#

i have tried to use UICulture property to convert some items format like number format , Currency format ... to a different cultures using the code below. actually working fine but now, i need to add phone masks, zip code. any help will be appreciated.

//this is the index.cshtml file 

@using System.Globalization
@using System.Threading

 @{
      Layout = null;
      if (!Request.QueryString["lang"].IsEmpty())
   {
    Culture = UICulture = Request.QueryString["lang"];
   }
 }

   <!DOCTYPE html>

   <html>
   <head>
   <meta name="viewport" content="width=device-width" />
   <title>Index</title>
 </head>
  <body>

          <a href="@Url.Action("Change" , "Demo" , new { lang = 
            "en"})">English</a>
          <a href="@Url.Action("Change" , "Demo" , new { lang = 
            "fr"})">French</a>
          <a href="@Url.Action("Change" , "Demo" , new { lang = 
            "de"})">Germany</a>
          <a href="@Url.Action("Change" , "Demo" , new { lang = 
            "ja"})">Japan</a>
          <a href="@Url.Action("Change" , "Demo" , new { lang = "pt- 
             BR"})">Brasil</a><br />

      @{ int number = 123456;}
      @{ double percent = 12.34;}

              Number format : @number.ToString("N")
              <br />
              Currency format : @number.ToString("C")
              <br />
              Percent format : @percent.ToString("P")
              <br />
              Date format : @DateTime.Now.ToString("D")
              <br />



  </body>
  </html>
Abdessamad Jadid
  • 381
  • 1
  • 4
  • 16
  • 1
    As for date, you can use `DateTime.Now.ToString("D", new CultureInfo("fr"))`. Not sure whether any support exists in the framework for zip / phone number, so those you may have to implement yourself. – Mr Anderson Jun 05 '19 at 20:20

0 Answers0