Advanced Strategic Command
i18n.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.org
3  Copyright (C) 1994-2010 Martin Bickel
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 #include <wx/intl.h>
22 #include <iostream>
23 
24 #include "i18n.h"
25 #include "gameoptions.h"
26 
28  public:
30 };
31 
33 {
34  data = new OpaqueLocaleData();
35  const wxLanguageInfo* lanInfo = wxLocale::GetLanguageInfo( wxLocale::GetSystemLanguage() );
36  if ( lanInfo ) {
37  data->canonicalName = ASCString( lanInfo->CanonicalName.mb_str() );
38  }
39 
40 }
41 
42 
44 {
45  if ( CGameOptions::Instance()->languageOverride.length() >= 2 )
47  else {
48  return data->canonicalName;
49  }
50 }
51 
52 ASCString Locale::getLocalizedFile( const ASCString& filename, const ASCString& nativeMessageLanguage )
53 {
54  ASCString lang = getLang();
55 
56  if ( lang != nativeMessageLanguage && !lang.empty()) {
57  ASCString newfilename = filename + "." + lang;
58  if ( exist( newfilename ))
59  return newfilename;
60  else {
61  newfilename.toLower();
62  if ( exist( newfilename ))
63  return newfilename;
64  }
65 
66  if ( lang.find( '_' ) != ASCString::npos ) {
67  ASCString country = lang.substr( 0, lang.find( '_' ) );
68 
69  tfindfile ff( filename + "." + country + "*");
70  if ( ff.getFoundFileNum() )
71  return ff.getnextname();
72 
73  tfindfile ff2( copytoLower(filename) + "." + country + "*");
74  if ( ff2.getFoundFileNum() )
75  return ff2.getnextname();
76 
77  }
78  }
79 
80  return "";
81 }
82 
84 {
85  delete data;
86 }
87 
ASCString & toLower()
Definition: ascstring.cpp:36
Locale()
Definition: i18n.cpp:32
ASCString getnextname(int *loc=NULL, bool *inContainer=NULL, ASCString *location=NULL)
Returns the next entry of the internal file list.
Definition: basestrm.cpp:2211
ASCString canonicalName
Definition: i18n.cpp:29
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
ASCString getLocalizedFile(const ASCString &filename, const ASCString &nativeMessageLanguage="")
Tries to find a file containing native message These files are the filename appended by "...
Definition: i18n.cpp:52
ASCString getLang()
Definition: i18n.cpp:43
Searching for files.
Definition: basestrm.h:484
~Locale()
Definition: i18n.cpp:83
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
bool exist(const ASCString &s)
does a file s exist (wildcards allowed)
Definition: basestrm.cpp:2444
int getFoundFileNum()
Definition: basestrm.h:546
ASCString languageOverride
Definition: gameoptions.h:254
ASCString copytoLower(const ASCString &s)