检查语言环境 - 容易吗?

发布于 2024-11-29 01:04:15 字数 54 浏览 0 评论 0原文

如何检查我的 JVM 支持多少种语言环境?有什么方法可以做到这一点还是其他什么?
谢谢

How to check how many locales are supported by my JVM? Is there a some method to do it or something else?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱花细雨 2024-12-06 01:04:15

您可以使用 Locale.getAvailableLocales(); 方法检查区域设置。

代码

import java.util.Arrays;
import java.util.Locale;

import javax.swing.table.*;
import javax.swing.*;

class ShowLocales {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                Locale[] locales = Locale.getAvailableLocales();
                LocaleTableModel tableModel = new LocaleTableModel(locales);
                JTable localeTable = new JTable(tableModel);
                localeTable.setAutoCreateRowSorter(true);
                JOptionPane.showMessageDialog(
                    null, 
                    new JScrollPane(localeTable));
            }
        });
    }
}

class LocaleTableModel extends AbstractTableModel {

    private Locale[] locales;

    LocaleTableModel(Locale[] locales) {
        this.locales = locales;
    }

    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Code";
            case 1:
                return "Language";
            case 2:
                return "Country";
            case 3:
                return "Variant";
        }
        return "";
    }

    public Object getValueAt(int row, int column) {
        switch (column) {
            case 0:
                return locales[row].toString();
            case 1:
                return locales[row].getDisplayLanguage();
            case 2:
                return locales[row].getDisplayCountry();
            case 3:
                return locales[row].getDisplayVariant();
        }
        return null;
    }

    public int getRowCount() {
        return locales.length;
    }

    public int getColumnCount() {
        return 4;
    }
}

E.G.

JVM 已知的一些语言环境

You can check the locales by using Locale.getAvailableLocales(); method.

Code

import java.util.Arrays;
import java.util.Locale;

import javax.swing.table.*;
import javax.swing.*;

class ShowLocales {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                Locale[] locales = Locale.getAvailableLocales();
                LocaleTableModel tableModel = new LocaleTableModel(locales);
                JTable localeTable = new JTable(tableModel);
                localeTable.setAutoCreateRowSorter(true);
                JOptionPane.showMessageDialog(
                    null, 
                    new JScrollPane(localeTable));
            }
        });
    }
}

class LocaleTableModel extends AbstractTableModel {

    private Locale[] locales;

    LocaleTableModel(Locale[] locales) {
        this.locales = locales;
    }

    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Code";
            case 1:
                return "Language";
            case 2:
                return "Country";
            case 3:
                return "Variant";
        }
        return "";
    }

    public Object getValueAt(int row, int column) {
        switch (column) {
            case 0:
                return locales[row].toString();
            case 1:
                return locales[row].getDisplayLanguage();
            case 2:
                return locales[row].getDisplayCountry();
            case 3:
                return locales[row].getDisplayVariant();
        }
        return null;
    }

    public int getRowCount() {
        return locales.length;
    }

    public int getColumnCount() {
        return 4;
    }
}

E.G.

Some locales known to JVM

若沐 2024-12-06 01:04:15

请参阅: http://java.sun.com/developer/technicalArticles/J2SE/locale /

Java 平台支持哪些语言环境?您可以创建任何您想要的区域设置。但是,您的运行时环境可能不完全支持您创建的Locale对象。

如果您想知道可以创建哪些Locale对象,答案很简单:您可以创建您想要的任何区域设置。构造函数不会抱怨非 ISO 参数。然而,对这个问题的更有用的重述是:类库为哪些语言环境提供更广泛的信息?图书馆可以为哪些区域设置提供校对、时间、日期、数字和货币信息?另外,您可能会问您的运行时环境支持哪些脚本或编写系统。

See: http://java.sun.com/developer/technicalArticles/J2SE/locale/

What locales does the Java platform support? You can create any locale that you'd like. However, your runtime environment may not fully support the Locale object you create.

If you want to know what Locale objects you can create, the answer is simple: You can create any locale you'd like. The constructors won't complain about non-ISO arguments. However, a more helpful restatement of the question is this: For which locales do the class libraries provide more extensive information? For which locales can the libraries provide collation, time, date, number, and currency information? Also, you might ask what scripts or writing systems your runtime environment supports.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文