i18n.cpp

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.org
00003      Copyright (C) 1994-2010  Martin Bickel
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
00019 */
00020 
00021 #include <wx/intl.h>
00022 #include <iostream>
00023 
00024 #include "i18n.h"
00025 #include "gameoptions.h"
00026 
00027 class OpaqueLocaleData {
00028    public: 
00029       ASCString canonicalName;  
00030 };
00031 
00032 Locale::Locale()
00033 {
00034    data = new OpaqueLocaleData();
00035    const wxLanguageInfo* lanInfo = wxLocale::GetLanguageInfo( wxLocale::GetSystemLanguage() );
00036    if ( lanInfo ) {
00037       data->canonicalName = ASCString( lanInfo->CanonicalName.mb_str() );
00038    }
00039    
00040 }
00041 
00042 
00043 ASCString Locale::getLang() 
00044 {
00045    if ( CGameOptions::Instance()->languageOverride.length() >= 2 )
00046       return CGameOptions::Instance()->languageOverride;
00047    else {
00048       return data->canonicalName;
00049    }
00050 }
00051       
00052 ASCString Locale::getLocalizedFile( const ASCString& filename, const ASCString& nativeMessageLanguage )
00053 {
00054    ASCString lang = getLang();
00055    
00056    if ( lang != nativeMessageLanguage && !lang.empty()) {
00057       ASCString newfilename = filename + "." + lang;
00058       if ( exist( newfilename )) 
00059          return newfilename; 
00060       else {
00061          newfilename.toLower();
00062          if ( exist( newfilename )) 
00063             return newfilename;
00064       }
00065       
00066       if ( lang.find( '_' ) != ASCString::npos ) {
00067          ASCString country = lang.substr( 0, lang.find( '_' ) );
00068          
00069          tfindfile ff( filename + "." + country + "*");
00070          if ( ff.getFoundFileNum() )
00071             return ff.getnextname();
00072          
00073          tfindfile ff2( copytoLower(filename) + "." + country + "*");
00074          if ( ff2.getFoundFileNum() )
00075             return ff2.getnextname();
00076          
00077       }
00078    }
00079 
00080    return "";
00081 }
00082       
00083 Locale::~Locale()
00084 {
00085    delete data;  
00086 }
00087 

Generated on Mon May 21 01:26:34 2012 for Advanced Strategic Command by  doxygen 1.5.1