Difference between revisions of "Custom Labels For Developers"
From LongJump Support Wiki
imported>Aeric |
imported>Aeric |
||
Line 16: | Line 16: | ||
: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: |
Revision as of 19:19, 12 July 2011
Accessing a Custom Label in JAVA
The translateToken API accesses a Custom Label (a message) defined in the Translation Workbench.
- Syntax
String result = Functions.translateToken(String key) String result = Functions.translateToken(String key, String [] args)
- 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.
String [] args = {"nice", "walk"}; String msg = Functions.translateToken("#custom.go_msg", args)); // ==> "It's a nice day for a walk."
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:
-
Created from category name, followed by '.' and token name
- Syntax
#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
- Components
- 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 default language (selected via Company Information).
- 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
<%@ taglib uri="/LJTagLib" prefix="lj" %> <lj:message key="#{category}.{token}" arg1="Julia" arg2="Jones"/>
- Example
Assume the following item is specified in the Translation Workbench:
Category webtab Token message Message Requester Name: {1}, {0}
Then this code:
<%@ taglib uri="/LJTagLib" prefix="lj" %> <html> <head> <title>Customer Details</title> </head> <body> <h1>Customer Details</h1> <p>All the details</p> <lj:message key="#webtab.message" arg1="Julia" arg2="Jones"/> </body> </html>
Causes this text to be inserted into the HTML:
- Requester Name: Jones, Julia