C H A P T E R 2 0
Localizing Newton Applications
Using the Localization Features of the Newton
20-5
A frames path the compiler uses to find the alternative object when the
Language setting in the Project Settings dialog box is for anything other than
English. You should avoid having reserved words in the path--refer to Appendix
A of The NewtonScript Programming Language for a complete list of reserved
words in NewtonScript.
If you display a message while searching for an object, for example, you can set up
the message for any language by wrapping the string in the
LocObj
function:
msg := LocObj("Searching for ^0...", 'find.searchfor)
When an English-language version of the application is compiled, the
LocObj
function simply returns its first argument; this implementation helps keep code
readable by allowing you to use English strings in your code. For non-English
versions of the application, the
LocObj
function uses the value of the
language
slot in NTK Package Settings and the path expression passed as its second
argument to return the appropriate object from the localization frame.
As another example, an application that is not localized might provide user feedback
by passing the string
"Not found."
to the
SetStatus
function, as in the
following code fragment:
:SetStatus("Not found.");
The localized version of the same code uses the
LocObj
function to return a path
expression based on the
'find.nope
argument and the language for which the
application is compiled. The
SetStatus
function then uses this path expression
to reference the localized string. Because the
LocObj
function returns this path
expression as its result, the argument to
SetStatus
can be "wrapped" in a call to
the
LocObj
function, as in the following line of code:
:SetStatus( LocObj("Not found", 'find.nope) );
The object passed to the
LocObj
method doesn't have to be a string; it can be an
array or an immediate value.
The path expression that references the object must be unique across the entire
system. Thus, to avoid name collisions, it's recommended that you use additional
naming levels based on your application symbol; for example,
'
myApp.find.nope
introduces a third naming level to the path expression.
Use ParamStr Rather Than "&" and "&&" Concatenation
20
While it is often convenient to use the ampersand string concatenators
&
and
&&
,
the
ParamStr
function provides a much more flexible and powerful way to
parameterize the construction of strings, which helps you customize your strings
for different languages by, for example, varying word order.