/[pcsx2_0.9.7]/trunk/common/src/Utilities/pxTranslate.cpp
ViewVC logotype

Contents of /trunk/common/src/Utilities/pxTranslate.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 1 month ago) by william
File size: 4005 byte(s)
re-commit (had local access denied errors when committing)
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #include "PrecompiledHeader.h"
17
18 bool pxIsEnglish( int id )
19 {
20 return ( id == wxLANGUAGE_ENGLISH || id == wxLANGUAGE_ENGLISH_US );
21 }
22
23 // --------------------------------------------------------------------------------------
24 // pxExpandMsg -- an Iconized Text Translator
25 // --------------------------------------------------------------------------------------
26 // This function provides two layers of translated lookups. It puts the key through the
27 // current language first and, if the key is not resolved (meaning the language pack doesn't
28 // have a translation for it), it's put through our own built-in english translation. This
29 // second step is needed to resolve some of our lengthy UI tooltips and descriptors, which
30 // use iconized GetText identifiers.
31 //
32 // (without this second pass many tooltips would just show up as "Savestate Tooltip" instead
33 // of something meaningful).
34 //
35 // Rationale: Traditional gnu-style gettext stuff tends to stop translating strings when
36 // the slightest change to a string is made (including punctuation and possibly even case).
37 // On long strings especially, this can be unwanted since future revisions of the app may have
38 // simple typo or newline fixes that *should not* break existing translations. Furthermore,
39 // icons can be used in places where otherwise identical english verbage for two separate
40 // terms can be differentiated. GNU gettext has some new tools for using fuzzy logic heuristics
41 // matching, but it is also imperfect and complicated, so we have opted to continue using this
42 // system instead.
43 //
44 const wxChar* __fastcall pxExpandMsg( const wxChar* key, const wxChar* englishContent )
45 {
46 #ifdef PCSX2_DEVBUILD
47 static const wxChar* tbl_pxE_Prefixes[] =
48 {
49 L"!Panel:",
50 L"!Notice:",
51 L"!Wizard:",
52 L"!Tooltip:",
53 L"!ContextTip:",
54 NULL
55 };
56
57 // test the prefix of the key for consistency to valid/known prefix types.
58 const wxChar** prefix = tbl_pxE_Prefixes;
59 while( *prefix != NULL )
60 {
61 if( wxString(key).StartsWith(*prefix) ) break;
62 ++prefix;
63 }
64 pxAssertDev( *prefix != NULL,
65 pxsFmt( L"Invalid pxE key prefix in key '%s'. Prefix must be one of the valid prefixes listed in pxExpandMsg.", key )
66 );
67 #endif
68
69 const wxLanguageInfo* info = (wxGetLocale() != NULL) ? wxLocale::GetLanguageInfo( wxGetLocale()->GetLanguage() ) : NULL;
70
71 if( ( info == NULL ) || pxIsEnglish( info->Language ) )
72 return englishContent;
73
74 const wxChar* retval = wxGetTranslation( key );
75
76 // Check if the translation failed, and fall back on an english lookup.
77 return ( wxStrcmp( retval, key ) == 0 ) ? englishContent : retval;
78 }
79
80 // ------------------------------------------------------------------------
81 // Alternative implementation for wxGetTranslation.
82 // This version performs a string length check in devel builds, which issues a warning
83 // if the string seems too long for gettext lookups. Longer complicated strings should
84 // usually be implemented used the pxMsgExpand system instead.
85 //
86 const wxChar* __fastcall pxGetTranslation( const wxChar* message )
87 {
88 if( IsDevBuild )
89 {
90 if( wxStrlen( message ) > 128 )
91 {
92 Console.Warning( "pxGetTranslation: Long message detected, maybe use pxE() instead?" );
93 Console.WriteLn( Color_Green, L"Message: %s", message );
94 }
95 }
96 return wxGetTranslation( message );
97 }

  ViewVC Help
Powered by ViewVC 1.1.22