date format - How to show Persian numbers on ASP.NET MVC page? -


i'm building site needs support both english , persian language. site built asp.net mvc 3 , .net 4 (c#). controllers inherit basecontroller, sets culture "fa-ir" (during test):

thread.currentthread.currentculture = new cultureinfo("fa-ir"); thread.currentthread.currentuiculture = new cultureinfo("fa-ir"); 

in views, i'm using static helper classes convert right timezone , format date. like:

dateformatter.tolocaldateandtime(model.createdonutc) 

i'm doing same money moneyformatter. money, currency prints correctly in persian (or, @ least think don't know persian. verified later on though our translators). same goes dates, month printed correctly. displays currently:

for money:

قیمت: ريال 1,000  

for dates:

21:01 ديسمبر 3 

in these examples, want numbers print in persian. how accomplish that?

i have tried adding:

<meta http-equiv="content-type" content="text/html; charset=windows-1256" /> 

in head tag, recommended on forums. not change though (from can see). have added "fa-ir" first language in browser languages (both ie , firefox). didn't either.

anyone got ideas on how solve this? i'd rather avoid creating translation tables between english numbers , persian numbers, if possible.

best regards,
eric

after further research found answer microsoft employee stating don't translate numbers, though it's possible using array of digits specific culture, provided nativedigits property (see http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.nativedigits.aspx).

to find out if text submitted in form arabic or latin i'm doing:

public bool iscontentarabic(string content) {     string pattern = @"\p{isarabic}";     return regex.ismatch(         content,          pattern,          regexoptions.righttoleft | regexoptions.ignorecase | regexoptions.multiline); }  public bool iscontentlatin1(string content) {     string pattern = @"\p{isbasiclatin}";     return regex.ismatch(         content,          pattern,          regexoptions.ignorecase | regexoptions.multiline);  } 

and convert persian digits "latin" equivalents, wrote helper:

public static class numberhelper {     private static readonly cultureinfo arabic = new cultureinfo("fa-ir");     private static readonly cultureinfo latin = new cultureinfo("en-us");      public static string toarabic(string input)     {         var arabicdigits = arabic.numberformat.nativedigits;         (int = 0; < arabicdigits.length; i++)         {            input = input.replace(i.tostring(), arabicdigits[i]);         }         return input;     }      public static string tolatin(string input)     {         var latindigits = latin.numberformat.nativedigits;         var arabicdigits = arabic.numberformat.nativedigits;         (int = 0; < latindigits.length; i++)         {             input = input.replace(arabicdigits[i], latindigits[i]);         }         return input;     } } 

i've hooked in before model binding takes place , there convert digit-only input forms latin digits, if applicable.

ako, direction goes managed solve quite bit of issues using 'dir' attribute (dir => direction) on html tag our web page. this:

<html dir="rtl"> 

the 'dir' attribute takes either "rtl" (right-to-left) or "ltr" (left-to-right).

hope helps someone!


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -