Fix: [NewGRF] New engines did not have a default cargo type set. (#13146)
[openttd-github.git] / src / language.h
blobc67df2bda1ec18b303a5390bd988e04e12ec5f8c
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 */
8 /** @file language.h Information about languages and their files. */
10 #ifndef LANGUAGE_H
11 #define LANGUAGE_H
13 #ifdef WITH_ICU_I18N
14 #include <unicode/coll.h>
15 #endif /* WITH_ICU_I18N */
16 #include "strings_type.h"
17 #include <filesystem>
19 static const uint8_t CASE_GENDER_LEN = 16; ///< The (maximum) length of a case/gender string.
20 static const uint8_t MAX_NUM_GENDERS = 8; ///< Maximum number of supported genders.
21 static const uint8_t MAX_NUM_CASES = 16; ///< Maximum number of supported cases.
23 /** Header of a language file. */
24 struct LanguagePackHeader {
25 static const uint32_t IDENT = 0x474E414C; ///< Identifier for OpenTTD language files, big endian for "LANG"
27 uint32_t ident; ///< 32-bits identifier
28 uint32_t version; ///< 32-bits of auto generated version info which is basically a hash of strings.h
29 char name[32]; ///< the international name of this language
30 char own_name[32]; ///< the localized name of this language
31 char isocode[16]; ///< the ISO code for the language (not country code)
32 uint16_t offsets[TEXT_TAB_END]; ///< the offsets
34 /** Thousand separator used for anything not currencies */
35 char digit_group_separator[8];
36 /** Thousand separator used for currencies */
37 char digit_group_separator_currency[8];
38 /** Decimal separator */
39 char digit_decimal_separator[8];
40 uint16_t missing; ///< number of missing strings.
41 uint8_t plural_form; ///< plural form index
42 uint8_t text_dir; ///< default direction of the text
43 /**
44 * Windows language ID:
45 * Windows cannot and will not convert isocodes to something it can use to
46 * determine whether a font can be used for the language or not. As a result
47 * of that we need to pass the language id via strgen to OpenTTD to tell
48 * what language it is in "Windows". The ID is the 'locale identifier' on:
49 * http://msdn.microsoft.com/en-us/library/ms776294.aspx
51 uint16_t winlangid; ///< windows language id
52 uint8_t newgrflangid; ///< newgrf language id
53 uint8_t num_genders; ///< the number of genders of this language
54 uint8_t num_cases; ///< the number of cases of this language
55 uint8_t pad[3]; ///< pad header to be a multiple of 4
57 char genders[MAX_NUM_GENDERS][CASE_GENDER_LEN]; ///< the genders used by this translation
58 char cases[MAX_NUM_CASES][CASE_GENDER_LEN]; ///< the cases used by this translation
60 bool IsValid() const;
61 bool IsReasonablyFinished() const;
63 /**
64 * Get the index for the given gender.
65 * @param gender_str The string representation of the gender.
66 * @return The index of the gender, or MAX_NUM_GENDERS when the gender is unknown.
68 uint8_t GetGenderIndex(const char *gender_str) const
70 for (uint8_t i = 0; i < MAX_NUM_GENDERS; i++) {
71 if (strcmp(gender_str, this->genders[i]) == 0) return i;
73 return MAX_NUM_GENDERS;
76 /**
77 * Get the index for the given case.
78 * @param case_str The string representation of the case.
79 * @return The index of the case, or MAX_NUM_CASES when the case is unknown.
81 uint8_t GetCaseIndex(const char *case_str) const
83 for (uint8_t i = 0; i < MAX_NUM_CASES; i++) {
84 if (strcmp(case_str, this->cases[i]) == 0) return i;
86 return MAX_NUM_CASES;
89 /** Make sure the size is right. */
90 static_assert(sizeof(LanguagePackHeader) % 4 == 0);
92 /** Metadata about a single language. */
93 struct LanguageMetadata : public LanguagePackHeader {
94 std::filesystem::path file; ///< Name of the file we read this data from.
97 /** Type for the list of language meta data. */
98 typedef std::vector<LanguageMetadata> LanguageList;
100 /** The actual list of language meta data. */
101 extern LanguageList _languages;
103 /** The currently loaded language. */
104 extern const LanguageMetadata *_current_language;
106 #ifdef WITH_ICU_I18N
107 extern std::unique_ptr<icu::Collator> _current_collator;
108 #endif /* WITH_ICU_I18N */
110 bool ReadLanguagePack(const LanguageMetadata *lang);
111 const LanguageMetadata *GetLanguage(uint8_t newgrflangid);
113 #endif /* LANGUAGE_H */