OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

language.h
Go to the documentation of this file.
1 /* $Id: language.h 27367 2015-08-09 12:33:27Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef LANGUAGE_H
13 #define LANGUAGE_H
14
15 #include "core/smallvec_type.hpp"
16 #ifdef WITH_ICU_SORT
17 #include <unicode/coll.h>
18 #endif /* WITH_ICU_SORT */
19
20 static const uint8 CASE_GENDER_LEN = 16;
21 static const uint8 MAX_NUM_GENDERS = 8;
22 static const uint8 MAX_NUM_CASES = 16;
23
24 static const uint TAB_SIZE_OFFSET = 0;
25 static const uint TAB_SIZE_BITS = 11;
26 static const uint TAB_SIZE = 1 << TAB_SIZE_BITS;
27 static const uint TAB_COUNT_OFFSET = TAB_SIZE_BITS;
28 static const uint TAB_COUNT_BITS = 5;
29 static const uint TAB_COUNT = 1 << TAB_COUNT_BITS;
30
32 struct LanguagePackHeader {
33 static const uint32 IDENT = 0x474E414C;
34
35 uint32 ident;
36 uint32 version;
37 char name[32];
38 char own_name[32];
39 char isocode[16];
40 uint16 offsets[TAB_COUNT];
41
43 char digit_group_separator[8];
45 char digit_group_separator_currency[8];
47 char digit_decimal_separator[8];
48 uint16 missing;
49 byte plural_form;
50 byte text_dir;
51
59 uint16 winlangid;
60 uint8 newgrflangid;
61 uint8 num_genders;
62 uint8 num_cases;
63 byte pad[3];
64
65 char genders[MAX_NUM_GENDERS][CASE_GENDER_LEN];
66 char cases[MAX_NUM_CASES][CASE_GENDER_LEN];
67
68 bool IsValid() const;
69
75 uint8 GetGenderIndex(const char *gender_str) const
76 {
77 for (uint8 i = 0; i < MAX_NUM_GENDERS; i++) {
78 if (strcmp(gender_str, this->genders[i]) == 0) return i;
79 }
80 return MAX_NUM_GENDERS;
81 }
82
88 uint8 GetCaseIndex(const char *case_str) const
89 {
90 for (uint8 i = 0; i < MAX_NUM_CASES; i++) {
91 if (strcmp(case_str, this->cases[i]) == 0) return i;
92 }
93 return MAX_NUM_CASES;
94 }
95 };
97 assert_compile(sizeof(LanguagePackHeader) % 4 == 0);
98
100 struct LanguageMetadata : public LanguagePackHeader {
101 char file[MAX_PATH];
102 };
103
105 typedef SmallVector<LanguageMetadata, 4> LanguageList;
106
108 extern LanguageList _languages;
109
111 extern const LanguageMetadata *_current_language;
112
113 #ifdef WITH_ICU_SORT
114 extern Collator *_current_collator;
115 #endif /* WITH_ICU_SORT */
116
117 bool ReadLanguagePack(const LanguageMetadata *lang);
118 const LanguageMetadata *GetLanguage(byte newgrflangid);
119
120 #endif /* LANGUAGE_H */