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/>.
8 /** @file language.h Information about languages and their files. */
13 #include "core/smallvec_type.hpp"
15 #include <unicode/coll.h>
16 #endif /* WITH_ICU_I18N */
17 #include "strings_type.h"
19 static const uint8 CASE_GENDER_LEN
= 16; ///< The (maximum) length of a case/gender string.
20 static const uint8 MAX_NUM_GENDERS
= 8; ///< Maximum number of supported genders.
21 static const uint8 MAX_NUM_CASES
= 16; ///< Maximum number of supported cases.
23 /** Header of a language file. */
24 struct LanguagePackHeader
{
25 static const uint32 IDENT
= 0x474E414C; ///< Identifier for OpenTTD language files, big endian for "LANG"
27 uint32 ident
; ///< 32-bits identifier
28 uint32 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 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 missing
; ///< number of missing strings.
41 byte plural_form
; ///< plural form index
42 byte text_dir
; ///< default direction of the text
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 winlangid
; ///< windows language id
52 uint8 newgrflangid
; ///< newgrf language id
53 uint8 num_genders
; ///< the number of genders of this language
54 uint8 num_cases
; ///< the number of cases of this language
55 byte 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
63 * Get the index for the given gender.
64 * @param gender_str The string representation of the gender.
65 * @return The index of the gender, or MAX_NUM_GENDERS when the gender is unknown.
67 uint8
GetGenderIndex(const char *gender_str
) const
69 for (uint8 i
= 0; i
< MAX_NUM_GENDERS
; i
++) {
70 if (strcmp(gender_str
, this->genders
[i
]) == 0) return i
;
72 return MAX_NUM_GENDERS
;
76 * Get the index for the given case.
77 * @param case_str The string representation of the case.
78 * @return The index of the case, or MAX_NUM_CASES when the case is unknown.
80 uint8
GetCaseIndex(const char *case_str
) const
82 for (uint8 i
= 0; i
< MAX_NUM_CASES
; i
++) {
83 if (strcmp(case_str
, this->cases
[i
]) == 0) return i
;
88 /** Make sure the size is right. */
89 assert_compile(sizeof(LanguagePackHeader
) % 4 == 0);
91 /** Metadata about a single language. */
92 struct LanguageMetadata
: public LanguagePackHeader
{
93 char file
[MAX_PATH
]; ///< Name of the file we read this data from.
96 /** Type for the list of language meta data. */
97 typedef std::vector
<LanguageMetadata
> LanguageList
;
99 /** The actual list of language meta data. */
100 extern LanguageList _languages
;
102 /** The currently loaded language. */
103 extern const LanguageMetadata
*_current_language
;
106 extern icu::Collator
*_current_collator
;
107 #endif /* WITH_ICU_I18N */
109 bool ReadLanguagePack(const LanguageMetadata
*lang
);
110 const LanguageMetadata
*GetLanguage(byte newgrflangid
);
112 #endif /* LANGUAGE_H */