00001 /* $Id: language.h 21845 2011-01-18 22:31:06Z rubidium $ */ 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 byte plural_form; 00042 byte text_dir; 00043 00051 uint16 winlangid; 00052 uint8 newgrflangid; 00053 uint8 num_genders; 00054 uint8 num_cases; 00055 byte pad[1]; 00056 00057 char genders[MAX_NUM_GENDERS][CASE_GENDER_LEN]; 00058 char cases[MAX_NUM_CASES][CASE_GENDER_LEN]; 00059 00060 bool IsValid() const; 00061 00067 uint8 GetGenderIndex(const char *gender_str) const 00068 { 00069 for (uint8 i = 0; i < MAX_NUM_GENDERS; i++) { 00070 if (strcmp(gender_str, this->genders[i]) == 0) return i; 00071 } 00072 return MAX_NUM_GENDERS; 00073 } 00074 00080 uint8 GetCaseIndex(const char *case_str) const 00081 { 00082 for (uint8 i = 0; i < MAX_NUM_CASES; i++) { 00083 if (strcmp(case_str, this->cases[i]) == 0) return i; 00084 } 00085 return MAX_NUM_CASES; 00086 } 00087 }; 00088 assert_compile(sizeof(LanguagePackHeader) % 4 == 0); 00089 00091 struct LanguageMetadata : public LanguagePackHeader { 00092 char file[MAX_PATH]; 00093 }; 00094 00096 typedef SmallVector<LanguageMetadata, 4> LanguageList; 00097 00099 extern LanguageList _languages; 00100 00102 extern const LanguageMetadata *_current_language; 00103 00104 #ifdef WITH_ICU 00105 extern Collator *_current_collator; 00106 #endif /* WITH_ICU */ 00107 00108 bool ReadLanguagePack(const LanguageMetadata *lang); 00109 const LanguageMetadata *GetLanguage(byte newgrflangid); 00110 00111 #endif /* LANGUAGE_H */