Difference between revisions of "Custom Labels For Developers"
imported>Aeric |
imported>Aeric |
||
(4 intermediate revisions by the same user not shown) | |||
Line 10: | Line 10: | ||
====Creating a Key==== | ====Creating a Key==== | ||
To access a Custom Label in HTML, you create a ''key'', using the same format as Template Variables: | To access a Custom Label in HTML, you create a ''key'', using the same format as Template Variables: | ||
<blockquote> | |||
{{:key}} | {{:key}} | ||
</blockquote> | |||
:where | :where | ||
::;<tt>categoryname</tt>:Name of the Category | ::;<tt>categoryname</tt>:Name of the Category | ||
::;<tt> | ::;<tt>tokenname</tt>:Name of the Token | ||
;Example: | ;Example: | ||
Line 36: | Line 36: | ||
::*HTML | ::*HTML | ||
::*Raw HTML | ::*Raw HTML | ||
;Example: | ;Example: | ||
Line 60: | Line 58: | ||
====Using Message Tags==== | ====Using Message Tags==== | ||
Message Tags support multiple languages, using Custom Labels created in the Translation Workbench. | Message Tags support multiple languages, using Custom Labels created in the Translation Workbench. | ||
:* When a message tag is implemented, the message appears in the | :* When a message tag is implemented, the message appears in the user's selected language. | ||
:* Message tags are part of the | :* Message tags are part of the platform Tag library | ||
::* The | ::* The platform Tag Library is a [http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPTags.html Java Custom Tag Library] | ||
:* If the <tt>key</tt> is not defined in the [[Translation Workbench]], the <tt>key</tt> defined in the call will be displayed. | :* If the <tt>key</tt> is not defined in the [[Translation Workbench]], the <tt>key</tt> defined in the call will be displayed. | ||
Latest revision as of 20:46, 18 February 2014
Accessing a Custom Label in JAVA
The translateToken API accesses a Custom Label (a message) defined in the Translation Workbench.
- Syntax
- <syntaxhighlight lang="java" enclose="div">
String result = Functions.translateToken(String key) String result = Functions.translateToken(String key, String [] args) </syntaxhighlight>
- Parameters
-
- key
- The category and token (index key) for the message to retrieve, in the form: "#category.token_name".
- args
- An array of string-arguments to be substituted into the message, in the locations defined by the message format.
- Returns
- A string containing the selected message in the user's currently active language, with specified arguments substituted.
- Example
- In this example, go_msg is a Custom Label in the Translation Workbench created in the "custom" category, where the translation in the user's current language is "It's a {1} day for a {2}." Supplying the arguments then allows for variations on the message.
- <syntaxhighlight lang="java" enclose="div">
String [] args = {"nice", "walk"}; String msg = Functions.translateToken("#custom.go_msg", args));
// ==> "It's a nice day for a walk."
</syntaxhighlight>
Accessing a Custom Label in HTML
In HTML:
- The category and tokens defined in Custom Labels are used to construct a key.
- The key and related arguments are passed to a Message Tag, which returns a localized message.
Creating a Key
To access a Custom Label in HTML, you create a key, using the same format as Template Variables:
A category name, followed by '.' and a message or label identifier (a "token").
Example: #categoryname.tokenname
- where
- categoryname
- Name of the Category
- tokenname
- Name of the Token
- Example
For a category named webtab, create the following tokens:
- welcome_msg = Welcome to the {0}
- message = This application keeps track of your customer service requests quickly and easily
To create language labels using the custom label key, add arguments as follows:
- {#webtab.welcome_msg^ABC}
-
- Which displays in the UI as: Welcome to the ABC
- Considerations
- The carat (^) character is used to separate arguments passed to the function
- If the argument is missing ({#webtab.message}), the default message is displayed: This application keeps track of your customer service requests quickly and easily.
- Tokens are supported in:
- Web Tabs, using:
- HTML
- Raw HTML
- Example
<html> <head> <title></title> </head> <body> <h1>{#webtab.welcom_msg^ABC}</h1> <p>{#webtab.messge}</p> </body> </html>
Using Message Tags
Message Tags support multiple languages, using Custom Labels created in the Translation Workbench.
- When a message tag is implemented, the message appears in the user's selected language.
- Message tags are part of the platform Tag library
- The platform Tag Library is a Java Custom Tag Library
- If the key is not defined in the Translation Workbench, the key defined in the call will be displayed.
- Syntax
- <syntaxhighlight lang="java" enclose="div">
<%@ taglib uri="/LJTagLib" prefix="lj" %> <lj:message key="#{category}.{token}" arg1="Julia" arg2="Jones"/> </syntaxhighlight >
- Example
Assume the following item is specified in the Translation Workbench:
Category webtab Token message Message Requester Name: {1}, {0}
Then this code:
- <syntaxhighlight lang="java" enclose="div">
<%@ taglib uri="/LJTagLib" prefix="lj" %> <html>
<head> <title>Customer Details</title> </head> <body>
Customer Details
All the details
<lj:message key="#webtab.message" arg1="Julia" arg2="Jones"/> </body>
</html> </syntaxhighlight >
Causes this text to be inserted into the HTML:
- Requester Name: Jones, Julia