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/>.
10 /** @file language.h Information about languages and their files. */
15 #include "core/smallvec_type.hpp"
17 #include <unicode/coll.h>
18 #endif /* WITH_ICU_SORT */
20 static const uint8 CASE_GENDER_LEN
= 16; ///< The (maximum) length of a case/gender string.
21 static const uint8 MAX_NUM_GENDERS
= 8; ///< Maximum number of supported genders.
22 static const uint8 MAX_NUM_CASES
= 16; ///< Maximum number of supported cases.
24 static const uint TAB_SIZE_OFFSET
= 0; ///< The offset for the tab size.
25 static const uint TAB_SIZE_BITS
= 11; ///< The number of bits used for the tab size.
26 static const uint TAB_SIZE
= 1 << TAB_SIZE_BITS
; ///< The number of values in a tab.
27 static const uint TAB_COUNT_OFFSET
= TAB_SIZE_BITS
; ///< The offset for the tab count.
28 static const uint TAB_COUNT_BITS
= 5; ///< The number of bits used for the amount of tabs.
29 static const uint TAB_COUNT
= 1 << TAB_COUNT_BITS
; ///< The amount of tabs.
31 /** Header of a language file. */
32 struct LanguagePackHeader
{
33 static const uint32 IDENT
= 0x474E414C; ///< Identifier for OpenTTD language files, big endian for "LANG"
35 uint32 ident
; ///< 32-bits identifier
36 uint32 version
; ///< 32-bits of auto generated version info which is basically a hash of strings.h
37 char name
[32]; ///< the international name of this language
38 char own_name
[32]; ///< the localized name of this language
39 char isocode
[16]; ///< the ISO code for the language (not country code)
40 uint16 offsets
[TAB_COUNT
]; ///< the offsets
42 /** Thousand separator used for anything not currencies */
43 char digit_group_separator
[8];
44 /** Thousand separator used for currencies */
45 char digit_group_separator_currency
[8];
46 /** Decimal separator */
47 char digit_decimal_separator
[8];
48 uint16 missing
; ///< number of missing strings.
49 byte plural_form
; ///< plural form index
50 byte text_dir
; ///< default direction of the text
52 * Windows language ID:
53 * Windows cannot and will not convert isocodes to something it can use to
54 * determine whether a font can be used for the language or not. As a result
55 * of that we need to pass the language id via strgen to OpenTTD to tell
56 * what language it is in "Windows". The ID is the 'locale identifier' on:
57 * http://msdn.microsoft.com/en-us/library/ms776294.aspx
59 uint16 winlangid
; ///< windows language id
60 uint8 newgrflangid
; ///< newgrf language id
61 uint8 num_genders
; ///< the number of genders of this language
62 uint8 num_cases
; ///< the number of cases of this language
63 byte pad
[3]; ///< pad header to be a multiple of 4
65 char genders
[MAX_NUM_GENDERS
][CASE_GENDER_LEN
]; ///< the genders used by this translation
66 char cases
[MAX_NUM_CASES
][CASE_GENDER_LEN
]; ///< the cases used by this translation
71 * Get the index for the given gender.
72 * @param gender_str The string representation of the gender.
73 * @return The index of the gender, or MAX_NUM_GENDERS when the gender is unknown.
75 uint8
GetGenderIndex(const char *gender_str
) const
77 for (uint8 i
= 0; i
< MAX_NUM_GENDERS
; i
++) {
78 if (strcmp(gender_str
, this->genders
[i
]) == 0) return i
;
80 return MAX_NUM_GENDERS
;
84 * Get the index for the given case.
85 * @param case_str The string representation of the case.
86 * @return The index of the case, or MAX_NUM_CASES when the case is unknown.
88 uint8
GetCaseIndex(const char *case_str
) const
90 for (uint8 i
= 0; i
< MAX_NUM_CASES
; i
++) {
91 if (strcmp(case_str
, this->cases
[i
]) == 0) return i
;
96 /** Make sure the size is right. */
97 assert_compile(sizeof(LanguagePackHeader
) % 4 == 0);
99 /** Metadata about a single language. */
100 struct LanguageMetadata
: public LanguagePackHeader
{
101 char file
[MAX_PATH
]; ///< Name of the file we read this data from.
104 /** Type for the list of language meta data. */
105 typedef SmallVector
<LanguageMetadata
, 4> LanguageList
;
107 /** The actual list of language meta data. */
108 extern LanguageList _languages
;
110 /** The currently loaded language. */
111 extern const LanguageMetadata
*_current_language
;
114 extern Collator
*_current_collator
;
115 #endif /* WITH_ICU_SORT */
117 bool ReadLanguagePack(const LanguageMetadata
*lang
);
118 const LanguageMetadata
*GetLanguage(byte newgrflangid
);
120 #endif /* LANGUAGE_H */