]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/intl.h
Add test for absence of events from wxSpinCtrlDouble ctor.
[wxWidgets.git] / interface / wx / intl.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: intl.h
e54c96f1 3// Purpose: interface of wxLocale
23324ae1 4// Author: wxWidgets team
526954c5 5// Licence: wxWindows licence
23324ae1
FM
6/////////////////////////////////////////////////////////////////////////////
7
f045c7f5
FM
8/**
9 This is the layout direction stored in wxLanguageInfo and returned by
51c0d02b
FM
10 wxApp::GetLayoutDirection(), wxWindow::GetLayoutDirection(),
11 wxDC::GetLayoutDirection() for RTL (right-to-left) languages support.
f045c7f5
FM
12*/
13enum wxLayoutDirection
14{
15 wxLayout_Default,
16 wxLayout_LeftToRight,
17 wxLayout_RightToLeft
18};
19
969daeea 20/**
f090e4ef 21 Encapsulates a ::wxLanguage identifier together with OS-specific information
fc79419b 22 related to that language.
1058f652
MB
23
24 @beginWxPerlOnly
25 In wxPerl @c Wx::LanguageInfo has only one method:
26 - Wx::LanguageInfo->new(language, canonicalName, WinLang, WinSubLang, Description)
27 @endWxPerlOnly
969daeea 28*/
639f8119 29struct wxLanguageInfo
969daeea 30{
89a7e1ff 31 /// ::wxLanguage id.
fc79419b
FM
32 /// It should be greater than @c wxLANGUAGE_USER_DEFINED when defining your own
33 /// language info structure.
969daeea 34 int Language;
9a6fda22
FM
35
36 /// Canonical name of the language, e.g. @c fr_FR.
37 wxString CanonicalName;
38
39 //@{
40 /**
41 Win32 language identifiers (LANG_xxxx, SUBLANG_xxxx).
42
43 @onlyfor{wxmsw}
44 */
45 wxUint32 WinLang, WinSublang;
46 //@}
47
48 /// Human-readable name of the language.
49 wxString Description;
50
51 /// The layout direction used for this language.
969daeea
FM
52 wxLayoutDirection LayoutDirection;
53
969daeea 54 /// Return the LCID corresponding to this language.
9a6fda22 55 /// @onlyfor{wxmsw}
969daeea 56 wxUint32 GetLCID() const;
969daeea
FM
57
58 /// Return the locale name corresponding to this language usable with
9a6fda22 59 /// @c setlocale() on the current system.
969daeea
FM
60 wxString GetLocaleName() const;
61};
62
63
fc79419b 64/**
89a7e1ff
VZ
65 The category of locale settings.
66
67 @see wxLocale::GetInfo()
fc79419b
FM
68*/
69enum wxLocaleCategory
70{
89a7e1ff 71 /// Number formatting.
fc79419b
FM
72 wxLOCALE_CAT_NUMBER,
73
89a7e1ff 74 /// Date/time formatting.
fc79419b
FM
75 wxLOCALE_CAT_DATE,
76
89a7e1ff 77 /// Monetary values formatting.
fc79419b
FM
78 wxLOCALE_CAT_MONEY,
79
89a7e1ff
VZ
80 /**
81 Default category for the wxLocaleInfo value.
82
83 This category can be used for values which only make sense for a single
84 category, e.g. wxLOCALE_SHORT_DATE_FMT which can only be used with
85 wxLOCALE_CAT_DATE. As this is the default value of the second parameter
86 of wxLocale::GetInfo(), wxLOCALE_CAT_DATE can be omitted when asking
87 for wxLOCALE_SHORT_DATE_FMT value.
88
89 @since 2.9.0
90 */
91 wxLOCALE_CAT_DEFAULT
fc79419b
FM
92};
93
94/**
95 The values understood by wxLocale::GetInfo().
ea0022d3
FM
96
97 Note that for the @c wxLOCALE_*_FMT constants (the date and time formats),
98 the strings returned by wxLocale::GetInfo() use strftime() or,
99 equivalently, wxDateTime::Format() format. If the relevant format
100 couldn't be determined, an empty string is returned -- there is no
101 fallback value so that the application could determine the best course
102 of actions itself in such case.
103
104 All of these values are used with @c wxLOCALE_CAT_DATE in wxLocale::GetInfo() or,
105 more typically, with @c wxLOCALE_CAT_DEFAULT as they only apply to a single category.
fc79419b
FM
106*/
107enum wxLocaleInfo
108{
89a7e1ff
VZ
109 /**
110 The thousands separator.
111
112 This value can be used with either wxLOCALE_CAT_NUMBER or
113 wxLOCALE_CAT_MONEY categories.
114 */
fc79419b
FM
115 wxLOCALE_THOUSANDS_SEP,
116
89a7e1ff
VZ
117 /**
118 The character used as decimal point.
119
120 This value can be used with either wxLOCALE_CAT_NUMBER or
121 wxLOCALE_CAT_MONEY categories.
122 */
123 wxLOCALE_DECIMAL_POINT,
124
89a7e1ff
VZ
125 /**
126 Short date format.
127
128 Notice that short and long date formats may be the same under POSIX
ea0022d3 129 systems currently but may, and typically are, different under MSW or OS X.
89a7e1ff
VZ
130
131 @since 2.9.0
132 */
133 wxLOCALE_SHORT_DATE_FMT,
134
135 /**
136 Long date format.
137
138 @since 2.9.0
139 */
140 wxLOCALE_LONG_DATE_FMT,
141
142 /**
143 Date and time format.
144
145 @since 2.9.0
146 */
147 wxLOCALE_DATE_TIME_FMT,
148
149 /**
150 Time format.
151
152 @since 2.9.0
153 */
154 wxLOCALE_TIME_FMT
fc79419b
FM
155};
156
157
23324ae1
FM
158/**
159 @class wxLocale
7c913512 160
23324ae1
FM
161 wxLocale class encapsulates all language-dependent settings and is a
162 generalization of the C locale concept.
7c913512 163
18e065b4
VS
164 In wxWidgets this class manages current locale. It also initializes and
165 activates wxTranslations object that manages message catalogs.
7c913512 166
969daeea
FM
167 For a list of the supported languages, please see ::wxLanguage enum values.
168 These constants may be used to specify the language in wxLocale::Init and
169 are returned by wxLocale::GetSystemLanguage.
170
171 @beginWxPerlOnly
172 In wxPerl you can't use the '_' function name, so
7c913512
FM
173 the @c Wx::Locale module can export the @c gettext and
174 @c gettext_noop under any given name.
175
23324ae1 176 @code
969daeea 177 # this imports gettext ( equivalent to Wx::GetTranslation
23324ae1
FM
178 # and gettext_noop ( a noop )
179 # into your module
180 use Wx::Locale qw(:default);
7c913512 181
23324ae1 182 # ....
7c913512 183
23324ae1 184 # use the functions
cdbcf4c2 185 print gettext( "Panic!" );
7c913512 186
cdbcf4c2 187 button = Wx::Button-new( window, -1, gettext( "Label" ) );
23324ae1 188 @endcode
7c913512 189
23324ae1
FM
190 If you need to translate a lot of strings, then adding gettext( ) around
191 each one is a long task ( that is why _( ) was introduced ), so just choose
192 a shorter name for gettext:
7c913512 193
23324ae1 194 @code
23324ae1
FM
195 use Wx::Locale 'gettext' = 't',
196 'gettext_noop' = 'gettext_noop';
7c913512 197
23324ae1 198 # ...
7c913512 199
23324ae1 200 # use the functions
cdbcf4c2 201 print t( "Panic!!" );
7c913512 202
23324ae1
FM
203 # ...
204 @endcode
969daeea 205 @endWxPerlOnly
7c913512 206
23324ae1 207 @library{wxbase}
3c99e2fd 208 @category{cfg}
7c913512 209
18e065b4 210 @see @ref overview_i18n, @ref page_samples_internat, wxXLocale, wxTranslations
23324ae1 211*/
7c913512 212class wxLocale
23324ae1
FM
213{
214public:
969daeea
FM
215 /**
216 This is the default constructor and it does nothing to initialize the object:
217 Init() must be used to do that.
218 */
219 wxLocale();
220
221 /**
222 See Init() for parameters description.
223 */
3acf8a8d 224 wxLocale(int language, int flags = wxLOCALE_LOAD_DEFAULT);
969daeea 225
23324ae1
FM
226 /**
227 See Init() for parameters description.
969daeea 228
23324ae1
FM
229 The call of this function has several global side effects which you should
230 understand: first of all, the application locale is changed - note that this
231 will affect many of standard C library functions such as printf() or strftime().
232 Second, this wxLocale object becomes the new current global locale for the
969daeea 233 application and so all subsequent calls to ::wxGetTranslation() will try to
23324ae1
FM
234 translate the messages using the message catalogs for this locale.
235 */
7c913512 236 wxLocale(const wxString& name,
96b77d60 237 const wxString& shortName = wxEmptyString,
7c913512 238 const wxString& locale = wxEmptyString,
3acf8a8d 239 bool bLoadDefault = true);
23324ae1
FM
240
241 /**
242 The destructor, like the constructor, also has global side effects: the
969daeea 243 previously set locale is restored and so the changes described in
23324ae1
FM
244 Init() documentation are rolled back.
245 */
adaaa686 246 virtual ~wxLocale();
23324ae1 247
23324ae1 248 /**
18e065b4 249 Calls wxTranslations::AddCatalog(const wxString&).
23324ae1
FM
250 */
251 bool AddCatalog(const wxString& domain);
a0a4c5aa
FM
252
253 /**
18e065b4
VS
254 Calls wxTranslations::AddCatalog(const wxString&, wxLanguage).
255 */
256 bool AddCatalog(const wxString& domain, wxLanguage msgIdLanguage);
a0a4c5aa 257
18e065b4
VS
258 /**
259 Calls wxTranslations::AddCatalog(const wxString&, wxLanguage, const wxString&).
a0a4c5aa 260 */
969daeea 261 bool AddCatalog(const wxString& domain, wxLanguage msgIdLanguage,
7c913512 262 const wxString& msgIdCharset);
23324ae1
FM
263
264 /**
18e065b4 265 Calls wxFileTranslationsLoader::AddCatalogLookupPathPrefix().
23324ae1 266 */
adaaa686 267 static void AddCatalogLookupPathPrefix(const wxString& prefix);
23324ae1
FM
268
269 /**
969daeea
FM
270 Adds custom, user-defined language to the database of known languages.
271 This database is used in conjunction with the first form of Init().
23324ae1
FM
272 */
273 static void AddLanguage(const wxLanguageInfo& info);
274
275 /**
276 This function may be used to find the language description structure for the
277 given locale, specified either as a two letter ISO language code (for example,
278 "pt"), a language code followed by the country code ("pt_BR") or a full, human
279 readable, language description ("Portuguese-Brazil").
969daeea 280
23324ae1 281 Returns the information for the given language or @NULL if this language
969daeea
FM
282 is unknown. Note that even if the returned pointer is valid, the caller
283 should @e not delete it.
3c4f71cc 284
4cc4bfaf 285 @see GetLanguageInfo()
23324ae1 286 */
382f12e4 287 static const wxLanguageInfo* FindLanguageInfo(const wxString& locale);
23324ae1
FM
288
289 /**
290 Returns the canonical form of current locale name. Canonical form is the
291 one that is used on UNIX systems: it is a two- or five-letter string in xx or
292 xx_YY format, where xx is ISO 639 code of language and YY is ISO 3166 code of
293 the country. Examples are "en", "en_GB", "en_US" or "fr_FR".
23324ae1 294 This form is internally used when looking up message catalogs.
23324ae1
FM
295 Compare GetSysName().
296 */
328f5751 297 wxString GetCanonicalName() const;
23324ae1
FM
298
299 /**
18e065b4 300 Calls wxTranslations::GetHeaderValue().
23324ae1
FM
301 */
302 wxString GetHeaderValue(const wxString& header,
328f5751 303 const wxString& domain = wxEmptyString) const;
23324ae1
FM
304
305 /**
d5c8403a 306 Returns the ::wxLanguage constant of current language.
969daeea 307
23324ae1 308 Note that you can call this function only if you used the form of
d5c8403a 309 Init() that takes ::wxLanguage argument.
23324ae1 310 */
328f5751 311 int GetLanguage() const;
23324ae1
FM
312
313 /**
969daeea
FM
314 Returns a pointer to wxLanguageInfo structure containing information about
315 the given language or @NULL if this language is unknown. Note that even if
316 the returned pointer is valid, the caller should @e not delete it.
317
318 See AddLanguage() for the wxLanguageInfo description.
319 As with Init(), @c wxLANGUAGE_DEFAULT has the special meaning if passed
320 as an argument to this function and in this case the result of
321 GetSystemLanguage() is used.
23324ae1 322 */
57bf907d 323 static const wxLanguageInfo* GetLanguageInfo(int lang);
23324ae1
FM
324
325 /**
326 Returns English name of the given language or empty string if this
327 language is unknown.
969daeea
FM
328
329 See GetLanguageInfo() for a remark about special meaning of @c wxLANGUAGE_DEFAULT.
23324ae1 330 */
57bf907d 331 static wxString GetLanguageName(int lang);
23324ae1 332
18e065b4
VS
333 /**
334 Returns canonical name (see GetCanonicalName()) of the given language
335 or empty string if this language is unknown.
336
337 See GetLanguageInfo() for a remark about special meaning of @c wxLANGUAGE_DEFAULT.
338
339 @since 2.9.1
340 */
341 static wxString GetLanguageCanonicalName(int lang);
342
23324ae1 343 /**
969daeea
FM
344 Returns the locale name as passed to the constructor or Init().
345
346 This is a full, human-readable name, e.g. "English" or "French".
23324ae1 347 */
969daeea 348 const wxString& GetLocale() const;
23324ae1
FM
349
350 /**
351 Returns the current short name for the locale (as given to the constructor or
352 the Init() function).
353 */
969daeea 354 const wxString& GetName() const;
23324ae1 355
23324ae1 356 /**
18e065b4 357 Calls wxTranslations::GetString(const wxString&, const wxString&) const.
969daeea 358 */
fadc2df6
FM
359 virtual const wxString& GetString(const wxString& origString,
360 const wxString& domain = wxEmptyString) const;
969daeea
FM
361
362 /**
dfbb5eff 363 Calls wxTranslations::GetString(const wxString&, const wxString&, unsigned, const wxString&) const.
23324ae1 364 */
7323ff1a 365 virtual const wxString& GetString(const wxString& origString,
dfbb5eff 366 const wxString& origString2, unsigned n,
7323ff1a 367 const wxString& domain = wxEmptyString) const;
23324ae1
FM
368
369 /**
370 Returns current platform-specific locale name as passed to setlocale().
23324ae1
FM
371 Compare GetCanonicalName().
372 */
328f5751 373 wxString GetSysName() const;
23324ae1
FM
374
375 /**
376 Tries to detect the user's default font encoding.
969daeea
FM
377 Returns wxFontEncoding() value or @c wxFONTENCODING_SYSTEM if it
378 couldn't be determined.
23324ae1 379 */
57bf907d 380 static wxFontEncoding GetSystemEncoding();
23324ae1
FM
381
382 /**
969daeea
FM
383 Tries to detect the name of the user's default font encoding.
384 This string isn't particularly useful for the application as its form is
385 platform-dependent and so you should probably use GetSystemEncoding() instead.
386
23324ae1
FM
387 Returns a user-readable string value or an empty string if it couldn't be
388 determined.
389 */
57bf907d 390 static wxString GetSystemEncodingName();
23324ae1
FM
391
392 /**
01f953ef 393 Tries to detect the user's default locale setting.
89a7e1ff 394
fc79419b 395 Returns the ::wxLanguage value or @c wxLANGUAGE_UNKNOWN if the language-guessing
969daeea 396 algorithm failed.
01f953ef
VS
397
398 @note This function works with @em locales and returns the user's default
399 locale. This may be, and usually is, the same as their preferred UI
400 language, but it's not the same thing. Use wxTranslation to obtain
401 @em language information.
402
403 @see wxTranslations::GetBestTranslation().
23324ae1 404 */
57bf907d 405 static int GetSystemLanguage();
23324ae1 406
fc79419b
FM
407 /**
408 Get the values of the given locale-dependent datum.
409
89a7e1ff
VZ
410 This function returns the value of the locale-specific option specified
411 by the given @a index.
412
413 @param index
414 One of the elements of wxLocaleInfo enum.
415 @param cat
416 The category to use with the given index or wxLOCALE_CAT_DEFAULT if
417 the index can only apply to a single category.
418 @return
419 The option value or empty string if the function failed.
fc79419b 420 */
89a7e1ff
VZ
421 static wxString GetInfo(wxLocaleInfo index,
422 wxLocaleCategory cat = wxLOCALE_CAT_DEFAULT);
fc79419b 423
23324ae1 424 /**
969daeea
FM
425 Initializes the wxLocale instance.
426
427 The call of this function has several global side effects which you should
428 understand: first of all, the application locale is changed - note that
429 this will affect many of standard C library functions such as printf()
430 or strftime().
431 Second, this wxLocale object becomes the new current global locale for
432 the application and so all subsequent calls to wxGetTranslation() will
433 try to translate the messages using the message catalogs for this locale.
3c4f71cc 434
7c913512 435 @param language
d5c8403a 436 ::wxLanguage identifier of the locale.
969daeea
FM
437 @c wxLANGUAGE_DEFAULT has special meaning -- wxLocale will use system's
438 default language (see GetSystemLanguage()).
7c913512 439 @param flags
4cc4bfaf 440 Combination of the following:
969daeea
FM
441 - wxLOCALE_LOAD_DEFAULT: Load the message catalog for the given locale
442 containing the translations of standard wxWidgets messages
443 automatically.
f30bd8f2 444 - wxLOCALE_DONT_LOAD_DEFAULT: Negation of wxLOCALE_LOAD_DEFAULT.
89bb3f02
FM
445
446 @return @true on success or @false if the given locale couldn't be set.
447 */
448 bool Init(int language = wxLANGUAGE_DEFAULT,
3acf8a8d 449 int flags = wxLOCALE_LOAD_DEFAULT);
89bb3f02
FM
450
451 /**
452 @deprecated
453 This form is deprecated, use the other one unless you know what you are doing.
454
4cc4bfaf
FM
455 @param name
456 The name of the locale. Only used in diagnostic messages.
457 @param short
458 The standard 2 letter locale abbreviation; it is used as the
459 directory prefix when looking for the message catalog files.
460 @param locale
969daeea
FM
461 The parameter for the call to setlocale().
462 Note that it is platform-specific.
4cc4bfaf 463 @param bLoadDefault
969daeea
FM
464 May be set to @false to prevent loading of the message catalog for the
465 given locale containing the translations of standard wxWidgets messages.
4cc4bfaf 466 This parameter would be rarely used in normal circumstances.
969daeea 467 */
96b77d60 468 bool Init(const wxString& name, const wxString& shortName = wxEmptyString,
3acf8a8d 469 const wxString& locale = wxEmptyString, bool bLoadDefault = true);
23324ae1
FM
470
471 /**
472 Check whether the operating system and/or C run time environment supports
473 this locale. For example in Windows 2000 and Windows XP, support for many
474 locales is not installed by default. Returns @true if the locale is
475 supported.
d5c8403a
FM
476
477 The argument @a lang is the ::wxLanguage identifier. To obtain this for a
478 given a two letter ISO language code, use FindLanguageInfo() to obtain its
479 wxLanguageInfo structure.
480 See AddLanguage() for the wxLanguageInfo description.
3c4f71cc 481
1e24c2af 482 @since 2.7.1.
23324ae1
FM
483 */
484 static bool IsAvailable(int lang);
485
18e065b4
VS
486 /**
487 Calls wxTranslations::IsLoaded().
488 */
489 bool IsLoaded(const wxString& domain) const;
490
491 /**
492 Returns @true if the locale could be set successfully.
493 */
494 bool IsOk() const;
495};