|
OpenTTD Source
14.0-RC1
|
Go to the source code of this file.
Data Structures | |
| struct | LanguagePackHeader |
| Header of a language file. More... | |
| struct | LanguageMetadata |
| Make sure the size is right. More... | |
| struct | NumberAbbreviation |
| Container for the power to abbreviation mapping for formatting short numbers. More... | |
Typedefs | |
| typedef std::vector< LanguageMetadata > | LanguageList |
| Type for the list of language meta data. | |
| using | NumberFormatSeparators = std::array< std::string, DIGITS_IN_UINT64_T > |
| Table with the text to place after each of the digits of a number. More... | |
| using | NumberAbbreviations = std::vector< NumberAbbreviation > |
| Lookup for abbreviated formats for different powers of ten. | |
Functions | |
| bool | ReadLanguagePack (const LanguageMetadata *lang) |
| Read a particular language. More... | |
| const LanguageMetadata * | GetLanguage (byte newgrflangid) |
| Get the language with the given NewGRF language ID. More... | |
| std::optional< std::string > | ParseNumberFormatSeparators (NumberFormatSeparators &separators, std::string_view format, size_t length=DIGITS_IN_UINT64_T) |
Parse the NumberFormatSeparators out of the given format string, with the expected number of digits. More... | |
| std::optional< std::string > | ParseNumberAbbreviations (NumberAbbreviations &abbreviations, std::string_view input) |
Parse the NumberAbbreviations out of the given input string. More... | |
Variables | |
| static const uint8_t | CASE_GENDER_LEN = 16 |
| The (maximum) length of a case/gender string. | |
| static const uint8_t | MAX_NUM_GENDERS = 8 |
| Maximum number of supported genders. | |
| static const uint8_t | MAX_NUM_CASES = 16 |
| Maximum number of supported cases. | |
| LanguageList | _languages |
| The actual list of language meta data. | |
| const LanguageMetadata * | _current_language |
| The currently loaded language. | |
| std::unique_ptr< icu::Collator > | _current_collator |
| Collator for the language currently in use. | |
| constexpr int | DIGITS_IN_UINT64_T = 20 |
| The number digits available in a uint64_t. | |
Information about languages and their files.
Definition in file language.h.
| using NumberFormatSeparators = std::array<std::string, DIGITS_IN_UINT64_T> |
Table with the text to place after each of the digits of a number.
The text at index "20 - i" will be inserted after the digit with value "10**i". So, for "normal" thousand separators, the strings at indices 3, 6, 9, 12, 15 and 18 will be filled. For CJK the strings at indices 0, 4, 8, 12 and 16 will be filled.
Definition at line 118 of file language.h.
| const LanguageMetadata* GetLanguage | ( | byte | newgrflangid | ) |
Get the language with the given NewGRF language ID.
| newgrflangid | NewGRF languages ID to check. |
Definition at line 2048 of file strings.cpp.
References _languages.
| std::optional<std::string> ParseNumberAbbreviations | ( | NumberAbbreviations & | abbreviations, |
| std::string_view | input | ||
| ) |
Parse the NumberAbbreviations out of the given input string.
In some places in the UI numbers are getting really big yet their exact value is not that important. For example in the graphs of company values. For this you want more compact number, e.g. 123 m for 123.456.789. However, due to the grouping of digits differing in different cultures, see ParseNumberFormatSeparators, there are many different ways of grouping digits.
This function builds up a lookup table of these abbreviations by power of ten. The input will be a list of definitions per power separator by a pipe character (|). Each definition is the power of ten and and the associated number format with DIGITS_IN_UINT64_T - power digits, separated by the equals sign (=).
For example, for English it defines every third power of ten with subsequently smaller number formats: 3=00,000,000,000,000,000{NBSP}k|6=00,000,000,000,000{NBSP}m|9=00,000,000,000{NBSP}bn|12=00,000,000{NBSP}tn|15=00,000{NBSP}Qa|18=00{NBSP}Qi
| abbreviations | The table to write the abbreviations in; is will be cleared before filling. |
| input | The input format to parse. |
std::optional with the error message, or std::nullopt when the parsing went without problems. Definition at line 1063 of file strgen_base.cpp.
References DIGITS_IN_UINT64_T.
| std::optional<std::string> ParseNumberFormatSeparators | ( | NumberFormatSeparators & | separators, |
| std::string_view | format, | ||
| size_t | length | ||
| ) |
Parse the NumberFormatSeparators out of the given format string, with the expected number of digits.
Different cultures have different ways to separate their numbers when they get really big. In the Western world these are often called thousands separators which come every three digits counted from the back. The actual separator differs per language/country. In Chinese, Japanese and Korean they add a character every four digits counted from the back, and this character differs for each spot as it denotes "ten thousand", "hundred million", etc. In the Indic numbering system (Indian subcontinent), the first separator is after three digits counted from the back, but the next separators are given every two digits.
So, there's no simple single parameter that you can add to the digit grouping character that is already configured. The simplest solution is just defining what character to place between each of the digits, i.e what characters separate each of the digits. These are the NumberFormatSeparators.
To define these, you simply write a string of length zeros and then add any characters in between at the right locations so the digit grouping is correct. When formatting numbers, it will start at the appropriate digit and continue from there with separators.
Examples of formats are "00,000,000,000,000,000,000" and "0000{NBSP}0000{NBSP}0000{NBSP}0000{NBSP}0000".
| separators | The separators to fill; it will be cleared first. |
| format | The format that is going to be read. |
| length | The number of digits that are expected in this format. |
std::optional with the error message, or std::nullopt when the parsing went without problems. Definition at line 1022 of file strgen_base.cpp.
| bool ReadLanguagePack | ( | const LanguageMetadata * | lang | ) |
Read a particular language.
| lang | The metadata about the language. |
Definition at line 1912 of file strings.cpp.
References LanguageMetadata::file, ReadFileToMem(), and TEXT_TAB_END.