国際化のために.propertiesファイルなどのファイルを作成する場合、EclipseにはUnicodeエディターが組み込まれています。[実行構成共通]タブで有効にした場合。Console Encoding => Otherで、UTF-8を選択します。その後、コンソールは選択した言語でそれを読み取ります。それでも、ファイルにUnicode文字を指定するか、文字をUNICODEに変換する必要があります。
さて、あなたの言語の文字がヒンディー語でここに言う場合विमलकृष्णा(一部のエディターでこれらの文字が必要です)、Eclipse .propertiesファイルに貼り付けるだけで、自動的に\ u0935 \ u093F \ u092E \ u0932\u0915に変換されます\ u0943 \ u0937 \ u094D \ u0923\u093E。
上記の文字列は、コンソールでविमलकृष्णाとして解釈されるようになります。
例:ステップ1 Springでは、「locale」という名前のファイルの下のクラスパス(たとえば、src / main / resources内)に次の名前のファイルが必要です。
messages_hi_IN.properties(ヒンディー語用)とコンテンツ
user.name=\u0935\u093F\u092E\u0932 \u0915\u0943\u0937\u094D\u0923\u093E, age : {0}, URL : {1}
messages_en_US.properties(英語の場合)とコンテンツ
user.name=vimal krishna, age : {0}, URL : {1}
ステップ2:
あなたのメインアプリケーション:
package com.vimal.common;
import java.text.SimpleDateFormat;
import java.util.Locale;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App {
public static void main(String[] args) {
ApplicationContext context
= new ClassPathXmlApplicationContext("com/vimal/common/beans.xml");
String name = context.getMessage("user.name", new Object[] { 45,"http://www.vkrishna.com" }, Locale.US);
System.out.println("User name (English) : " + name);
String nameHindi = context.getMessage("user.name", new Object[] {45, "http://www.vkrishna.com" }, new Locale("hi", "IN"));
System.out.println("User name (Hindi) : " + nameHindi);
}
}
ステップ3:構成ファイル
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>locale\messages</value>
</property>
</bean>
ここで、 localeは、messages_hi_IN.propertiesファイルが配置されているクラスパス(Mavenプロジェクトがeclipseによって作成されている場合)上にあるsrc / main/resources内のフォルダーです。locale \ messagesは、このメッセージ_hi_IN.propertiesファイルを参照します。hi_INを追加することは、ヒンディー語のロケール検出の鍵となります。これで、メインアプリケーションで、locale.USなどのEclipseで定義されていないため、新しいLocale( "hi"、 "IN")が作成されていることがわかります。
結果は次のようになります:
Dez 31, 2014 12:19:12 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFORMATION: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5594a1b5: defining beans [messageSource]; root of factory hierarchy
Customer name (English) : vimal krishna, age : 45, URL : http://www.vkrishna.com
Customer name (Hindi) : विमल कृष्णा, age : ४५, URL : http://www.vkrishna.com
リンクを作り直しました...