AgileApps Support Wiki Pre Release

Custom Labels For Developers

From AgileApps Support Wiki
Revision as of 22:55, 30 August 2012 by imported>Aeric

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:
  • 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
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