设置阿拉伯数字系统区域设置不显示阿拉伯数字 [英] Setting Arabic numbering system locale doesn't show Arabic numbers

查看:67
本文介绍了设置阿拉伯数字系统区域设置不显示阿拉伯数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了这篇文章:JDK 8 和 JRE 8 支持的语言环境,它表示:

I read this article: JDK 8 and JRE 8 Supported Locales, it stated that:

可以通过带有编号系统 ID 的语言标签指定编号系统<代码>╔===================╦====================╦====╦===================╗║ 编号系统 ID ║ 编号系统 ║ 数字零值 ║╠===================╬===================╬====╬===================╣║ 阿拉伯 ║ 阿拉伯-印度数字 ║ \u0660 ║╚===================╩===================╩====╩===================╝

Numbering systems can be specified by a language tag with a numbering system ID ╔═════════════════════╦══════════════════════╦══════════════════╗ ║ Numbering System ID ║ Numbering System ║ Digit Zero Value ║ ╠═════════════════════╬══════════════════════╬══════════════════╣ ║ arab ║ Arabic-Indic Digits ║ \u0660 ║ ╚═════════════════════╩══════════════════════╩══════════════════╝

现在,为了证明这一点,我编写了以下代码:

Now, to demonstrate this, I wrote the following codes:

import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Locale;

public class Main
{
    public static void main(String[] args)
    {
        Locale locale = new Locale("ar", "sa", "arab");
        DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(locale);
        NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
        System.out.println(dfs.getZeroDigit());
        System.out.println(numberFormat.format(123));
    }
}

我期望输出类似于:

٠
١٢٣

但是,输出如下:

0
123

这样做的主要目的是让 JavaFX GUI 显示阿拉伯数字而不是英语数字,因为它使用默认语言环境(我可以用 Locale.setDefault(...) 设置它).

The main purpose of this is to make JavaFX GUI showing Arabic numbers instead of English numbers as it uses the default locale (and I can set it with Locale.setDefault(...)).

所以我的问题是,如何在语言环境中使用编号系统来显示 Java 中的本地化数字?那么,是否可以将其应用于JavaFX?

So my question is, how to use the numbering system in the locale to show localized numbers in Java? Then, is it possible to apply it on JavaFX?

推荐答案

是的,我做到了!仔细阅读Locale的JavaDoc后,我能够生成所需的语言环境:

YES, I did it! After reading Locale's JavaDoc carefully, I was able to produce the required locale:

Locale arabicLocale = new Locale.Builder().setLanguageTag("ar-SA-u-nu-arab").build();

相当于:

Locale arabicLocale = new Locale.Builder().setLanguage("ar").setRegion("SA")
                   .setExtension(Locale.UNICODE_LOCALE_EXTENSION, "nu-arab").build();

<小时>

请注意,我正在使用称为(Unicode 语言环境/语言扩展)的东西:


Note that I am using something called (Unicode locale/language extension):

UTS#35,Unicode 区域设置数据标记语言"定义了可选的属性和关键字,以覆盖或优化与区域设置相关的默认行为.关键字由一对键和类型表示.

UTS#35, "Unicode Locale Data Markup Language" defines optional attributes and keywords to override or refine the default behavior associated with a locale. A keyword is represented by a pair of key and type.

使用扩展键u"(UNICODE_LOCALE_EXTENSION)将关键字映射到 BCP 47 扩展值.

The keywords are mapped to a BCP 47 extension value using the extension key 'u' (UNICODE_LOCALE_EXTENSION).

数字的扩展键是 (nu),我使用的值是 (arab).

The extension key for numbers is (nu) and the value I used is (arab).

您可以在此处查看所有扩展键的列表.

You can see a list of all extension keys here.

这篇关于设置阿拉伯数字系统区域设置不显示阿拉伯数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆