【问题标题】:Is there a localizable way to format numbers with HTML?有没有一种可本地化的方式来用 HTML 格式化数字?
【发布时间】:2019-05-08 05:22:17
【问题描述】:

不同国家有不同的decimal separators和千位分隔符:

  • 英语:十进制 (.)、千位 (,)
  • 德语:十进制 (,)、千位 (.)

在编写文本时,有没有办法对数字进行注释,以便翻译引擎更轻松?

类似

(1) Germany has a population of <number>83000000</number>.
(2) <number>57.3</number>% of them are Christian.
(3) Both are in <number>12345678.9</number>.

对于英语用户,数字应该呈现如下:

(1) Germany has a population of 83,000,000.
(2) 57.3% of them are Christian.
(3) Both are in 12,345,678.9

翻译引擎可以轻松地将数字转换为:

(1) Germany has a population of 83.000.000.
(2) 57,3% of them are Christian.
(3) Both are in 12.345.678,9

Google 翻译在没有注释的情况下得到 (1) 和 (2) 正确,但不是 (3)。

(注意:这是我的问题Does a standardized way to annotate quantities to allow automatic localization exist in HTML?的一个更基本的变体)

【问题讨论】:

    标签: html localization language-translation


    【解决方案1】:

    你可以试试这个方法:

    // For English Users
    $(function(){
    	$("#ban").text((1234567.89).toLocaleString('en'))
    })
    
    /*
    // For German Users
    $(function(){
    	$("#ban").text((1234567.89).toLocaleString('de'))
    })
    */
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <div id="ban">
      
    </div>

    【讨论】:

      猜你喜欢
      • 2011-04-10
      • 2023-03-09
      • 2010-10-07
      • 2014-06-06
      • 2017-10-24
      • 1970-01-01
      • 2019-05-19
      • 2018-02-28
      • 1970-01-01
      相关资源
      最近更新 更多