language.h

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef LANGUAGE_H
00013 #define LANGUAGE_H
00014 
00015 #include "core/smallvec_type.hpp"
00016 #ifdef WITH_ICU
00017 #include <unicode/coll.h>
00018 #endif /* WITH_ICU */
00019 
00020 static const uint8 CASE_GENDER_LEN = 16; 
00021 static const uint8 MAX_NUM_GENDERS =  8; 
00022 static const uint8 MAX_NUM_CASES   = 16; 
00023 
00025 struct LanguagePackHeader {
00026   static const uint32 IDENT = 0x474E414C; 
00027 
00028   uint32 ident;       
00029   uint32 version;     
00030   char name[32];      
00031   char own_name[32];  
00032   char isocode[16];   
00033   uint16 offsets[32]; 
00034 
00036   char digit_group_separator[8];
00038   char digit_group_separator_currency[8];
00040   char digit_decimal_separator[8];
00041   uint16 missing;     
00042   byte plural_form;   
00043   byte text_dir;      
00044 
00052   uint16 winlangid;   
00053   uint8 newgrflangid; 
00054   uint8 num_genders;  
00055   uint8 num_cases;    
00056   byte pad[3];        
00057 
00058   char genders[MAX_NUM_GENDERS][CASE_GENDER_LEN]; 
00059   char cases[MAX_NUM_CASES][CASE_GENDER_LEN];     
00060 
00061   bool IsValid() const;
00062 
00068   uint8 GetGenderIndex(const char *gender_str) const
00069   {
00070     for (uint8 i = 0; i < MAX_NUM_GENDERS; i++) {
00071       if (strcmp(gender_str, this->genders[i]) == 0) return i;
00072     }
00073     return MAX_NUM_GENDERS;
00074   }
00075 
00081   uint8 GetCaseIndex(const char *case_str) const
00082   {
00083     for (uint8 i = 0; i < MAX_NUM_CASES; i++) {
00084       if (strcmp(case_str, this->cases[i]) == 0) return i;
00085     }
00086     return MAX_NUM_CASES;
00087   }
00088 };
00090 assert_compile(sizeof(LanguagePackHeader) % 4 == 0);
00091 
00093 struct LanguageMetadata : public LanguagePackHeader {
00094   char file[MAX_PATH]; 
00095 };
00096 
00098 typedef SmallVector<LanguageMetadata, 4> LanguageList;
00099 
00101 extern LanguageList _languages;
00102 
00104 extern const LanguageMetadata *_current_language;
00105 
00106 #ifdef WITH_ICU
00107 extern Collator *_current_collator;
00108 #endif /* WITH_ICU */
00109 
00110 bool ReadLanguagePack(const LanguageMetadata *lang);
00111 const LanguageMetadata *GetLanguage(byte newgrflangid);
00112 
00113 #endif /* LANGUAGE_H */