html - 有没有一种可本地化的方式来用 HTML 格式化数字?
问题描述
不同的国家有不同的小数分隔符和千位分隔符:
- 英语:小数 (
.
)、千 (,
) - 德语:十进制 (
,
)、千 (.
)
在编写文本时,有没有办法对数字进行注释,以便翻译引擎更轻松?
就像是
(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
谷歌翻译在没有注释的情况下得到 (1) 和 (2) 正确,但不是 (3)。
(注意:这是我的问题的一个更基本的变体。HTML 中是否存在标注数量以允许自动本地化的标准化方法?)
解决方案
你可以这样试试:
// 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>
推荐阅读
- excel - 防止excel弄乱mac地址
- java - 如何将 GraphiQL 与 Spring-Boot 集成?
- serverless-framework - 只需使用适用于 AWS 的无服务器框架部署 cloudformation 更改
- android - TextInputLayout 抛出“此组件的样式要求您的应用主题为 Theme.AppCompat(或后代)。”
- c# - 基本 WebSocket 聊天
- android - RotateAnimation 获取图像的当前角度
- java - 创建缓存时如何将所有缓存名称及其数据放入 List<> 中?
- neural-network - 以逐个字符的方式生成注意力文本
- c# - 我怎么知道我的进程在 c# 中被杀死了?
- c++ - 是否可以在 C++ 中将类标记为非最终/可派生?