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

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

问题描述

我读过这篇文章: JDK 8和JRE 8支持的语言环境,它声明:

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


编号系统可由具有编号系统ID的语言标签指定
$ b $b╔════════════════════════════════════════════════════════════════════════════════════════ ═════════════════════b $ b║编号系统ID║编号系统║数字零值║$ b $b╠═══════ ══════════════╬══════════════════════╬════════════ ══════╣
║阿拉伯║阿拉伯语 - 印度语数字║\ u0660║
╚══════════════════════════════════════════════════════════════════════════ ═════════════ = = code>

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));
    }
}

我原以为输出是这样的:

I was expecting the output to be something like:


0

123

٠
١٢٣

但是,输出如下:


0

123

0
123

这样做的主要目的是让JavaFX GUI显示阿拉伯数字而不是英文数字,​​因为它使用默认的语言环境(我可以用<$ c设置它) $ c> 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?

推荐答案

是的,我做到了!阅读 区域设置后仔细阅读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语言环境) / language extension):


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天全站免登陆