OpenTTD
language.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #ifndef LANGUAGE_H
11 #define LANGUAGE_H
12 
13 #include "core/smallvec_type.hpp"
14 #ifdef WITH_ICU_I18N
15 #include <unicode/coll.h>
16 #endif /* WITH_ICU_I18N */
17 #include "strings_type.h"
18 
19 static const uint8 CASE_GENDER_LEN = 16;
20 static const uint8 MAX_NUM_GENDERS = 8;
21 static const uint8 MAX_NUM_CASES = 16;
22 
25  static const uint32 IDENT = 0x474E414C;
26 
27  uint32 ident;
28  uint32 version;
29  char name[32];
30  char own_name[32];
31  char isocode[16];
33 
40  uint16 missing;
41  byte plural_form;
42  byte text_dir;
43 
51  uint16 winlangid;
52  uint8 newgrflangid;
53  uint8 num_genders;
54  uint8 num_cases;
55  byte pad[3];
56 
59 
60  bool IsValid() const;
61 
67  uint8 GetGenderIndex(const char *gender_str) const
68  {
69  for (uint8 i = 0; i < MAX_NUM_GENDERS; i++) {
70  if (strcmp(gender_str, this->genders[i]) == 0) return i;
71  }
72  return MAX_NUM_GENDERS;
73  }
74 
80  uint8 GetCaseIndex(const char *case_str) const
81  {
82  for (uint8 i = 0; i < MAX_NUM_CASES; i++) {
83  if (strcmp(case_str, this->cases[i]) == 0) return i;
84  }
85  return MAX_NUM_CASES;
86  }
87 };
89 assert_compile(sizeof(LanguagePackHeader) % 4 == 0);
90 
93  char file[MAX_PATH];
94 };
95 
97 typedef std::vector<LanguageMetadata> LanguageList;
98 
100 extern LanguageList _languages;
101 
103 extern const LanguageMetadata *_current_language;
104 
105 #ifdef WITH_ICU_I18N
106 extern icu::Collator *_current_collator;
107 #endif /* WITH_ICU_I18N */
108 
109 bool ReadLanguagePack(const LanguageMetadata *lang);
111 
112 #endif /* LANGUAGE_H */
uint8 GetCaseIndex(const char *case_str) const
Get the index for the given case.
Definition: language.h:80
Simple vector class that allows allocating an item without the need to copy this->data needlessly...
const LanguageMetadata * _current_language
The currently loaded language.
Definition: strings.cpp:46
uint32 version
32-bits of auto generated version info which is basically a hash of strings.h
Definition: language.h:28
byte pad[3]
pad header to be a multiple of 4
Definition: language.h:55
LanguageList _languages
The actual list of language meta data.
Definition: strings.cpp:45
static const uint32 IDENT
Identifier for OpenTTD language files, big endian for "LANG".
Definition: language.h:25
uint16 offsets[TEXT_TAB_END]
the offsets
Definition: language.h:32
uint16 winlangid
Windows language ID: Windows cannot and will not convert isocodes to something it can use to determin...
Definition: language.h:51
Metadata about a single language.
Definition: language.h:92
char name[32]
the international name of this language
Definition: language.h:29
char isocode[16]
the ISO code for the language (not country code)
Definition: language.h:31
const LanguageMetadata * GetLanguage(byte newgrflangid)
Get the language with the given NewGRF language ID.
Definition: strings.cpp:1880
uint8 num_cases
the number of cases of this language
Definition: language.h:54
bool ReadLanguagePack(const LanguageMetadata *lang)
Read a particular language.
Definition: strings.cpp:1713
Header of a language file.
Definition: language.h:24
static const uint8 MAX_NUM_GENDERS
Maximum number of supported genders.
Definition: language.h:20
byte plural_form
plural form index
Definition: language.h:41
static const uint8 MAX_NUM_CASES
Maximum number of supported cases.
Definition: language.h:21
uint8 GetGenderIndex(const char *gender_str) const
Get the index for the given gender.
Definition: language.h:67
char genders[MAX_NUM_GENDERS][CASE_GENDER_LEN]
the genders used by this translation
Definition: language.h:57
uint16 missing
number of missing strings.
Definition: language.h:40
uint8 num_genders
the number of genders of this language
Definition: language.h:53
End of language files.
Definition: strings_type.h:38
char digit_decimal_separator[8]
Decimal separator.
Definition: language.h:39
char digit_group_separator[8]
Thousand separator used for anything not currencies.
Definition: language.h:35
static const uint8 CASE_GENDER_LEN
The (maximum) length of a case/gender string.
Definition: language.h:19
bool IsValid() const
Check whether the header is a valid header for OpenTTD.
Definition: strings.cpp:1691
std::vector< LanguageMetadata > LanguageList
Type for the list of language meta data.
Definition: language.h:97
assert_compile(sizeof(LanguagePackHeader) % 4==0)
Make sure the size is right.
char own_name[32]
the localized name of this language
Definition: language.h:30
Types related to strings.
char digit_group_separator_currency[8]
Thousand separator used for currencies.
Definition: language.h:37
uint32 ident
32-bits identifier
Definition: language.h:27
char cases[MAX_NUM_CASES][CASE_GENDER_LEN]
the cases used by this translation
Definition: language.h:58
uint8 newgrflangid
newgrf language id
Definition: language.h:52
byte text_dir
default direction of the text
Definition: language.h:42
icu::Collator * _current_collator
Collator for the language currently in use.
Definition: strings.cpp:51