Add wxTranslations::GetBestTranslation().

Implement preferred language selection on modern systems (OS X, Windows
Vista+). User settings for locale (aka "regional settings") and UI
language are independent there and the UI language shouldn't be
determined from the locale.

Moreover, the OS provides a list of preferred languages, not a single
value (as with locale), so we should use the best language given user's
preferences and available translations. A Czech user may prefer Slovak
UI over English, for example, and we should use Slovak translation in
absence of Czech one in that case instead of falling back to English.

On Unix, locale is language and so things remain as before.

Notice that calling wxLocale::Init(wxLANGUAGE_DEFAULT) does the right
thing now: it sets the locale to whatever the user has configured in
regional settings and loads translations corresponding to default
wxTranslations language, which is determined as described above.
Previously, UI would be translated using a language corresponding to the
regional settings.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72430 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2012-09-08 08:58:38 +00:00
parent 8566fe6edf
commit 01f953efb2
4 changed files with 231 additions and 13 deletions

View File

@@ -30,7 +30,7 @@
@since 2.9.1
@see wxLocale
@see wxLocale, wxTranslationsLoader, wxFileTranslationsLoader
*/
class wxTranslations
{
@@ -85,9 +85,58 @@ public:
This method can be used e.g. to populate list of application's
translations offered to the user. To do this, pass the app's main
catalog as @a domain.
@see GetBestTranslation()
*/
wxArrayString GetAvailableTranslations(const wxString& domain) const;
/**
Returns the best UI language for the @a domain.
The language is determined from the preferred UI language or languages
list the user configured in the OS. Notice that this may or may not
correspond to the default @em locale as obtained from
wxLocale::GetSystemLanguage(); modern operation systems (Windows
Vista+, OS X) have separate language and regional (= locale) settings.
@param domain
The catalog domain to look for.
@param msgIdLanguage
Specifies the language of "msgid" strings in source code
(i.e. arguments to GetString(), wxGetTranslation() and the _() macro).
@return Language code if a suitable match was found, empty string
otherwise.
@since 2.9.5
*/
wxString GetBestTranslation(const wxString& domain, wxLanguage msgIdLanguage);
/**
Returns the best UI language for the @a domain.
The language is determined from the preferred UI language or languages
list the user configured in the OS. Notice that this may or may not
correspond to the default @em locale as obtained from
wxLocale::GetSystemLanguage(); modern operation systems (Windows
Vista+, OS X) have separate language and regional (= locale) settings.
@param domain
The catalog domain to look for.
@param msgIdLanguage
Specifies the language of "msgid" strings in source code
(i.e. arguments to GetString(), wxGetTranslation() and the _() macro).
@return Language code if a suitable match was found, empty string
otherwise.
@since 2.9.5
*/
wxString GetBestTranslation(const wxString& domain,
const wxString& msgIdLanguage = "en");
/**
Add standard wxWidgets catalogs ("wxstd" and possible port-specific
catalogs).