Adobe 27510753 Scripting Guide - Page 69
Variable values in localized strings, Enabling automatic localization, de: Hallo Welt, Hallo Welt
UPC - 718659445294
View all Adobe 27510753 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 69 highlights
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features 61 For portions 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 details of the syntax, see the "Locale names" section. 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); To use automatic translation of localization objects, you must enable localization in your script with this statement: $.localize = true; The localize function always performs its translation, regardless of the setting of the $.localize variable. For example: msg = { en: "Yes", de: "Ja", fr: "Oui" }; //Only works if the $.localize=true alert (msg); //Always works, regardless of $.localize value alert ( localize (msg)); If you need to include variables in the localized strings, use the localize function.