Handling of translated strings. More...
#include "stdafx.h"
#include "currency.h"
#include "station_base.h"
#include "town.h"
#include "screenshot.h"
#include "waypoint_base.h"
#include "depot_base.h"
#include "industry.h"
#include "newgrf_text.h"
#include "fileio_func.h"
#include "group.h"
#include "signs_base.h"
#include "cargotype.h"
#include "fontcache.h"
#include "gui.h"
#include "strings_func.h"
#include "rev.h"
#include "core/endian_func.hpp"
#include "date_func.h"
#include "vehicle_base.h"
#include "engine_base.h"
#include "language.h"
#include "townname_func.h"
#include "string_func.h"
#include "company_base.h"
#include "smallmap_gui.h"
#include "window_func.h"
#include "debug.h"
#include <stack>
#include "table/strings.h"
#include "table/control_codes.h"
Go to the source code of this file.
Data Structures | |
struct | LanguagePack |
struct | Units |
Functions | |
static char * | StationGetSpecialString (char *buff, int x, const char *last) |
static char * | GetSpecialTownNameString (char *buff, int ind, uint32 seed, const char *last) |
static char * | GetSpecialNameString (char *buff, int ind, int64 *argv, const int64 *argve, const char *last, WChar *argt=NULL) |
static char * | FormatString (char *buff, const char *str_arg, int64 *argv, const int64 *argve, uint casei, const char *last, WChar *argt, bool dry_run) |
Parse most format codes within a string and write the result to a buffer. | |
static int64 | GetInt64 (int64 **argv, const int64 *argve, WChar **argt, WChar type=0) |
Read an int64 from the argv array. | |
static int32 | GetInt32 (int64 **argv, const int64 *argve, WChar **argt, WChar type=0) |
Read an int32 from the argv array. | |
static int64 * | GetArgvPtr (int64 **argv, int n, const int64 *argve, WChar **argt) |
Read an array from the argv array. | |
const char * | GetStringPtr (StringID string) |
char * | GetStringWithArgs (char *buffr, uint string, int64 *argv, const int64 *argve, const char *last, WChar *argt) |
The highest 8 bits of string contain the "case index". | |
char * | GetString (char *buffr, StringID string, const char *last) |
char * | InlineString (char *buf, StringID string) |
void | SetDParamStr (uint n, const char *str) |
This function is used to "bind" a C string to a OpenTTD dparam slot. | |
void | InjectDParam (uint amount) |
Shift the string parameters in the global string parameter array by amount positions, making room at the beginning. | |
static char * | FormatNumber (char *buff, int64 number, const char *last, const char *separator, int zerofill_from=19) |
static char * | FormatCommaNumber (char *buff, int64 number, const char *last) |
static char * | FormatNoCommaNumber (char *buff, int64 number, const char *last) |
static char * | FormatZerofillNumber (char *buff, int64 number, int64 count, const char *last) |
static char * | FormatHexNumber (char *buff, uint64 number, const char *last) |
static char * | FormatBytes (char *buff, int64 number, const char *last) |
Format a given number as a number of bytes with the SI prefix. | |
static char * | FormatYmdString (char *buff, Date date, uint modifier, const char *last) |
static char * | FormatMonthAndYear (char *buff, Date date, uint modifier, const char *last) |
static char * | FormatTinyOrISODate (char *buff, Date date, StringID str, const char *last) |
static char * | FormatGenericCurrency (char *buff, const CurrencySpec *spec, Money number, bool compact, const char *last) |
static int | DeterminePluralForm (int64 count, int plural_form) |
Determine the "plural" index given a plural form and a number. | |
static const char * | ParseStringChoice (const char *b, uint form, char **dst, const char *last) |
uint | ConvertSpeedToDisplaySpeed (uint speed) |
Convert the given (internal) speed to the display speed. | |
uint | ConvertDisplaySpeedToSpeed (uint speed) |
Convert the given display speed to the (internal) speed. | |
static char * | GenAndCoName (char *buff, uint32 arg, const char *last) |
static char * | GenPresidentName (char *buff, uint32 x, const char *last) |
void | SortNetworkLanguages () |
bool | ReadLanguagePack (const LanguageMetadata *lang) |
const char * | GetCurrentLocale (const char *param) |
Determine the current charset based on the environment First check some default values, after this one we passed ourselves and if none exist return the value for $LANG. | |
int CDECL | StringIDSorter (const StringID *a, const StringID *b) |
const LanguageMetadata * | GetLanguage (byte newgrflangid) |
Get the language with the given NewGRF language ID. | |
static bool | GetLanguageFileHeader (const char *file, LanguagePackHeader *hdr) |
Reads the language file header and checks compatability. | |
static void | GetLanguageList (const char *path) |
Gets a list of languages from the given directory. | |
void | InitializeLanguagePacks () |
Make a list of the available language packs. | |
const char * | GetCurrentLanguageIsoCode () |
Get the ISO language code of the currently loaded language. | |
static bool | FindMissingGlyphs (const char **str) |
Check whether there are glyphs missing in the current language. | |
void | CheckForMissingGlyphsInLoadedLanguagePack () |
Check whether the currently loaded language pack uses characters that the currently loaded font does not support. | |
Variables | |
char | _config_language_file [MAX_PATH] |
The file (name) stored in the configuration. | |
LanguageList | _languages |
The actual list of language meta data. | |
const LanguageMetadata * | _current_language = NULL |
The currently loaded language. | |
TextDirection | _current_text_dir |
Text direction of the currently selected language. | |
uint64 | _decode_parameters [20] |
Global array of string parameters. To access, use SetDParam. | |
WChar | _parameter_type [20] |
Type of parameters stored in _decode_parameters. | |
Collator * | _current_collator = NULL |
Collator for the language currently in use. | |
static char ** | _langpack_offs |
static LanguagePack * | _langpack |
static uint | _langtab_num [32] |
Offset into langpack offs. | |
static uint | _langtab_start [32] |
Offset into langpack offs. | |
static bool | _keep_gender_data = false |
Should we retain the gender data in the current string? | |
static const Units | units [] |
static const char *const | _silly_company_names [] |
static const char *const | _surname_list [] |
static const char *const | _silly_surname_list [] |
static const char | _initial_name_letters [] |
Handling of translated strings.
Definition in file strings.cpp.
void CheckForMissingGlyphsInLoadedLanguagePack | ( | ) |
Check whether the currently loaded language pack uses characters that the currently loaded font does not support.
If this is the case an error message will be shown in English. The error message will not be localized because that would mean it might use characters that are not in the font, which is the whole reason this check has been added.
Definition at line 1756 of file strings.cpp.
References _current_text_dir, FindMissingGlyphs(), INVALID_STRING_ID, LanguagePackHeader::isocode, LoadStringWidthTable(), SetDParamStr(), SetFallbackFont(), ShowErrorMessage(), TD_LTR, UninitFreeType(), Utf8Encode(), LanguagePackHeader::winlangid, WL_ERROR, and WL_WARNING.
Referenced by GameOptionsWindow::OnDropdownSelect().
uint ConvertDisplaySpeedToSpeed | ( | uint | speed | ) |
Convert the given display speed to the (internal) speed.
speed | the speed to convert |
Definition at line 612 of file strings.cpp.
References _settings_game, GameSettings::locale, Units::s_m, Units::s_s, and LocaleSettings::units.
Referenced by OrdersWindow::OnQueryTextFinished().
uint ConvertSpeedToDisplaySpeed | ( | uint | speed | ) |
Convert the given (internal) speed to the display speed.
speed | the speed to convert |
Definition at line 602 of file strings.cpp.
References _settings_game, GameSettings::locale, Units::s_m, and LocaleSettings::units.
Referenced by DrawOrderString(), FormatString(), OrdersWindow::OnClick(), and OrdersWindow::SetStringParameters().
static int DeterminePluralForm | ( | int64 | count, | |
int | plural_form | |||
) | [static] |
Determine the "plural" index given a plural form and a number.
count | The number to get the plural index of. | |
plural_form | The plural form we want an index for. |
Definition at line 420 of file strings.cpp.
References abs().
Referenced by FormatString().
static bool FindMissingGlyphs | ( | const char ** | str | ) | [static] |
Check whether there are glyphs missing in the current language.
Pointer | to an address for storing the text pointer. |
true
, else return . true
is returned and str is not NULL, *str points to a string that is found to contain at least one missing glyph. Definition at line 1706 of file strings.cpp.
References _langtab_num, _langtab_start, FS_BEGIN, FS_LARGE, FS_NORMAL, FS_SMALL, IsTextDirectionChar(), SCC_BIGFONT, SCC_TINYFONT, and UninitFreeType().
Referenced by CheckForMissingGlyphsInLoadedLanguagePack().
static char* FormatBytes | ( | char * | buff, | |
int64 | number, | |||
const char * | last | |||
) | [static] |
Format a given number as a number of bytes with the SI prefix.
buff | the buffer to write to | |
number | the number of bytes to write down | |
last | the last element in the buffer |
Definition at line 293 of file strings.cpp.
References _settings_game, LanguagePackHeader::digit_decimal_separator, LocaleSettings::digit_decimal_separator, lengthof, GameSettings::locale, and seprintf().
Referenced by FormatString().
static char * FormatString | ( | char * | buff, | |
const char * | str_arg, | |||
int64 * | argv, | |||
const int64 * | argve, | |||
uint | casei, | |||
const char * | last, | |||
WChar * | argt, | |||
bool | dry_run | |||
) | [static] |
Parse most format codes within a string and write the result to a buffer.
buff | The buffer to write the final string to. | |
str | The original string with format codes. | |
argv | Pointer to an array with extra arguments used by various string codes. | |
argve | Pointer to just past the end of the argv array. | |
casei | ||
last | Pointer to just past the end of the buff array. | |
argt | Pointer to an array with the string codes used to parse the argv array. | |
dry_run | True when the argt array is not yet initialized. |
Definition at line 628 of file strings.cpp.
References _keep_gender_data, _settings_game, ConvertSpeedToDisplaySpeed(), CreateTextRefStackBackup(), CT_INVALID, DeterminePluralForm(), endof, Units::f_m, Units::f_s, Units::force, FormatBytes(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_sign_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_group_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_depot_pool >::Get(), SpecializedStation< Waypoint, true >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), CargoSpec::Get(), GetArgvPtr(), SpecializedStation< Station, false >::GetIfValid(), GetIndustrySpec(), GetInt32(), GetInt64(), GetStringWithArgs(), GetTownName(), Units::h_m, Units::h_s, Units::height, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Station::indtype, Company::IsValidHumanID(), Units::l_volume, Units::l_weight, lastof, lengthof, GameSettings::locale, CompanyProperties::name, Vehicle::name, Engine::name, Group::name, BaseStation::name, IndustrySpec::name, CompanyProperties::name_1, CompanyProperties::name_2, Units::p_m, Units::p_s, Units::power, CompanyProperties::president_name, CompanyProperties::president_name_1, CompanyProperties::president_name_2, CargoSpec::quantifier, RemapNewGRFStringControlCode(), RestoreTextRefStackBackup(), Units::s_volume, Units::s_weight, SCC_NEWGRF_FIRST, SCC_NEWGRF_PRINT_STRING_ID, SCC_NEWGRF_STRINL, IndustrySpec::station_name, strecpy(), EngineInfo::string_id, BaseStation::string_id, BaseStation::town, Industry::town, Depot::town_cn, Waypoint::town_cn, BaseVehicle::type, Industry::type, Vehicle::unitnumber, LocaleSettings::units, CargoSpec::units_volume, UsingNewGRFTextStack(), Utf8CharLen(), Utf8Encode(), Units::v_m, Units::v_s, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, Units::velocity, Units::w_m, and Units::w_s.
Referenced by GetStringWithArgs().
static int64* GetArgvPtr | ( | int64 ** | argv, | |
int | n, | |||
const int64 * | argve, | |||
WChar ** | argt | |||
) | [inline, static] |
Read an array from the argv array.
This is done by increasing *argv and *argt by n and returning the original values.
argv | Pointer to a position in the argv array. | |
n | Number of parameters to skip. | |
argve | Pointer just past the end of the argv array. | |
argt | Pointer to a position in the argument type array, or pointer to NULL. |
Definition at line 110 of file strings.cpp.
Referenced by FormatString().
const char* GetCurrentLanguageIsoCode | ( | ) |
Get the ISO language code of the currently loaded language.
Definition at line 1695 of file strings.cpp.
References LanguagePackHeader::isocode.
Referenced by GameOptionsWindow::DrawWidget(), and GameOptionsWindow::UpdateWidgetSize().
const char* GetCurrentLocale | ( | const char * | param | ) |
Determine the current charset based on the environment First check some default values, after this one we passed ourselves and if none exist return the value for $LANG.
param | environment variable to check conditionally if default ones are not set. Pass NULL if you don't want additional checks. |
Definition at line 1545 of file strings.cpp.
static int32 GetInt32 | ( | int64 ** | argv, | |
const int64 * | argve, | |||
WChar ** | argt, | |||
WChar | type = 0 | |||
) | [inline, static] |
Read an int32 from the argv array.
Definition at line 97 of file strings.cpp.
References GetInt64().
Referenced by FormatString(), and GetStringWithArgs().
static int64 GetInt64 | ( | int64 ** | argv, | |
const int64 * | argve, | |||
WChar ** | argt, | |||
WChar | type = 0 | |||
) | [inline, static] |
Read an int64 from the argv array.
The argv and argt arrays are incremented so the next time GetInt64 is called the next value is read.
argv | Pointer to a position in the argv array. | |
argve | Pointer just past the end of the argv array. | |
argt | Pointer to a position in the argument type array, or pointer to NULL. | |
type | Type of the argument to get. Must be equal to **argt if *argt is not NULL and **argt != 0. |
Definition at line 84 of file strings.cpp.
Referenced by FormatString(), and GetInt32().
const LanguageMetadata* GetLanguage | ( | byte | newgrflangid | ) |
Get the language with the given NewGRF language ID.
newgrflangid | NewGRF languages ID to check. |
Definition at line 1581 of file strings.cpp.
References SmallVector< T, S >::Begin(), SmallVector< T, S >::End(), and LanguagePackHeader::newgrflangid.
Referenced by GetLanguageList().
static bool GetLanguageFileHeader | ( | const char * | file, | |
LanguagePackHeader * | hdr | |||
) | [static] |
Reads the language file header and checks compatability.
file | the file to read | |
hdr | the place to write the header information to |
Definition at line 1596 of file strings.cpp.
References LanguagePackHeader::IsValid(), and LanguagePackHeader::winlangid.
Referenced by GetLanguageList().
static void GetLanguageList | ( | const char * | path | ) | [static] |
Gets a list of languages from the given directory.
path | the base directory to search in |
Definition at line 1615 of file strings.cpp.
References SmallVector< T, S >::Append(), DEBUG, LanguageMetadata::file, FS2OTTD(), GetLanguage(), GetLanguageFileHeader(), lastof, LanguagePackHeader::newgrflangid, seprintf(), and ttd_opendir().
Referenced by InitializeLanguagePacks().
char* GetStringWithArgs | ( | char * | buffr, | |
uint | string, | |||
int64 * | argv, | |||
const int64 * | argve, | |||
const char * | last, | |||
WChar * | argt | |||
) |
The highest 8 bits of string contain the "case index".
These 8 bits will only be set when FormatString wants to print the string in a different case. No one else except FormatString should set those bits, therefore string CANNOT be StringID, but uint32.
buffr | Pointer to a string buffer where the formatted string should be written to. | |
string | ||
argv | Array with arguments for the string. | |
argve | Pointer just past the end of argv. | |
last | Pointer just past the end of buffr. | |
argt | Array to be filled with the type of parameters. |
Definition at line 147 of file strings.cpp.
References _langtab_num, error(), FormatString(), GB(), GetGRFStringID(), GetGRFStringPtr(), GetInt32(), GetStringWithArgs(), and HasBit().
Referenced by FormatString(), GetStringWithArgs(), and GetTownName().
void InitializeLanguagePacks | ( | ) |
Make a list of the available language packs.
put the data in _dynlang struct.
< Matching the language in the configuartion file or the current locale
< Using pt_PT for pt_BR locale when pt_BR is not available
< Fallback when no locale-matching language has been found
Definition at line 1647 of file strings.cpp.
References _config_language_file, SmallVector< T, S >::Begin(), SmallVector< T, S >::End(), LanguageMetadata::file, FOR_ALL_SEARCHPATHS, GetCurrentLocale(), GetLanguageList(), LANG_DIR, SmallVector< T, S >::Length(), lengthof, and usererror().
void InjectDParam | ( | uint | amount | ) |
Shift the string parameters in the global string parameter array by amount positions, making room at the beginning.
amount | Number of positions to shift. |
Definition at line 228 of file strings.cpp.
References lengthof.
Referenced by Subsidy::AwardTo().
void SetDParamStr | ( | uint | n, | |
const char * | str | |||
) |
This function is used to "bind" a C string to a OpenTTD dparam slot.
n | slot of the string | |
str | string to bind |
Definition at line 219 of file strings.cpp.
References SetDParam().
Referenced by Subsidy::AwardTo(), CheckForMissingGlyphsInLoadedLanguagePack(), CmdCompanyCtrl(), CmdFoundTown(), CompanyCheckBankrupt(), DrawCargoListText(), NetworkContentListWindow::DrawDetails(), IndustryViewWindow::DrawInfo(), GameOptionsWindow::DrawWidget(), NewsWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), NetworkContentDownloadStatusWindow::DrawWidget(), NetworkChatWindow::DrawWidget(), MusicWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), LandInfoWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), AIConfigWindow::DrawWidget(), AISettingsWindow::DrawWidget(), AIListWindow::DrawWidget(), GenerateCompanyName(), IndustryDirectoryWindow::GetIndustryString(), GetSaveLoadErrorString(), IndustryProductionCallback(), MakeScreenshot(), CustomCurrencyWindow::OnClick(), NetworkStartServerWindow::OnClick(), NetworkGameWindow::OnClick(), IConsoleWindow::OnPaint(), SaveFileError(), CustomCurrencyWindow::SetStringParameters(), GameOptionsWindow::SetStringParameters(), NewGRFWindow::SetStringParameters(), SpriteAlignerWindow::SetStringParameters(), NetworkLobbyWindow::SetStringParameters(), AboutWindow::SetStringParameters(), AIDebugWindow::SetStringParameters(), ShowNewGRFError(), ShowNewGrfVehicleError(), ShowRefitOptionsList(), GameOptionsWindow::UpdateWidgetSize(), NewGRFWindow::UpdateWidgetSize(), NetworkChatWindow::UpdateWidgetSize(), MusicWindow::UpdateWidgetSize(), MusicTrackSelectionWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), and WarnCorruptSprite().
const LanguageMetadata* _current_language = NULL |
The currently loaded language.
Definition at line 47 of file strings.cpp.
Referenced by UnmappedChoiceList::Flush(), CrashLog::LogConfiguration(), GameOptionsWindow::OnClick(), and GameOptionsWindow::SetStringParameters().
const char _initial_name_letters[] [static] |
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', }
Definition at line 1307 of file strings.cpp.
The actual list of language meta data.
Definition at line 46 of file strings.cpp.
Referenced by GameOptionsWindow::OnClick(), and GameOptionsWindow::OnDropdownSelect().
const char* const _silly_company_names[] [static] |
{ "Bloggs Brothers", "Tiny Transport Ltd.", "Express Travel", "Comfy-Coach & Co.", "Crush & Bump Ltd.", "Broken & Late Ltd.", "Sam Speedy & Son", "Supersonic Travel", "Mike's Motors", "Lightning International", "Pannik & Loozit Ltd.", "Inter-City Transport", "Getout & Pushit Ltd." }
Definition at line 1244 of file strings.cpp.
const char* const _silly_surname_list[] [static] |
{ "Grumpy", "Dozy", "Speedy", "Nosey", "Dribble", "Mushroom", "Cabbage", "Sniffle", "Fishy", "Swindle", "Sneaky", "Nutkins" }
Definition at line 1292 of file strings.cpp.
const Units units[] [static] |
{ { 1, 0, STR_UNITS_VELOCITY_IMPERIAL, 1, 0, STR_UNITS_POWER_IMPERIAL, 1, 0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC, 1000, 0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, 1, 0, STR_UNITS_FORCE_SI, 3, 0, STR_UNITS_HEIGHT_IMPERIAL, }, { 103, 6, STR_UNITS_VELOCITY_METRIC, 1, 0, STR_UNITS_POWER_METRIC, 1, 0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC, 1000, 0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, 1, 0, STR_UNITS_FORCE_SI, 1, 0, STR_UNITS_HEIGHT_SI, }, { 1831, 12, STR_UNITS_VELOCITY_SI, 764, 10, STR_UNITS_POWER_SI, 1000, 0, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI, 1, 0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI, 1, 0, STR_UNITS_FORCE_SI, 1, 0, STR_UNITS_HEIGHT_SI, }, }
Definition at line 570 of file strings.cpp.