You set up a Rich UI properties library
(RUIPropertiesLibrary stereotype)
to retrieve displayable text from external files instead of hard-coding
the text in your Rich UI application. For more information, see "Use
of properties files for displayable text." You can also use an implicit
function in a Rich UI properties library to substitute values in any
string.
Here is an example of a Rich
UI properties library:
Library myLibrary type RUIPropertiesLibrary {propertiesFile="myFile")
entryForInputRequired STRING;
entryForOthers STRING;
someText STRING;
end
Any value that is assigned directly in a declaration
(for example, someText
String = "Click!";) has no effect. Every runtime value comes
from an external file, with one exception: if the file does not include
a particular entry (for example, if the file does not include an entry
for someText), the value at run time is the string
equivalent of the variable name (for example, "someText").
Property
propertiesFile
The
propertiesFile property
refers to the root name of the file. The file (or files, if multiple
translations are available) must reside directly in the WebContent/properties
directory of the project. Do not include any of the following details
in the root name:
- Path information such as "properties/myFile"
- Hyphens
- Translation-specific information such "en_US"
- The file extension, which is necessarily .properties
The default value for propertiesFile is
the name of the library; in this case, "myLibrary".
Function getMessage
Every RUI properties
library implicitly includes the
getMessage function,
which you can use to add inserts when you select a message from the
properties file or from a string in your code. For example, the following
message in a properties file requires two inserts:
someText=Promote {0} in the {1} department
This
example code writes the string "Promote Jeff in the Sales department"
to a label:
employeeName, departmentName String;
employeeName = "Jeff";
departmentName = "Sales";
myLabel TextLabel {text =
myLibrary.getMessage(myLibrary.someText, [employeeName, departmentName]);
An
alternative invocation has the same effect as the previous one, but
does not access a properties file:
myMessage STRING = "Promote {0} in the {1} department";
myLabel TextLabel {text =
myLibrary.getMessage(myMessage, [employeeName, departmentName]);
Here
is the function signature:
getMessage(baseMessage STRING in, inserts STRING[] in) returns (fullMessage STRING);
- baseMessage
- A string
or a field in an RUI properties library.
- inserts
- An array of strings, with the first element providing an insert
for the placeholder {0}, the second providing an insert for the placeholder
{1}, and so on.
- fullMessage
- The base message with as many placeholders resolved as possible
The inserts are in ascending order, starting
at 0, and the placeholders in the message can be in any order and
do not need to be in sequence. If an insert does not match a placeholder
by number, the insert is not used. If a placeholder is unresolved,
the placeholder itself is in the returned message. For example, the
returned message is "Promote Jeff in the {1} department" in the following
case:
employeeName STRING = "Jeff";
myMessage STRING = "Promote {0} in the {1} department";
myLabel TextLabel {text =
myLibrary.getMessage(myMessage, [employeeName]);
You
cannot use the getMessage function when
you override a validation or formatting message. You cannot pass inserts
to such a message.