Creating a unique API per message
To generate a unique API per message, you must tag the <trans-unit>
elements
in the resource file with the extraData
attribute.
This attribute represents the name of a C++ macro or Perl subroutine.
Procedure
To generate a unique API per message, tag the
<trans-unit>
elements
in the resource file with the extraData
attribute.
Example
#define MY_TOOLKIT_MESSAGE_1(p0, p1) \
(::SPL::FormattableMessage2<RuntimeMessageFormatter,int64_t,int64_t>("MyToolkit", "MyResource", "en_US", "MSG0001", "Tuple "{0,number,integer}" value is "{1,number,integer}".", p0, p1))
You
can then use the MY_TOOLKIT_MESSAGE_1
macro in your SPL application as
follows:std::string str = MY_TOOLKIT_MESSAGE_1 (1, 2);
A comparable construct
is created in Perl that can be used with some existing helper functions to access the string. For
example:sub MY_TOOLKIT_MESSAGE_1($$)
{
my $defaultText = <<STOP;
English/default: Tuple "{0,number,integer}" value is "{1,number,integer}".
STOP
return SPL::Helper::SPLFormattedMessage($toolkitRoot, "MyToolkit", "MyResource", "en_US", "MSG0001", \$defaultText, @_);
}
my $string = MY_TOOLKIT_MESSAGE_1 (1, 2);
The
default text is part of the message API so that it can be used if the resource bundle cannot be
found at message load time. The default text is in the language in the XLIFF file that is specified
by the default
attribute of the <lang>
element. If the PE is
running in the locale that is specified by the default
attribute, then the default
text is used so that resource loading does not occur.