Translations update
[openttd/fttd.git] / src / language.h
blobd33ba81892f1e94b0eb90f953cd5ac2dea6964a1
1 /* $Id$ */
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 */
10 /** @file language.h Information about languages and their files. */
12 #ifndef LANGUAGE_H
13 #define LANGUAGE_H
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"
21 static const uint8 CASE_GENDER_LEN = 16; ///< The (maximum) length of a case/gender string.
22 static const uint8 MAX_NUM_GENDERS = 8; ///< Maximum number of supported genders.
23 static const uint8 MAX_NUM_CASES = 16; ///< Maximum number of supported cases.
25 /** Header of a language file. */
26 struct LanguagePackHeader {
27 static const uint32 IDENT = 0x474E414C; ///< Identifier for OpenTTD language files, big endian for "LANG"
29 uint32 ident; ///< 32-bits identifier
30 uint32 version; ///< 32-bits of auto generated version info which is basically a hash of strings.h
31 char name[32]; ///< the international name of this language
32 char own_name[32]; ///< the localized name of this language
33 char isocode[16]; ///< the ISO code for the language (not country code)
34 uint16 offsets[TEXT_TAB_END]; ///< the offsets
36 /** Thousand separator used for anything not currencies */
37 char digit_group_separator[8];
38 /** Thousand separator used for currencies */
39 char digit_group_separator_currency[8];
40 /** Decimal separator */
41 char digit_decimal_separator[8];
42 uint16 missing; ///< number of missing strings.
43 byte plural_form; ///< plural form index
44 byte text_dir; ///< default direction of the text
45 /**
46 * Windows language ID:
47 * Windows cannot and will not convert isocodes to something it can use to
48 * determine whether a font can be used for the language or not. As a result
49 * of that we need to pass the language id via strgen to OpenTTD to tell
50 * what language it is in "Windows". The ID is the 'locale identifier' on:
51 * http://msdn.microsoft.com/en-us/library/ms776294.aspx
53 uint16 winlangid; ///< windows language id
54 uint8 newgrflangid; ///< newgrf language id
55 uint8 num_genders; ///< the number of genders of this language
56 uint8 num_cases; ///< the number of cases of this language
57 byte pad[3]; ///< pad header to be a multiple of 4
59 char genders[MAX_NUM_GENDERS][CASE_GENDER_LEN]; ///< the genders used by this translation
60 char cases[MAX_NUM_CASES][CASE_GENDER_LEN]; ///< the cases used by this translation
62 bool IsValid() const;
64 /**
65 * Get the index for the given gender.
66 * @param gender_str The string representation of the gender.
67 * @return The index of the gender, or MAX_NUM_GENDERS when the gender is unknown.
69 uint8 GetGenderIndex(const char *gender_str) const
71 for (uint8 i = 0; i < MAX_NUM_GENDERS; i++) {
72 if (strcmp(gender_str, this->genders[i]) == 0) return i;
74 return MAX_NUM_GENDERS;
77 /**
78 * Get the index for the given case.
79 * @param case_str The string representation of the case.
80 * @return The index of the case, or MAX_NUM_CASES when the case is unknown.
82 uint8 GetCaseIndex(const char *case_str) const
84 for (uint8 i = 0; i < MAX_NUM_CASES; i++) {
85 if (strcmp(case_str, this->cases[i]) == 0) return i;
87 return MAX_NUM_CASES;
90 /** Make sure the size is right. */
91 assert_compile(sizeof(LanguagePackHeader) % 4 == 0);
93 /** Metadata about a single language. */
94 struct LanguageMetadata : public LanguagePackHeader {
95 char file[MAX_PATH]; ///< Name of the file we read this data from.
98 /** Type for the list of language meta data. */
99 typedef SmallVector<LanguageMetadata, 4> LanguageList;
101 /** The actual list of language meta data. */
102 extern LanguageList _languages;
104 /** The currently loaded language. */
105 extern const LanguageMetadata *_current_language;
107 #ifdef WITH_ICU_SORT
108 extern Collator *_current_collator;
109 #endif /* WITH_ICU_SORT */
111 bool ReadLanguagePack(const LanguageMetadata *lang);
112 const LanguageMetadata *GetLanguage(byte newgrflangid);
114 #endif /* LANGUAGE_H */