
CHAPTER 8: ExtendScript Tools and Features Localizing ExtendScript strings 224
Localizing ExtendScript strings
Localization is the process of translating and otherwise manipulating an interface so it looks as if it were
originally designed for a particular language. ExtendScript enables you to localize the strings in your
script’s user interface. The language is chosen by the application at startup, according to the current locale
provided by the operating system.
For parts of your user interface that are displayed on the screen, you may want to localize the displayed
text. You can localize any string explicitly, using the Global localize function
, which takes as its argument a
localization object containing the localized versions of a string.
A localization object is a JavaScript object literal whose property names are locale names and whose
property values are the localized text strings. The locale name is a standard language code with an
optional region identifier. For syntax details, see Locale names
.
In this example, a
msg object contains localized text strings for two locales. This object supplies the text for
an alert dialog.
msg = { en: "Hello, world", de: "Hallo Welt" };
alert (msg);
ExtendScript matches the current locale and platform to one of the object’s properties and uses the
associated string. On a German system, for example, the property
de: "Hallo Welt" is converted to the
string
"Hallo Welt".
Variable values in localized strings
Some localization strings need to contain additional data whose position and order may change according
to the language used.
You can include variables in the string values of the localization object, in the form
%n. The variables are
replaced in the returned string with the results of JavaScript expressions, supplied as additional arguments
to the
localize function. The variable %1 corresponds to the first additional argument, %2 to the second,
and so on.
Because the replacement occurs after the localized string is chosen, the variable values are inserted in the
correct position. For example:
today = {
en: "Today is %1/%2.",
de: "Heute ist der %2.%1."
};
d = new Date();
alert (localize (today, d.getMonth()+1, d.getDate()));
Enabling automatic localization
ExtendScript offers an automatic localization feature. When it is enabled, you can specify a localization
object directly as the value of any property that takes a localizable string, without using the
localize
function. For example:
msg = { en: "Yes", de: "Ja", fr: "Oui" };
alert (msg);
Komentáře k této Příručce