Adobe 27510753 Scripting Guide - Page 70

Locale names, Testing localization, en _ US, en _ US _ Win, locale

Page 70 highlights

62 Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide Locale names A locale name is an identifier string in that contains an ISO 639 language specifier, and optionally an ISO 3166 region specifier, separated from the language specifier by an underscore. l The ISO 639 standard defines a set of two-letter language abbreviations, such as en for English and de for German. l The ISO 3166 standard defines a region code, another two-letter identifier, which you can optionally ap- pend to the language identifier with an underscore. For example, en _ US identifies U.S. English, while en _ GB identifies British English. This object defines one message for British English, another for all other flavors of English, and another for all flavors of German: message = { en_GB: "Please select a colour." en: "Please select a colour." de: "Bitte wählen Sie eine Farbe." }; If you need to specify different messages for different platforms, you can append another underline character and the name of the platform, one of Win, Mac , or Unix. For example, this objects defines one message in British English to be displayed in Mac OS, one for all other flavors of English in Mac OS, and one for all other flavors of English on all other platforms: pressMsg = { en_GB_Mac: "Press Cmd-S to select a colour.", en_Mac: "Press Cmd-S to select a color.", en: "Press Ctrl-S to select a color." }; All of these identifiers are case sensitive. For example, EN _ US is not valid. ➤ How locale names are resolved 1. ExtendScript gets the hosting application's locale; for example, en _ US. 2. It appends the platform identifier; for example, en _ US _ Win. 3. It looks for a matching property, and if found, returns the value string. 4. If not found, it removes the platform identifier (for example, en _ US) and retries. 5. If not found, it removes the region identifier (for example, en) and retries. 6. If not found, it tries the identifier en (that is, the default language is English). 7. If not found, it returns the entire localizer object. Testing localization ExtendScript stores the current locale in the variable $.locale. This variable is updated whenever the locale of the hosting application changes. To test your localized strings, you can temporarily reset the locale. To restore the original behavior, set the variable to null, false, 0, or the empty string. An example: $.locale = "ru"; // try your Russian messages $.locale = null; // restore to the locale of the app

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184

62
Using ExtendScript Tools and Features
Adobe InDesign CS2 Scripting Guide
Locale names
A locale name is an identifier string in that contains an ISO 639 language specifier, and optionally an ISO 3166
region specifier, separated from the language specifier by an underscore.
The ISO 639 standard defines a set of two-letter language abbreviations, such as
en
for English and
de
for
German.
The ISO 3166 standard defines a region code, another two-letter identifier, which you can optionally ap-
pend to the language identifier with an underscore. For example,
en _ US
identifies U.S. English, while
en _ GB
identifies British English.
This object defines one message for British English, another for all other flavors of English, and another for all
flavors of German:
message = {
en_GB: "Please select a colour."
en: "Please select a colour."
de: "Bitte wählen Sie eine Farbe."
};
If you need to specify different messages for different platforms, you can append another underline character
and the name of the platform, one of
Win
,
Mac
, or
Unix
. For example, this objects defines one message in
British English to be displayed in Mac OS, one for all other flavors of English in Mac OS, and one for all other
flavors of English on all other platforms:
pressMsg = {
en_GB_Mac: "Press Cmd-S to select a colour.",
en_Mac: "Press Cmd-S to select a color.",
en: "Press Ctrl-S to select a color."
};
All of these identifiers are case sensitive. For example,
EN _ US
is not valid.
How locale names are resolved
1. ExtendScript gets the hosting application’s locale; for example,
en _ US
.
2. It appends the platform identifier; for example,
en _ US _ Win
.
3. It looks for a matching property, and if found, returns the value string.
4. If not found, it removes the platform identifier (for example,
en _ US
) and retries
.
5. If not found, it removes the region identifier (for example,
en
) and retries
.
6. If not found, it tries the identifier
en
(that is, the default language is English).
7. If not found, it returns the entire localizer object.
Testing localization
ExtendScript stores the current locale in the variable
$.locale
. This variable is updated whenever the locale
of the hosting application changes.
To test your localized strings, you can temporarily reset the locale. To restore the original behavior, set the
variable to
null
,
false
, 0, or the empty string. An example:
$.locale = "ru"; // try your Russian messages
$.locale = null; // restore to the locale of the app
l
l