次の記事では、Java における国際化の概要を説明します。国際化とは、アプリケーションに変更を加えることなく、複数の国、言語、通貨を自動的にサポートするような Web アプリケーションを作成するプロセスです。文字 I と N の間に 18 文字があるため、I18N とも呼ばれます。今日、ソフトウェアや Web サイトを設計する場合、世界的な市場は重要な要素です。世界市場向けのソフトウェア アプリケーションの拡大が続く中、企業は現地の地域や言語のユーザーを魅了する製品を作成する必要があります。
無料ソフトウェア開発コースを始めましょう
Web 開発、プログラミング言語、ソフトウェア テスト、その他
国際市場向けのソフトウェアに取り組んでいる開発者は、それぞれの文化の習慣と違いを認識する必要があります。言語、句読点、通貨、日付、時刻、数字、タイムゾーンはすべて違いの例です。最初の文字「L」と最後の文字「N」の間に 10 文字があるため、ローカリゼーションは I10N とも短縮されます。ローカリゼーションとは、アプリケーションを特定の言語と場所に合わせて調整できるように、ロケール固有のテキストとコンポーネントをアプリケーションに追加するプロセスです。
Java における国際化の構文
次のクラスを使用して国際化を実装できます:
- ロケール
- 数値形式
- 日付形式
1.ロケール
Locale オブジェクトは、地理的位置または言語を表すために使用できます。 java.util パッケージには Locale クラスが含まれています。
Locale クラスのコンストラクター:
Locale l = new Locale(String language);
Locale l = new Locale(String language, String country);
ロケールクラスの定数:
一部の Locale 定数は Locale クラスですでに宣言されています。
これらの定数は直接使用できます。いくつかの定数を以下に示します。
- ロケール。イギリス
- ロケール.ITALY
- ロケール.US
ロケールクラスの関数:
- pubic static Locale getDefault(): このメソッドは、現在のロケールのインスタンスを取得するために使用されます。
- public static Locale[] getAvailableLocales(): このメソッドは、現在のロケールの配列を取得するために使用されます。
- public String getDisplayLanguage(Locale l): このメソッドは、渡されたロケール オブジェクトの言語名を取得するために使用されます。
- public String getDisplayVariant(Locale l): このメソッドは、渡されたロケール オブジェクトのバリアント コードを取得するために使用されます。
- public String getDisplay Country(Locale l): このメソッドは、渡されたロケール オブジェクトの国名を取得するために使用されます。
- public static getISO3Language(): このメソッドは、ロケールの現在の言語コードの 3 文字の省略形を取得するために使用されます。
- public static getISO3 Country(): このメソッドは、ロケールの現在の国の 3 文字の略称を取得するために使用されます。
2.数値形式
NumberFormat クラスを使用すると、特定のロケールに従って数値を書式設定できます。 NumberFormat クラスは java.Text パッケージに存在し、抽象クラスであるため、そのコンストラクターを使用してオブジェクトを作成できません。
ロケールクラスの関数:
- public static NumberFormat getInstance(): このメソッドは、デフォルトの Locale のオブジェクトを取得するために使用されます。
- public static NumberFormat getInstance(Locale l): このメソッドは、渡された Locale オブジェクトのオブジェクトを取得するために使用されます。
- public static NumberFormat getCurrencyInstance(): このメソッドは、特定の通貨で表示するデフォルト ロケールのオブジェクトを取得するために使用されます。
- public static format(long l):このメソッドは、渡された数値をロケール オブジェクトに変換するために使用されます。
3.日付形式
日付の形式は場所によって異なるため、日付形式を国際化しています。 DateFromat クラスを使用すると、指定されたロケールに従って日付をフォーマットできます。 DateFormat は java.text パッケージの抽象クラスです。
ロケールクラスの定数:
一部の DateFormat 定数は、DateFormat クラスですでに宣言されています。
これらの定数は直接使用できます。いくつかの定数を以下に示します。
- DateFormat.LONG
- DateFormat.MINUTE_FIELD
- DateFormat.MINUTE_FIELD
DateFormat クラスの関数:
- final String format(Date date): This method converts and returns the specified Date object into a string.
- static final DateFormat getInstance(): This method is used to gets a date-time formatter with a short formatting style for date and time.
- static Locale[] getAvailableLocales(): This method is used to gets an array of present locales.
- static final DateFormat getTimeInstance(): This method is used to gets time formatter with default formatting style for the default locale.
- static final DateFormat getTimeInstance(int style): This method is used to gets time formatter with the specified formatting style for the default locale.
- static final DateFormat getTimeInstance(int style, Locale locale): This method is used to gets time formatter with the specified formatting style for the given locale.
- TimeZone getTimeZone(): This method is used to gets an object of TimeZone for this DateFormat instance.
- static final DateFormat getDateInstance(): This method is used to gets date formatter with default formatting style for the default locale.
- static final DateFormat getDateInstance(int style): This method is used to gets date formatter with the specified formatting style for the default locale.
- static final DateFormat getDateInstance(int style, Locale locale): This method is used to gets date formatter with the specified formatting style for the given locale.
- static final DateFormat getDateTimeInstance(): This method is used to gets date or time formatter with default formatting style for the default locale.
- NumberFormat getNumberFormat(): This method is used to gets an object of NumberFormat for this DateFormat instance.
- Calendar getCalendar(): This method is used to gets an object of the Calendar for this DateFormat instance.
Examples of Internationalization in Java
Given below are the examples mentioned:
Example #1
Example for the internationalization in Java to create different country locale.
Code:
// The program can be tested in Eclipse IDE, JAVA 11 package jex; import java.util.Locale; public class ex { public static void main(String[] args) { Locale[] locales = { new Locale("en", "US"), new Locale("it", "IT"), new Locale("es", "ES") }; for (int l=0; l <p><strong>Output:</strong></p> <p><img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/172500369926024.jpg?x-oss-process=image/resize,p_40" class="lazy" alt="Java の国際化" ></p> <p>As in the above program, the Locale class objects are created and store in the array. Next, used the for loop to iterate each locale object and display its name and its language, as we can see in the above output.</p> <h4 id="Example">Example #2</h4> <p>Example for the internationalization in Java to show the number in different formats for the different countries.</p> <p><strong>Code:</strong></p> <pre class="brush:php;toolbar:false">// The program can be tested in Eclipse IDE, JAVA 11 package jex; import java.util.*; import java.text.*; public class ex { public static void main (String[]args) { double n = 45273.8956; NumberFormat f1 = NumberFormat.getInstance (Locale.US); NumberFormat f2 = NumberFormat.getInstance (Locale.ITALY); NumberFormat f3 = NumberFormat.getInstance (Locale.CHINA); System.out.println ("The number format in US is :" + f1.format (n)); System.out.println ("The number format in ITALY is:" + f2.format (n)); System.out.println ("The number format in CHINA is :" + f3.format (n)); } }
Output:
As in the above program, three different NumberFormat class objects are created using the Locale class. Next, using the format() method of the NumberFormat class, the given number is printing in the specific format of the country, as we can see in the above output.
Example #3
Example for the internationalization in Java to show the date in different formats for the different countries.
Code:
// The program can be tested in Eclipse IDE, JAVA 11 package jex; import java.text.DateFormat; import java.util.Date; import java.util.Locale; public class ex { public static void main (String[]args) { DateFormat d1 = DateFormat.getDateInstance (0, Locale.US); DateFormat d2 = DateFormat.getDateInstance (0, Locale.ITALY); DateFormat d3 = DateFormat.getDateInstance (0, Locale.CHINA); System.out.println ("The date format in US is :" + d1.format (new Date ())); System.out.println ("The date format in ITALY is : " + d2.format (new Date ())); System.out.println ("The date format in CHINA is : " + d3.format (new Date ())); } }
Output:
As in the above program, three different DateFormat class objects are created using the Locale class. Next, using the format() method of the DateFormat class, the return date of the Date() method is printing in the specific format of the country, as we can see in the above output.
Conclusion
Internationalization is also called I18N because there are 18 characters between the letters I and N. It is the process of creating web applications in such a way that they automatically support several countries, languages, and currencies without requiring any changes to the application.
以上がJava の国際化の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于结构化数据处理开源库SPL的相关问题,下面就一起来看一下java下理想的结构化数据处理类库,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于PriorityQueue优先级队列的相关知识,Java集合框架中提供了PriorityQueue和PriorityBlockingQueue两种类型的优先级队列,PriorityQueue是线程不安全的,PriorityBlockingQueue是线程安全的,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于java锁的相关问题,包括了独占锁、悲观锁、乐观锁、共享锁等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于多线程的相关问题,包括了线程安装、线程加锁与线程不安全的原因、线程安全的标准类等等内容,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于枚举的相关问题,包括了枚举的基本操作、集合类对枚举的支持等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Java的相关知识,其中主要介绍了关于关键字中this和super的相关问题,以及他们的一些区别,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于平衡二叉树(AVL树)的相关知识,AVL树本质上是带了平衡功能的二叉查找树,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Java的相关知识,其中主要整理了Stream流的概念和使用的相关问题,包括了Stream流的概念、Stream流的获取、Stream流的常用方法等等内容,下面一起来看一下,希望对大家有帮助。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

ドリームウィーバー CS6
ビジュアル Web 開発ツール

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

メモ帳++7.3.1
使いやすく無料のコードエディター

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

ホットトピック



