# 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
    00024 static const uint TAB_SIZE_OFFSET  = 0;
    00025 static const uint TAB_SIZE_BITS    = 11;
    00026 static const uint TAB_SIZE         = 1 << TAB_SIZE_BITS;
    00027 static const uint TAB_COUNT_OFFSET = TAB_SIZE_BITS;
    00028 static const uint TAB_COUNT_BITS   = 5;
    00029 static const uint TAB_COUNT        = 1 << TAB_COUNT_BITS;
    00030
    00032 struct LanguagePackHeader {
    00033   static const uint32 IDENT = 0x474E414C;
    00034
    00035   uint32 ident;
    00036   uint32 version;
    00037   char name[32];
    00038   char own_name[32];
    00039   char isocode[16];
    00040   uint16 offsets[TAB_COUNT];
    00041
    00043   char digit_group_separator[8];
    00045   char digit_group_separator_currency[8];
    00047   char digit_decimal_separator[8];
    00048   uint16 missing;
    00049   byte plural_form;
    00050   byte text_dir;
    00051
    00059   uint16 winlangid;
    00060   uint8 newgrflangid;
    00061   uint8 num_genders;
    00062   uint8 num_cases;
    00063   byte pad[3];
    00064
    00065   char genders[MAX_NUM_GENDERS][CASE_GENDER_LEN];
    00066   char cases[MAX_NUM_CASES][CASE_GENDER_LEN];
    00067
    00068   bool IsValid() const;
    00069
    00075   uint8 GetGenderIndex(const char *gender_str) const
    00076   {
    00077     for (uint8 i = 0; i < MAX_NUM_GENDERS; i++) {
    00078       if (strcmp(gender_str, this->genders[i]) == 0) return i;
    00079     }
    00080     return MAX_NUM_GENDERS;
    00081   }
    00082
    00088   uint8 GetCaseIndex(const char *case_str) const
    00089   {
    00090     for (uint8 i = 0; i < MAX_NUM_CASES; i++) {
    00091       if (strcmp(case_str, this->cases[i]) == 0) return i;
    00092     }
    00093     return MAX_NUM_CASES;
    00094   }
    00095 };
    00097 assert_compile(sizeof(LanguagePackHeader) % 4 == 0);
    00098
    00100 struct LanguageMetadata : public LanguagePackHeader {
    00101   char file[MAX_PATH];
    00102 };
    00103
    00105 typedef SmallVector<LanguageMetadata, 4> LanguageList;
    00106
    00108 extern LanguageList _languages;
    00109
    00111 extern const LanguageMetadata *_current_language;
    00112
    00113 #ifdef WITH_ICU
    00114 extern Collator *_current_collator;
    00115 #endif /* WITH_ICU */
    00116
    00117 bool ReadLanguagePack(const LanguageMetadata *lang);
    00118 const LanguageMetadata *GetLanguage(byte newgrflangid);
    00119
    00120 #endif /* LANGUAGE_H */