OpenTTD
language.h
Go to the documentation of this file.
1 /* $Id: language.h 27756 2017-02-26 19:40:53Z frosch $ */
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 #include "strings_type.h"
20 
21 static const uint8 CASE_GENDER_LEN = 16;
22 static const uint8 MAX_NUM_GENDERS = 8;
23 static const uint8 MAX_NUM_CASES = 16;
24 
27  static const uint32 IDENT = 0x474E414C;
28 
29  uint32 ident;
30  uint32 version;
31  char name[32];
32  char own_name[32];
33  char isocode[16];
35 
42  uint16 missing;
43  byte plural_form;
44  byte text_dir;
45 
53  uint16 winlangid;
54  uint8 newgrflangid;
55  uint8 num_genders;
56  uint8 num_cases;
57  byte pad[3];
58 
61 
62  bool IsValid() const;
63 
69  uint8 GetGenderIndex(const char *gender_str) const
70  {
71  for (uint8 i = 0; i < MAX_NUM_GENDERS; i++) {
72  if (strcmp(gender_str, this->genders[i]) == 0) return i;
73  }
74  return MAX_NUM_GENDERS;
75  }
76 
82  uint8 GetCaseIndex(const char *case_str) const
83  {
84  for (uint8 i = 0; i < MAX_NUM_CASES; i++) {
85  if (strcmp(case_str, this->cases[i]) == 0) return i;
86  }
87  return MAX_NUM_CASES;
88  }
89 };
91 assert_compile(sizeof(LanguagePackHeader) % 4 == 0);
92 
95  char file[MAX_PATH];
96 };
97 
100 
102 extern LanguageList _languages;
103 
105 extern const LanguageMetadata *_current_language;
106 
107 #ifdef WITH_ICU_SORT
108 extern Collator *_current_collator;
109 #endif /* WITH_ICU_SORT */
110 
111 bool ReadLanguagePack(const LanguageMetadata *lang);
113 
114 #endif /* LANGUAGE_H */
uint8 GetCaseIndex(const char *case_str) const
Get the index for the given case.
Definition: language.h:82
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:50
uint32 version
32-bits of auto generated version info which is basically a hash of strings.h
Definition: language.h:30
byte pad[3]
pad header to be a multiple of 4
Definition: language.h:57
LanguageList _languages
The actual list of language meta data.
Definition: strings.cpp:49
static const uint32 IDENT
Identifier for OpenTTD language files, big endian for "LANG".
Definition: language.h:27
Simple vector template class.
uint16 offsets[TEXT_TAB_END]
the offsets
Definition: language.h:34
uint16 winlangid
Windows language ID: Windows cannot and will not convert isocodes to something it can use to determin...
Definition: language.h:53
Metadata about a single language.
Definition: language.h:94
char name[32]
the international name of this language
Definition: language.h:31
char isocode[16]
the ISO code for the language (not country code)
Definition: language.h:33
const LanguageMetadata * GetLanguage(byte newgrflangid)
Get the language with the given NewGRF language ID.
Definition: strings.cpp:1875
uint8 num_cases
the number of cases of this language
Definition: language.h:56
bool ReadLanguagePack(const LanguageMetadata *lang)
Read a particular language.
Definition: strings.cpp:1716
Header of a language file.
Definition: language.h:26
SmallVector< LanguageMetadata, 4 > LanguageList
Type for the list of language meta data.
Definition: language.h:99
static const uint8 MAX_NUM_GENDERS
Maximum number of supported genders.
Definition: language.h:22
byte plural_form
plural form index
Definition: language.h:43
static const uint8 MAX_NUM_CASES
Maximum number of supported cases.
Definition: language.h:23
uint8 GetGenderIndex(const char *gender_str) const
Get the index for the given gender.
Definition: language.h:69
char genders[MAX_NUM_GENDERS][CASE_GENDER_LEN]
the genders used by this translation
Definition: language.h:59
uint16 missing
number of missing strings.
Definition: language.h:42
uint8 num_genders
the number of genders of this language
Definition: language.h:55
End of language files.
Definition: strings_type.h:40
char digit_decimal_separator[8]
Decimal separator.
Definition: language.h:41
char digit_group_separator[8]
Thousand separator used for anything not currencies.
Definition: language.h:37
static const uint8 CASE_GENDER_LEN
The (maximum) length of a case/gender string.
Definition: language.h:21
bool IsValid() const
Check whether the header is a valid header for OpenTTD.
Definition: strings.cpp:1694
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:32
Collator * _current_collator
Collator for the language currently in use.
Definition: strings.cpp:55
Types related to strings.
char digit_group_separator_currency[8]
Thousand separator used for currencies.
Definition: language.h:39
uint32 ident
32-bits identifier
Definition: language.h:29
char cases[MAX_NUM_CASES][CASE_GENDER_LEN]
the cases used by this translation
Definition: language.h:60
uint8 newgrflangid
newgrf language id
Definition: language.h:54
byte text_dir
default direction of the text
Definition: language.h:44