2008-11-24 11:20:07 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2010-11-13 11:11:02 +00:00
|
|
|
/** @file language.h Information about languages and their files. */
|
2008-11-24 11:20:07 +00:00
|
|
|
|
2010-11-13 11:11:02 +00:00
|
|
|
#ifndef LANGUAGE_H
|
|
|
|
#define LANGUAGE_H
|
2008-11-24 11:20:07 +00:00
|
|
|
|
2010-11-13 12:09:30 +00:00
|
|
|
#include "core/smallvec_type.hpp"
|
2019-03-10 15:46:19 +00:00
|
|
|
#ifdef WITH_ICU_I18N
|
2010-11-27 22:47:29 +00:00
|
|
|
#include <unicode/coll.h>
|
2019-03-10 15:46:19 +00:00
|
|
|
#endif /* WITH_ICU_I18N */
|
2017-02-26 19:40:32 +00:00
|
|
|
#include "strings_type.h"
|
2010-11-13 12:09:30 +00:00
|
|
|
|
2010-11-13 14:36:43 +00:00
|
|
|
static const uint8 CASE_GENDER_LEN = 16; ///< The (maximum) length of a case/gender string.
|
|
|
|
static const uint8 MAX_NUM_GENDERS = 8; ///< Maximum number of supported genders.
|
|
|
|
static const uint8 MAX_NUM_CASES = 16; ///< Maximum number of supported cases.
|
|
|
|
|
2009-04-23 21:05:00 +00:00
|
|
|
/** Header of a language file. */
|
2008-11-24 11:20:07 +00:00
|
|
|
struct LanguagePackHeader {
|
2010-11-07 18:35:59 +00:00
|
|
|
static const uint32 IDENT = 0x474E414C; ///< Identifier for OpenTTD language files, big endian for "LANG"
|
|
|
|
|
2009-04-23 21:05:00 +00:00
|
|
|
uint32 ident; ///< 32-bits identifier
|
|
|
|
uint32 version; ///< 32-bits of auto generated version info which is basically a hash of strings.h
|
|
|
|
char name[32]; ///< the international name of this language
|
|
|
|
char own_name[32]; ///< the localized name of this language
|
|
|
|
char isocode[16]; ///< the ISO code for the language (not country code)
|
2017-02-26 19:40:53 +00:00
|
|
|
uint16 offsets[TEXT_TAB_END]; ///< the offsets
|
2009-04-23 21:05:00 +00:00
|
|
|
|
|
|
|
/** Thousand separator used for anything not currencies */
|
|
|
|
char digit_group_separator[8];
|
|
|
|
/** Thousand separator used for currencies */
|
|
|
|
char digit_group_separator_currency[8];
|
2009-08-12 01:28:11 +00:00
|
|
|
/** Decimal separator */
|
|
|
|
char digit_decimal_separator[8];
|
2011-08-21 19:21:38 +00:00
|
|
|
uint16 missing; ///< number of missing strings.
|
2009-04-23 21:05:00 +00:00
|
|
|
byte plural_form; ///< plural form index
|
|
|
|
byte text_dir; ///< default direction of the text
|
2008-11-24 18:53:17 +00:00
|
|
|
/**
|
|
|
|
* Windows language ID:
|
|
|
|
* Windows cannot and will not convert isocodes to something it can use to
|
|
|
|
* determine whether a font can be used for the language or not. As a result
|
|
|
|
* of that we need to pass the language id via strgen to OpenTTD to tell
|
|
|
|
* what language it is in "Windows". The ID is the 'locale identifier' on:
|
|
|
|
* http://msdn.microsoft.com/en-us/library/ms776294.aspx
|
|
|
|
*/
|
2009-04-23 21:05:00 +00:00
|
|
|
uint16 winlangid; ///< windows language id
|
|
|
|
uint8 newgrflangid; ///< newgrf language id
|
2010-11-13 14:36:43 +00:00
|
|
|
uint8 num_genders; ///< the number of genders of this language
|
|
|
|
uint8 num_cases; ///< the number of cases of this language
|
2011-08-21 19:21:38 +00:00
|
|
|
byte pad[3]; ///< pad header to be a multiple of 4
|
2010-11-13 14:36:43 +00:00
|
|
|
|
|
|
|
char genders[MAX_NUM_GENDERS][CASE_GENDER_LEN]; ///< the genders used by this translation
|
|
|
|
char cases[MAX_NUM_CASES][CASE_GENDER_LEN]; ///< the cases used by this translation
|
2010-11-10 17:48:31 +00:00
|
|
|
|
|
|
|
bool IsValid() const;
|
2010-11-13 14:36:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the index for the given gender.
|
|
|
|
* @param gender_str The string representation of the gender.
|
|
|
|
* @return The index of the gender, or MAX_NUM_GENDERS when the gender is unknown.
|
|
|
|
*/
|
|
|
|
uint8 GetGenderIndex(const char *gender_str) const
|
|
|
|
{
|
|
|
|
for (uint8 i = 0; i < MAX_NUM_GENDERS; i++) {
|
|
|
|
if (strcmp(gender_str, this->genders[i]) == 0) return i;
|
|
|
|
}
|
|
|
|
return MAX_NUM_GENDERS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the index for the given case.
|
|
|
|
* @param case_str The string representation of the case.
|
|
|
|
* @return The index of the case, or MAX_NUM_CASES when the case is unknown.
|
|
|
|
*/
|
|
|
|
uint8 GetCaseIndex(const char *case_str) const
|
|
|
|
{
|
|
|
|
for (uint8 i = 0; i < MAX_NUM_CASES; i++) {
|
|
|
|
if (strcmp(case_str, this->cases[i]) == 0) return i;
|
|
|
|
}
|
|
|
|
return MAX_NUM_CASES;
|
|
|
|
}
|
2008-11-24 11:20:07 +00:00
|
|
|
};
|
2011-05-02 17:42:12 +00:00
|
|
|
/** Make sure the size is right. */
|
2008-11-24 11:20:07 +00:00
|
|
|
assert_compile(sizeof(LanguagePackHeader) % 4 == 0);
|
|
|
|
|
2010-11-13 11:11:02 +00:00
|
|
|
/** Metadata about a single language. */
|
|
|
|
struct LanguageMetadata : public LanguagePackHeader {
|
|
|
|
char file[MAX_PATH]; ///< Name of the file we read this data from.
|
|
|
|
};
|
|
|
|
|
2010-11-13 12:09:30 +00:00
|
|
|
/** Type for the list of language meta data. */
|
|
|
|
typedef SmallVector<LanguageMetadata, 4> LanguageList;
|
|
|
|
|
|
|
|
/** The actual list of language meta data. */
|
|
|
|
extern LanguageList _languages;
|
|
|
|
|
2010-11-13 11:25:58 +00:00
|
|
|
/** The currently loaded language. */
|
|
|
|
extern const LanguageMetadata *_current_language;
|
|
|
|
|
2019-03-10 15:46:19 +00:00
|
|
|
#ifdef WITH_ICU_I18N
|
2018-04-08 00:06:18 +00:00
|
|
|
extern icu::Collator *_current_collator;
|
2019-03-10 15:46:19 +00:00
|
|
|
#endif /* WITH_ICU_I18N */
|
2010-11-27 22:47:29 +00:00
|
|
|
|
2010-11-13 11:38:01 +00:00
|
|
|
bool ReadLanguagePack(const LanguageMetadata *lang);
|
2010-11-13 19:10:30 +00:00
|
|
|
const LanguageMetadata *GetLanguage(byte newgrflangid);
|
2010-11-13 11:38:01 +00:00
|
|
|
|
2010-11-13 11:11:02 +00:00
|
|
|
#endif /* LANGUAGE_H */
|