The Jakarta Project < Velocity Tools - Struts >

Velocity Tools

VelocityStruts

VelocityStruts Tools

その他のサブプロジェクト

MessageTool リファレンスドキュメント
       

The MessageTool is used to render internationalized message strings. Source of the strings are the message resource bundles of the Struts framework. The following methods operate on these message resources.

MessageTool は国際化されたメッセージの表示に使用します。 文字列は Struts フレームワークのメッセージリソースバンドルから取得されます。 メッセージリソースを操作する以下のメソッドが利用できます。

Class
 org.apache.velocity.tools.struts.MessageTool
Name
 $text (Velocityコンテキスト内での推奨名)
Toolbox設定例
 
<tool>
  <key>text</key>
  <scope>request</scope>
  <class>org.apache.velocity.tools.struts.MessageTool</class>
</tool>
作者
 Gabriel Sidler
Method Overview
get() Looks up and returns the localized message for the specified key.
exists() Checks if a message string for a specified message key exists for the user's locale.
getLocale() Returns the user's locale. If a locale is not found, the default locale is returned (deprecated - will be removed in VelocityTools 1.2).
Method Overview
get() 指定されたキーに対応する地域化されたメッセージを検索し返却します。
exists() ユーザのロカールで、指定されたキーに対するメッセージが存在するかどうかをチェックします。
getLocale() ユーザのロカールを返却します。 ロカールが見つからなかった場合、デフォルトロカールが返却されます。 (推奨されていません。 - VelocityTools 1.2では削除されます。)
get()
       

Looks up and returns the localized message for the specified key.

String get(String key)

String get(String key, String bundle)

String get(String key, Object args[])

String get(String key, String bundle, Object args[])

String get(String key, List args)

String get(String key, String bundle, List args)

Parameters
key
Message key.
bundle
The (non-default) message-resources bundle that holds the message.
args
Replacement parameters for this message. Typically an array of Strings or a List of Strings (but any Object with a reasonable toString() method can be used).
Returns
The localized message for the specified key. Returns null if no message exists for the key passed.
See Also
Struts user's guide on Internationalized Messages.

The user's locale is consulted to determine the language of the message. The third, fourth, fifth and sixth signatures take a list of up to five replacement parameters. The third and fourth signatures are provided for compatibility with existing applications. The fifth and sixth signatures are Velocity-friendlier.

Assuming that the message resource files contain the following messages:

title=Welcome to Velocity for Struts
test=This message has five replacement parameters: {0}, {1}, {2}, {3}, {4}

then the following Velocity script:

$text.get("title")
$text.title
$text.get("test", ["bear", "wolf", "tiger"])

produces this output:

Welcome to Velocity for Struts
Welcome to Velocity for Struts
This message has five replacement parameters: bear, wolf, tiger, {3}, {4}

指定されたキーに対応する地域化されたメッセージを検索し返却します。

String get(String key)

String get(String key, String bundle)

String get(String key, Object args[])

String get(String key, String bundle, Object args[])

String get(String key, List args)

String get(String key, String bundle, List args)

Parameters
key
メッセージのキー。
bundle
メッセージを保持する(デフォルトではない)メッセージリソースバンドル。
args
メッセージの置換パラメータ。 通常は String の配列、もしくは String を格納した List (String以外でも、適切な toString() メソッドが実装されているオブジェクトなら利用可能) 。
Returns
指定されたキーに対応する地域化されたメッセージ。 キーに対応するメッセージが存在しない場合には null を返却します。
See Also
Struts ユーザガイドの Internationalized Messages

使用するメッセージの言語を決定するため、ユーザのロカールが参照されます。 3つめ、4つめ、5つめ、6つめのメソッドシグニチャは5つまで置換パラメータを受け取ることが出来ます。 3つめ、4つめのメソッドシグニチャは、既存のアプリケーションとの互換性を提供します。 5つめ、6つめのメソッドシグニチャはよりVelocityで使いやすいものです。

メッセージリソースファイルが以下のメッセージを含んでいる場合:

title=Velocity for Strutsへようこそ
test=このメッセージは5つの置換パラメータがあります: {0}, {1}, {2}, {3}, {4}

以下の Velocity スクリプトは:

$text.get("title")
$text.title
$text.get("test", ["bear", "wolf", "tiger"])

このように出力されます:

Velocity for Strutsへようこそ
Velocity for Strutsへようこそ
このメッセージは5つの置換パラメータがあります: bear, wolf, tiger, {3}, {4}

exists()
       

Checks if a message string for a specified message key exists for the user's locale.

boolean exists(String key)

boolean exists(String key, String bundle)

Parameters
key
Message key.
bundle
The (non-default) message-resources bundle that holds the message.
Returns
true if a message string for the specified message key exists for the user's locale. false otherwise.
$text.exists("title")

ユーザのロカールで、指定されたキーに対するメッセージが存在するかどうかをチェックします。

boolean exists(String key)

boolean exists(String key, String bundle)

Parameters
key
メッセージのキー。
bundle
メッセージを保持する(デフォルトではない)メッセージリソースバンドル。
Returns
ユーザのロカールで、メッセージのキーが存在する場合 true 。そうではない場合、 false
$text.exists("title")

getLocale()
       

Returns the user's locale. If a locale is not found, the default locale is returned (deprecated - will be removed in VelocityTools 1.2).

Locale getLocale()

Returns
An instance of class java.util.Locale.
$text.getLocale()
$text.locale
$text.getLocale().getDisplayLanguage()

produces:

en
en
English

The returned object of class Locale is automatically rendered by Velocity by calling its toString() method. The third example calls method getDisplayLanguage() of class Locale


ユーザのロカールを返却します。 ロカールが見つからなかった場合、デフォルトロカールが返却されます。 (推奨されていません。 - VelocityTools 1.2では削除されます。)

Locale getLocale()

Returns
java.util.Locale クラスのインスタンス。
$text.getLocale()
$text.locale
$text.getLocale().getDisplayLanguage()

は次を生成します:

ja
ja
日本語

返却される Locale クラスのオブジェクトは、 Velocity により toString() メソッドが呼び出され、自動的にレンダリングされます。 3つめの例は Locale クラスの getDisplayLanguage() を呼び出しています。



[訳注: この文書は Shinobu Kawai 木村 貴由 が翻訳しました。 日本語訳に対するコメントがあれば、report@jajakarta.orgに送って下さい。]
Copyright © 1999-2003, Apache Software Foundation