How can I view Arabic/Persian numbers in a HTML page with strict doctype?

后端 未结 10 1849
时光说笑
时光说笑 2020-12-18 19:26

I have an HTML page that is right-to-left. When I don\'t use any doctype, my numbers are in Arabic/Persian, but when I use strict mode they turn to English.

         


        
相关标签:
10条回答
  • 2020-12-18 19:45

    Assuming you want an XHTML 1.0 Strict document:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fa" lang="fa" dir="rtl">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Title here</title>
      </head>
    
      <body>
        <p>Text here</p>
      </body>
    </html>
    

    Here's an equivalent HTML 4.01 Strict document:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="fa" dir="rtl">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Title here</title>
      </head>
    
      <body>
        <p>Text here</p>
      </body>
    </html>
    

    Here's an equivalent HTML5 page, just for comparison purposes.

    <!DOCTYPE html>
    <html lang="fa" dir="rtl">
      <head>
        <meta charset="UTF-8" />
        <title>Title here</title>
      </head>
    
      <body>
        <p>Text here</p>
      </body>
    </html>
    
    0 讨论(0)
  • 2020-12-18 19:46

    firefox default render number to latin for change this setting go to addressbar of Firefox and type about:config this page is advanced setting of firefox find this line "bidi.numeral" and double click on it if set value to "1" firefox for render text look at context. if text is persian render number to persian. if set value to "4" alwase render digit number to persian

    0 讨论(0)
  • 2020-12-18 19:53

    here is a little javascript code that converts a 1234 string to ١٢٣٤ string

       var map =
        [
        "&\#1632;","&\#1633;","&\#1634;","&\#1635;","&\#1636;",
        "&\#1637;","&\#1638;","&\#1639;","&\#1640;","&\#1641;"
        ];
    
        function getArabicNumbers(str)
        {
            var newStr = "";
    
            str = String(str);
    
            for(i=0; i<str.length; i++)
            {
                newStr += map[parseInt(str.charAt(i))];
            }
    
            return newStr;
        }
    
    0 讨论(0)
  • 2020-12-18 19:53

    This works for me, regardless of the text direction (in Chrome, Safari, Firefox and Opera):

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">
    
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <style type="text/css">
                body { direction: rtl; }
            </style>
        </head>
    
        <body>
            ۴۲
        </body>
    </html>
    

    (Omitted the content-language since that isn’t necessary here.)

    0 讨论(0)
  • 2020-12-18 20:01

    try this , hope helps you ;)

    between and

    <script language="JavaScript" type="text/javascript">
    
    
    var replaceDigits = function() {
    var map =
    [
    "&\#1632;","&\#1633;","&\#1634;","&\#1635;","&\#1636;",
    "&\#1637;","&\#1638;","&\#1639;","&\#1640;","&\#1641;"
    ]
    
    document.body.innerHTML =
    document.body.innerHTML.replace(
    /\d(?=[^<>]*(<|$))/g,
    function($0) { return map[$0] }
    );
    }
    
    </script>
    

    then in end of body tag insert this :

    <script type="text/javascript">
    window.onload = replaceDigits
    </script>
    
    0 讨论(0)
  • 2020-12-18 20:04
    var map_format_arabic = ["&\#1632;","&\#1633;","&\#1634;","&\#1635;","&\#1636;", "&\#1637;","&\#1638;","&\#1639;","&\#1640;","&\#1641;"];
    
    $.each( $('.format_arabic'), function () {
        var n=$(this).text().replace(/\d(?=[^<>]*(<|$))/g, function($0) { return map_format_arabic[$0]});
        $(this).html(n);
    });
    
    0 讨论(0)
提交回复
热议问题