OpenTTD Source: src/strings.cpp File Reference

OpenTTD Source 15.0-RC2

Data Structures | Functions | Variables
strings.cpp File Reference

Handling of translated strings. More...

`#include "stdafx.h"`
`#include "currency.h"`
`#include "station_base.h"`
`#include "town.h"`
`#include "waypoint_base.h"`
`#include "depot_base.h"`
`#include "industry.h"`
`#include "newgrf_text.h"`
`#include "fileio_func.h"`
`#include "signs_base.h"`
`#include "error.h"`
`#include "error_func.h"`
`#include "strings_func.h"`
`#include "rev.h"`
`#include "core/endian_func.hpp"`
`#include "timer/timer_game_calendar.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 "game/game_text.hpp"`
`#include "network/network_content_gui.h"`
`#include "newgrf_engine.h"`
`#include "core/backup_type.hpp"`
`#include "gfx_layout.h"`
`#include "core/utf8.hpp"`
`#include "core/string_consumer.hpp"`
`#include <stack>`
`#include "table/strings.h"`
`#include "table/control_codes.h"`
`#include "3rdparty/fmt/std.h"`
`#include "strings_internal.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | LanguagePack
struct | LanguagePackDeleter
struct | LoadedLanguagePack
struct | UnitConversion
| Helper for unit conversion. More...
struct | Units
| Information about a specific unit system. More...
struct | UnitsLong
| Information about a specific unit system with a long variant. More...
class | LanguagePackGlyphSearcher
| Helper for searching through the language pack. More...

## Functions
EncodedString | GetEncodedString (StringID str)
| Encode a string with no parameters into an encoded string.
EncodedString | GetEncodedStringWithArgs (StringID str, std::span< const StringParameter > params)
| Encode a string with its parameters into an encoded string.
uint64_t | GetParamMaxDigits (uint count, FontSize size)
| Get some number that is suitable for string size computations.
uint64_t | GetParamMaxValue (uint64_t max_value, uint min_count, FontSize size)
| Get some number that is suitable for string size computations.
static void | StationGetSpecialString (StringBuilder &builder, StationFacilities x)
static bool | GetSpecialNameString (StringBuilder &builder, StringID string, StringParameters &args)
static void | FormatString (StringBuilder &builder, std::string_view str_arg, StringParameters &args, uint orig_case_index, bool game_script, bool dry_run)
| Parse most format codes within a string and write the result to a buffer.
static void | FormatString (StringBuilder &builder, std::string_view str, std::span< StringParameter > params, uint case_index=0, bool game_script=false, bool dry_run=false)
| Parse most format codes within a string and write the result to a buffer.
std::string_view | GetListSeparator ()
| Get the list separator string for the current language.
std::string_view | GetEllipsis ()
| Get the ellipsis string for the current language.
std::string_view | GetStringPtr (StringID string)
void | GetStringWithArgs (StringBuilder &builder, StringID string, StringParameters &args, uint case_index, bool game_script)
| Get a parsed string with most special stringcodes replaced by the string parameters.
void | GetStringWithArgs (StringBuilder &builder, StringID string, std::span< StringParameter > params, uint case_index, bool game_script)
| Get a parsed string with most special stringcodes replaced by the string parameters.
std::string | GetString (StringID string)
| Resolve the given StringID into a std::string with formatting but no parameters.
void | AppendStringInPlace (std::string &result, StringID string)
| Resolve the given StringID and append in place into an existing std::string with formatting but no parameters.
void | AppendStringWithArgsInPlace (std::string &result, StringID string, std::span< StringParameter > params)
std::string | GetStringWithArgs (StringID string, StringParameters &args)
| Get a parsed string with most special stringcodes replaced by the string parameters.
std::string | GetStringWithArgs (StringID string, std::span< StringParameter > args)
static std::string_view | GetDecimalSeparator ()
static void | FormatNumber (StringBuilder &builder, int64_t number, std::string_view separator)
| Format a number into a string.
static void | FormatCommaNumber (StringBuilder &builder, int64_t number)
static void | FormatNoCommaNumber (StringBuilder &builder, int64_t number)
static void | FormatZerofillNumber (StringBuilder &builder, int64_t number, int count)
static void | FormatHexNumber (StringBuilder &builder, uint64_t number)
static void | FormatBytes (StringBuilder &builder, int64_t number)
| Format a given number as a number of bytes with the SI prefix.
static void | FormatYmdString (StringBuilder &builder, TimerGameCalendar::Date date, uint case_index)
static void | FormatMonthAndYear (StringBuilder &builder, TimerGameCalendar::Date date, uint case_index)
static void | FormatTinyOrISODate (StringBuilder &builder, TimerGameCalendar::Date date, StringID str)
static void | FormatGenericCurrency (StringBuilder &builder, const CurrencySpec *spec, Money number, bool compact)
static int | DeterminePluralForm (int64_t count, uint plural_form)
| Determine the "plural" index given a plural form and a number.
static void | SkipStringChoice (StringConsumer &consumer)
static void | ParseStringChoice (StringConsumer &consumer, uint form, StringBuilder &builder)
static const Units | GetVelocityUnits (VehicleType type)
| Get the correct velocity units depending on the vehicle type and whether we're using real-time units.
uint | ConvertSpeedToDisplaySpeed (uint speed, VehicleType type)
| Convert the given (internal) speed to the display speed.
uint | ConvertDisplaySpeedToSpeed (uint speed, VehicleType type)
| Convert the given display speed to the (internal) speed.
uint | ConvertKmhishSpeedToDisplaySpeed (uint speed, VehicleType type)
| Convert the given km/h-ish speed to the display speed.
uint | ConvertDisplaySpeedToKmhishSpeed (uint speed, VehicleType type)
| Convert the given display speed to the km/h-ish speed.
static void | DecodeEncodedString (StringConsumer &consumer, bool game_script, StringBuilder &builder)
| Decodes an encoded string during FormatString.
static std::span< const std::string_view > | GetSurnameOptions ()
static std::string_view | GetSurname (uint32_t seed)
| Get the surname of the president with the given seed.
static void | GenAndCoName (StringBuilder &builder, uint32_t seed)
static void | GenPresidentName (StringBuilder &builder, uint32_t seed)
bool | ReadLanguagePack (const LanguageMetadata *lang)
| Read a particular language.
std::optional< std::string > | 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.
const LanguageMetadata * | GetLanguage (uint8_t newgrflangid)
| Get the language with the given NewGRF language ID.
static bool | GetLanguageFileHeader (const std::string &file, LanguagePackHeader *hdr)
| Reads the language file header and checks compatibility.
static void | FillLanguageList (const std::string &path)
| Search for the languages in the given directory and add them to the _languages list.
void | InitializeLanguagePacks ()
| Make a list of the available language packs.
std::string_view | GetCurrentLanguageIsoCode ()
| Get the ISO language code of the currently loaded language.
void | CheckForMissingGlyphs (MissingGlyphSearcher *searcher)
| Check whether the currently loaded language pack uses characters that the currently loaded font does not support.

## Variables
std::string | _config_language_file
| The file (name) stored in the configuration.
LanguageList | _languages
| The actual list of language meta data.
const LanguageMetadata * | _current_language = nullptr
| The currently loaded language.
TextDirection | _current_text_dir
| Text direction of the currently selected language.
std::unique_ptr< icu::Collator > | _current_collator
| Collator for the language currently in use.
static LoadedLanguagePack | _langpack
static bool | _scan_for_gender_data = false
| Are we scanning for the gender of the current string? (instead of formatting it)
static const Units | _units_velocity_calendar []
| Unit conversions for velocity.
static const Units | _units_velocity_realtime []
| Unit conversions for velocity.
static const Units | _units_power []
| Unit conversions for power.
static const Units | _units_power_to_weight []
| Unit conversions for power to weight.
static const UnitsLong | _units_weight []
| Unit conversions for weight.
static const UnitsLong | _units_volume []
| Unit conversions for volume.
static const Units | _units_force []
| Unit conversions for force.
static const Units | _units_height []
| Unit conversions for height.
static const Units | _units_time_days_or_seconds []
| Unit conversions for time in calendar days or wallclock seconds.
static const Units | _units_time_months_or_minutes []
| Unit conversions for time in calendar months or wallclock minutes.
static const Units | _units_time_years_or_periods []
| Unit conversions for time in calendar years or economic periods.
static const Units | _units_time_years_or_minutes []
| Unit conversions for time in calendar years or wallclock minutes.
static const std::string_view | _silly_company_names []
static const std::string_view | _surname_list []
static const std::string_view | _silly_surname_list []
static const char | _initial_name_letters []

## Detailed Description

Handling of translated strings.

Definition in file strings.cpp.

## Function Documentation

## ◆ AppendStringInPlace()

void AppendStringInPlace | ( | std::string & | result,
|  | StringID | string
| ) |  |

Resolve the given StringID and append in place into an existing std::string with formatting but no parameters.

Parameters

  result | The std::string to place the translated string.
  string | The unique identifier of the translatable string.

Definition at line 434 of file strings.cpp.

References GetStringWithArgs().

Referenced by DrawBadgeNameList(), and DrawRoadVehDetails().

## ◆ AppendStringWithArgsInPlace()

void AppendStringWithArgsInPlace | ( | std::string & | result,
|  | StringID | string,
|  | std::span< StringParameter > | params
| ) |  |

Definition at line 440 of file strings.cpp.

## ◆ CheckForMissingGlyphs()

void CheckForMissingGlyphs | ( | MissingGlyphSearcher * | searcher | ) |

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.

Parameters

  searcher | The methods to use to search for strings to check. If nullptr the loaded language pack searcher is used.

Definition at line 2363 of file strings.cpp.

References _current_text_dir, FontProviderManager::FindFallbackFont(), MissingGlyphSearcher::FindMissingGlyphs(), FontCacheSubSetting::font, FONTSIZES_REQUIRED, GetEncodedString(), FontCache::LoadFontCaches(), LoadStringWidthTable(), FontCacheSettings::medium, FontCacheSettings::mono, MissingGlyphSearcher::Monospace(), FontCacheSubSetting::os_handle, BaseStringBuilder::Put(), BaseStringBuilder::PutUtf8(), ShowErrorMessage(), TD_LTR, WL_ERROR, and WL_WARNING.

Referenced by HandleBootstrap(), LoadIntroGame(), TextfileWindow::LoadText(), GameOptionsWindow::OnClick(), and GameOptionsWindow::OnDropdownSelect().

## ◆ ConvertDisplaySpeedToKmhishSpeed()

uint ConvertDisplaySpeedToKmhishSpeed | ( | uint | speed,
|  | VehicleType | type
| ) |  |

Convert the given display speed to the km/h-ish speed.

Parameters

  speed | the speed to convert

Returns
  the converted speed.

Definition at line 1001 of file strings.cpp.

References Units::c, UnitConversion::FromDisplay(), and GetVelocityUnits().

Referenced by TimetableWindow::OnQueryTextFinished().

## ◆ ConvertDisplaySpeedToSpeed()

uint ConvertDisplaySpeedToSpeed | ( | uint | speed,
|  | VehicleType | type
| ) |  |

Convert the given display speed to the (internal) speed.

Parameters

  speed | the speed to convert

Returns
  the converted speed.

Definition at line 981 of file strings.cpp.

References Units::c, UnitConversion::FromDisplay(), and GetVelocityUnits().

Referenced by OrdersWindow::OnQueryTextFinished().

## ◆ ConvertKmhishSpeedToDisplaySpeed()

uint ConvertKmhishSpeedToDisplaySpeed | ( | uint | speed,
|  | VehicleType | type
| ) |  |

Convert the given km/h-ish speed to the display speed.

Parameters

  speed | the speed to convert

Returns
  the converted speed.

Definition at line 991 of file strings.cpp.

References Units::c, GetVelocityUnits(), and UnitConversion::ToDisplay().

Referenced by FormatString(), and TimetableWindow::OnClick().

## ◆ ConvertSpeedToDisplaySpeed()

uint ConvertSpeedToDisplaySpeed | ( | uint | speed,
|  | VehicleType | type
| ) |  |

Convert the given (internal) speed to the display speed.

Parameters

  speed | the speed to convert

Returns
  the converted speed.

Definition at line 968 of file strings.cpp.

References Units::c, GetVelocityUnits(), and UnitConversion::ToDisplay().

Referenced by DrawOrderString(), OrdersWindow::GetWidgetString(), and OrdersWindow::OnClick().

## ◆ DecodeEncodedString()

static void DecodeEncodedString | ( | StringConsumer & | consumer,
|  | bool | game_script,
|  | StringBuilder & | builder
| ) |  |
| static

Decodes an encoded string during FormatString.

Parameters

  consumer | The encoded string.
  game_script | Set if decoding a GameScript-encoded string. This affects how string IDs are handled.
  builder | The string builder to write the string to.

Definition at line 1012 of file strings.cpp.

References StringConsumer::AnyBytesLeft(), GetStringWithArgs(), StringConsumer::KEEP_SEPARATOR, MakeStringID(), StringConsumer::npos, StringConsumer::PeekUtf8If(), StringConsumer::Read(), StringConsumer::ReadIntegerBase(), StringConsumer::ReadUntilUtf8(), StringConsumer::ReadUtf8(), SCC_ENCODED, SCC_ENCODED_NUMERIC, SCC_ENCODED_STRING, StringConsumer::SkipAll(), StringConsumer::SkipUtf8If(), TAB_SIZE_GAMESCRIPT, and TEXT_TAB_GAMESCRIPT_START.

Referenced by FormatString().

## ◆ DeterminePluralForm()

static int DeterminePluralForm | ( | int64_t | count,
|  | uint | plural_form
| ) |  |
| static

Determine the "plural" index given a plural form and a number.

Parameters

  count | The number to get the plural index of.
  plural_form | The plural form we want an index for.

Returns
  The plural index for the given form.

Definition at line 656 of file strings.cpp.

References abs().

Referenced by FormatString().

## ◆ FillLanguageList()

static void FillLanguageList | ( | const std::string & | path | ) |
| static

Search for the languages in the given directory and add them to the _languages list.

Parameters

  path | the base directory to search in

Definition at line 2193 of file strings.cpp.

References _languages, Debug, LanguageMetadata::file, FS2OTTD(), GetLanguage(), GetLanguageFileHeader(), LanguagePackHeader::newgrflangid, and OTTD2FS().

Referenced by InitializeLanguagePacks().

## ◆ FormatBytes()

static void FormatBytes | ( | StringBuilder & | builder,
|  | int64_t | number
| ) |  |
| static

Format a given number as a number of bytes with the SI prefix.

Parameters

  builder | the string builder to write to
  number | the number of bytes to write down

Definition at line 537 of file strings.cpp.

References StringBuilder::back_inserter(), lengthof, and NBSP.

Referenced by FormatString().

## ◆ FormatCommaNumber()

static void FormatCommaNumber | ( | StringBuilder & | builder,
|  | int64_t | number
| ) |  |
| static

Definition at line 510 of file strings.cpp.

## ◆ FormatGenericCurrency()

static void FormatGenericCurrency | ( | StringBuilder & | builder,
|  | const CurrencySpec * | spec,
|  | Money | number,
|  | bool | compact
| ) |  |
| static

Definition at line 590 of file strings.cpp.

## ◆ FormatHexNumber()

static void FormatHexNumber | ( | StringBuilder & | builder,
|  | uint64_t | number
| ) |  |
| static

Definition at line 527 of file strings.cpp.

## ◆ FormatMonthAndYear()

static void FormatMonthAndYear | ( | StringBuilder & | builder,
|  | TimerGameCalendar::Date | date,
|  | uint | case_index
| ) |  |
| static

Definition at line 573 of file strings.cpp.

## ◆ FormatNoCommaNumber()

static void FormatNoCommaNumber | ( | StringBuilder & | builder,
|  | int64_t | number
| ) |  |
| static

Definition at line 517 of file strings.cpp.

## ◆ FormatNumber()

static void FormatNumber | ( | StringBuilder & | builder,
|  | int64_t | number,
|  | std::string_view | separator
| ) |  |
| static

Format a number into a string.

Parameters

  builder | the string builder to write to
  number | the number to write down
  separator | the thousands-separator to use

Definition at line 482 of file strings.cpp.

References BaseStringBuilder::PutChar().

## ◆ FormatString() [1/2]

static void FormatString | ( | StringBuilder & | builder,
|  | std::string_view | str,
|  | std::span< StringParameter > | params,
|  | uint | case_index = `0`,
|  | bool | game_script = `false`,
|  | bool | dry_run = `false`
| ) |  |
| static

Parse most format codes within a string and write the result to a buffer.

This is a wrapper for a span of StringParameter which creates the StringParameters state and forwards to the regular call.

Parameters

  builder | The string builder to write the final string to.
  str | Pointer to string to format.
  params | The span of parameters to pass.
  case_index | The current case index.
  game_script | True when doing GameScript text processing.
  dry_run | True when the args' type data is not yet initialized.

Definition at line 261 of file strings.cpp.

References FormatString().

## ◆ FormatString() [2/2]

static void FormatString | ( | StringBuilder & | builder,
|  | std::string_view | str_arg,
|  | StringParameters & | args,
|  | uint | orig_case_index,
|  | bool | game_script,
|  | bool | dry_run
| ) |  |
| static

Parse most format codes within a string and write the result to a buffer.

Parameters

  builder | The string builder to write the final string to.
  str_arg | The original string with format codes.
  args | Pointer to extra arguments used by various string codes.
  dry_run | True when the args' type data is not yet initialized.

Definition at line 1083 of file strings.cpp.

References _scan_for_gender_data, _settings_game, _sorted_cargo_specs, _units_force, _units_height, _units_power, _units_power_to_weight, _units_time_days_or_seconds, _units_time_months_or_minutes, _units_time_years_or_minutes, _units_time_years_or_periods, _units_volume, _units_weight, StringParameters::AdvanceOffset(), StringBuilder::back_inserter(), UnitsLong::c, CBID_VEHICLE_NAME, ConvertKmhishSpeedToDisplaySpeed(), Debug, DecodeEncodedString(), DEFAULT_GROUP, DeterminePluralForm(), FormatBytes(), FormatString(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_depot_pool >::Get(), CargoSpec::Get(), CargoSpec::GetArraySize(), GetCurrency(), StringParameters::GetDataLeft(), GetGRFStringWithTextStack(), SpecializedStation< Waypoint, true >::GetIfValid(), SpecializedStation< Station, false >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_sign_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_industry_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), GetIndustrySpec(), GetListSeparator(), StringParameters::GetNextParameter(), StringParameters::GetNextParameterString(), StringParameters::GetNumParameters(), StringParameters::GetOffset(), StringParameters::GetRemainingParameters(), GetStringTab(), GetStringWithArgs(), StringParameters::GetTypeAtOffset(), GetVehicleCallback(), GetVelocityUnits(), GRFSTR_MISC_GRF_TEXT, Vehicle::group_id, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsInsideMM(), IsValidCargoType(), Company::IsValidHumanID(), lengthof, GameSettings::locale, MakeParameters(), BaseConsist::name, BaseStation::name, CompanyProperties::name, Group::name, IndustrySpec::name, Name, Town::name, CompanyProperties::name_1, CompanyProperties::name_2, Group::number, PowerOfTen(), CompanyProperties::president_name, CompanyProperties::president_name_1, CompanyProperties::president_name_2, BaseStringBuilder::PutUint8(), BaseStringBuilder::PutUtf8(), StringConsumer::Read(), StringConsumer::ReadUint16LE(), StringConsumer::ReadUint8(), StringConsumer::ReadUtf8(), StringConsumer::ReadUtf8If(), RemapNewGRFStringControlCode(), SCC_ENCODED, SCC_ENCODED_INTERNAL, SCC_NEWGRF_FIRST, SCC_NEWGRF_PRINT_WORD_STRING_ID, SCC_NEWGRF_STRINL, StringParameters::SetOffset(), IndustrySpec::station_name, BaseStation::string_id, TEXT_TAB_GAMESCRIPT_START, UnitConversion::ToDisplay(), BaseStation::town, Industry::town, Depot::town_cn, Waypoint::town_cn, Industry::type, BaseVehicle::type, Vehicle::unitnumber, LocaleSettings::units_force, LocaleSettings::units_height, LocaleSettings::units_power, CargoSpec::units_volume, LocaleSettings::units_volume, LocaleSettings::units_weight, TimerGameEconomy::UsingWallclockUnits(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by FormatString(), FormatString(), and GetStringWithArgs().

## ◆ FormatTinyOrISODate()

static void FormatTinyOrISODate | ( | StringBuilder & | builder,
|  | TimerGameCalendar::Date | date,
|  | StringID | str
| ) |  |
| static

Definition at line 581 of file strings.cpp.

## ◆ FormatYmdString()

static void FormatYmdString | ( | StringBuilder & | builder,
|  | TimerGameCalendar::Date | date,
|  | uint | case_index
| ) |  |
| static

Definition at line 565 of file strings.cpp.

## ◆ FormatZerofillNumber()

static void FormatZerofillNumber | ( | StringBuilder & | builder,
|  | int64_t | number,
|  | int | count
| ) |  |
| static

Definition at line 522 of file strings.cpp.

## ◆ GenAndCoName()

static void GenAndCoName | ( | StringBuilder & | builder,
|  | uint32_t | seed
| ) |  |
| static

Definition at line 1939 of file strings.cpp.

## ◆ GenPresidentName()

static void GenPresidentName | ( | StringBuilder & | builder,
|  | uint32_t | seed
| ) |  |
| static

Definition at line 1945 of file strings.cpp.

## ◆ GetCurrentLanguageIsoCode()

std::string_view GetCurrentLanguageIsoCode | ( |  | ) |

Get the ISO language code of the currently loaded language.

Returns
  the ISO code.

Definition at line 2270 of file strings.cpp.

Referenced by GameOptionsWindow::DrawWidget(), GetTextfile(), and GameOptionsWindow::OnResize().

## ◆ GetCurrentLocale()

std::optional< std::string > 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.

Parameters

  param | environment variable to check conditionally if default ones are not set. Pass nullptr if you don't want additional checks.

Returns
  return string containing current charset, or nullptr if not-determinable

Definition at line 2130 of file strings.cpp.

References GetEnv().

Referenced by InitializeLanguagePacks().

## ◆ GetDecimalSeparator()

static std::string_view GetDecimalSeparator | ( |  | ) |
| static

Definition at line 469 of file strings.cpp.

## ◆ GetEllipsis()

std::string_view GetEllipsis | ( |  | ) |

Get the ellipsis string for the current language.

Returns
  string containing ellipsis to use.

Definition at line 308 of file strings.cpp.

References LoadedLanguagePack::ellipsis.

Referenced by DrawLayoutLine().

## ◆ GetEncodedString()

EncodedString GetEncodedString | ( | StringID | str | ) |

Encode a string with no parameters into an encoded string.

Parameters

  str | The StringID to format.

Returns
  The encoded string.

Definition at line 90 of file strings.cpp.

References GetEncodedStringWithArgs().

Referenced by FiosFileScanner::AddFile(), NewGRFWindow::AddGRFToActive(), AdvertiseIndustryOpening(), ClientNetworkContentSocketHandler::AfterDownload(), AfterLoadGame(), AgeVehicle(), AircraftEntersTerminal(), AircraftHandleDestTooFar(), Subsidy::AwardTo(), ClientNetworkContentSocketHandler::BeforeDownload(), BuildReplacementVehicle(), CalcRaildirsDrawstyle(), CcStartStopVehicle(), ChangeIndustryProduction(), CheckCompanyHasMoney(), ClientNetworkGameSocketHandler::CheckConnection(), CheckDynamicEngines(), CheckEngines(), CheckForMissingGlyphs(), CheckIndustries(), CheckOrders(), CheckTownRoadTypes(), CheckTrainCollision(), CheckTrainsLengths(), ClickChangeMaxHlCheat(), NetworkGameSocketHandler::CloseConnection(), CmdBuildIndustry(), CmdCompanyCtrl(), CmdFoundTown(), CmdIndustrySetProduction(), CmdPause(), CommandCostWithParam(), CompanyCheckBankrupt(), CrashAirplane(), CreateSubsidy(), AIInstance::Died(), GameInstance::Died(), Disaster_CoalMine_Init(), DisasterTick_Aircraft(), DisasterTick_Big_Ufo(), DisasterTick_Ufo(), DisasterTick_Zeppeliner(), DispatchHoverEvent(), DispatchRightClickEvent(), DoAutoOrNetsave(), ErrorUnknownCallbackResult(), FiosGetFileList(), FloodVehicle(), GenerateCompanyName(), GenerateTowns(), GetEncodedStringIfValid(), GetOrderCmdFromTile(), GetSavegameFormat(), GetSaveLoadErrorMessage(), GetSaveLoadErrorType(), ButtonLine::GetTooltip(), ClientButtonLine::GetTooltip(), GraphicsSetLoadConfig(), GRFLoadConfig(), Vehicle::HandlePathfindingResult(), IndustryProductionCallback(), CommandHelperBase::InternalPostBefore(), CommandHelperBase::InternalPostResult(), LoadTownData(), MakeScreenshotWithConfirm(), NetworkValidateClientName(), NetworkValidateServerName(), NewVehicleAvailable(), AIConfigWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), DepotWindow::OnClick(), SaveLoadWindow::OnClick(), GSConfigWindow::OnClick(), GenerateLandscapeWindow::OnClick(), GenerateProgressWindow::OnClick(), VehicleGroupWindow::OnClick(), BuildIndustryWindow::OnClick(), SelectGameWindow::OnClick(), NetworkContentListWindow::OnClick(), NewGRFWindow::OnClick(), GameOptionsWindow::OnClick(), ScenarioEditorLandscapeGenerationWindow::OnClick(), NetworkContentListWindow::OnConnect(), NetworkClientListWindow::OnDropdownSelect(), GameOptionsWindow::OnDropdownSelect(), BuildIndustryWindow::OnPlaceObject(), SelectCompanyManagerFaceWindow::OnQueryTextFinished(), FoundTownWindow::OnQueryTextFinished(), DepotWindow::OnRightClick(), SaveLoadWindow::OnTimeout(), ReplaceVehicleWindow::OnTooltip(), CheatWindow::OnTooltip(), IndustryCargoesWindow::OnTooltip(), LinkGraphLegendWindow::OnTooltip(), BuildRailToolbarWindow::OnTooltip(), TextfileWindow::OnTooltip(), VehicleDetailsWindow::OnTooltip(), DepotWindow::OnVehicleSelect(), OrdersWindow::OnVehicleSelect(), openttd_main(), ListSettingDesc::ParseValue(), IntSettingDesc::ParseValue(), BoolSettingDesc::ParseValue(), OneOfManySettingDesc::ParseValue(), ManyOfManySettingDesc::ParseValue(), ReadHeightmapBMP(), ReadHeightmapPNG(), RealMakeScreenshot(), ClientNetworkCoordinatorSocketHandler::Receive_GC_ERROR(), ClientNetworkCoordinatorSocketHandler::Receive_GC_REGISTER_ACK(), ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(), ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(), ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(), ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(), ClientNetworkGameSocketHandler::Receive_SERVER_FULL(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(), ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME(), ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(), ReportNewsProductionChangeIndustry(), RoadVehArrivesAt(), SaveOrLoad(), DriverFactoryBase::SelectDriverImpl(), ShipArrivesAt(), ShowBuildBridgeWindow(), ShowCostOrIncomeAnimation(), ShowEstimatedCostOrIncome(), ShowFeederIncomeAnimation(), ShowFillingPercent(), ShowNetworkContentListWindow(), ShowNewGrfVehicleError(), ShowRejectOrAcceptNews(), ShowScriptDebugWindow(), TownActionBribe(), TownActionBuyRights(), TownActionRoadRebuild(), TrainEnterStation(), UpdateFillingPercent(), VehicleEnterDepot(), VpSelectTilesWithMethod(), VpSetPresizeRange(), and WarnCorruptSprite().

## ◆ GetEncodedStringWithArgs()

EncodedString GetEncodedStringWithArgs | ( | StringID | str,
|  | std::span< const StringParameter > | params
| ) |  |

Encode a string with its parameters into an encoded string.

The encoded string can be stored and decoded later without requiring parameters to be stored separately.

Parameters

  str | The StringID to format.
  params | The parameters of the string.

Returns
  The encoded string.

Definition at line 102 of file strings.cpp.

Referenced by CheckOwnership(), CmdConvertRoad(), GetEncodedString(), GetEncodedString(), GetErrorMessageFromLocationCallbackResult(), and ShowNewGRFError().

## ◆ GetLanguage()

const LanguageMetadata * GetLanguage | ( | uint8_t | newgrflangid | ) |

Get the language with the given NewGRF language ID.

Parameters

  newgrflangid | NewGRF languages ID to check.

Returns
  The language's metadata, or nullptr if it is not known.

Definition at line 2157 of file strings.cpp.

References _languages.

Referenced by FillLanguageList(), and GlobalVarChangeInfo().

## ◆ GetLanguageFileHeader()

static bool GetLanguageFileHeader | ( | const std::string & | file,
|  | LanguagePackHeader * | hdr
| ) |  |
| static

Reads the language file header and checks compatibility.

Parameters

  file | the file to read
  hdr | the place to write the header information to

Returns
  true if and only if the language file is of a compatible version

Definition at line 2172 of file strings.cpp.

References LanguagePackHeader::IsValid(), LanguagePackHeader::missing, FileHandle::Open(), and LanguagePackHeader::winlangid.

Referenced by FillLanguageList().

## ◆ GetListSeparator()

std::string_view GetListSeparator | ( |  | ) |

Get the list separator string for the current language.

Returns
  string containing list separator to use.

Definition at line 299 of file strings.cpp.

References LoadedLanguagePack::list_separator.

Referenced by BuildCargoAcceptanceString(), DrawBadgeNameList(), NetworkContentListWindow::DrawDetails(), DrawRoadVehDetails(), and FormatString().

## ◆ GetParamMaxDigits()

uint64_t GetParamMaxDigits | ( | uint | count,
|  | FontSize | size
| ) |  |

Get some number that is suitable for string size computations.

Parameters

  count | Number of digits which shall be displayable.
  size | Font of the number

Returns
  Number to use for string size computations.

Definition at line 218 of file strings.cpp.

References GetBroadestDigit().

Referenced by GetParamMaxValue(), GetUnitNumberWidth(), DepotWindow::UpdateWidgetSize(), FramerateWindow::UpdateWidgetSize(), VehicleGroupWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), MusicWindow::UpdateWidgetSize(), BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize(), NetworkJoinStatusWindow::UpdateWidgetSize(), SpriteAlignerWindow::UpdateWidgetSize(), ScanProgressWindow::UpdateWidgetSize(), TimetableWindow::UpdateWidgetSize(), and TownDirectoryWindow::UpdateWidgetSize().

## ◆ GetParamMaxValue()

uint64_t GetParamMaxValue | ( | uint64_t | max_value,
|  | uint | min_count,
|  | FontSize | size
| ) |  |

Get some number that is suitable for string size computations.

Parameters

  max_value | The biggest value which shall be displayed. For the result only the number of digits of max_value matter.
  min_count | Minimum number of digits independent of max.
  size | Font of the number

Returns
  Number to use for string size computations.

Definition at line 236 of file strings.cpp.

References GetParamMaxDigits().

Referenced by VehicleGroupWindow::ComputeGroupInfoSize(), TimetableWindow::DrawTimetablePanel(), OrdersWindow::DrawWidget(), CompanyFinancesWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), SetDateWindow::UpdateWidgetSize(), DepotWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), GenerateProgressWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), PerformanceRatingDetailWindow::UpdateWidgetSize(), NetworkGameWindow::UpdateWidgetSize(), NetworkJoinStatusWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), ScanProgressWindow::UpdateWidgetSize(), SignListWindow::UpdateWidgetSize(), StatusBarWindow::UpdateWidgetSize(), TimetableWindow::UpdateWidgetSize(), and VehicleDetailsWindow::UpdateWidgetSize().

## ◆ GetSpecialNameString()

static bool GetSpecialNameString | ( | StringBuilder & | builder,
|  | StringID | string,
|  | StringParameters & | args
| ) |  |
| static

Definition at line 1960 of file strings.cpp.

## ◆ GetString()

std::string GetString | ( | StringID | string | ) |

Resolve the given StringID into a std::string with formatting but no parameters.

Parameters

  string | The unique identifier of the translatable string.

Returns
  The std::string of the translated string.

Definition at line 424 of file strings.cpp.

References GetStringWithArgs().

Referenced by Subsidy::AwardTo(), BadgeTextFilter::BadgeTextFilter(), BuildCargoAcceptanceString(), StoryBookWindow::BuildDropDownList(), GameOptionsWindow::BuildDropDownList(), CargoSpecNameSorter(), ClassTagNameFilter(), CmdFoundTown(), CmdGiveMoney(), CmdRenameCompany(), CmdRenamePresident(), CompanyNewsInformation::CompanyNewsInformation(), VehicleGroupWindow::ComputeGroupInfoSize(), CompanyButtonLine::Draw(), ClientButtonLine::Draw(), StationViewWindow::DrawAcceptedCargo(), DrawAircraftDetails(), DrawAircraftPurchaseInfo(), TimetableWindow::DrawArrivalDeparturePanel(), DrawBadgeNameList(), StationViewWindow::DrawCargoRatings(), NetworkContentListWindow::DrawDetails(), FramerateWindow::DrawElementTimesColumn(), DrawEngineList(), StationViewWindow::DrawEntries(), BaseGraphWindow::DrawGraph(), VehicleGroupWindow::DrawGroupInfo(), IndustryViewWindow::DrawInfo(), GoalListWindow::DrawListColumn(), NewGRFInspectWindow::DrawMainPanelWidget(), DrawOrderString(), DrawPrice(), TownAuthorityWindow::DrawRatings(), DrawRoadVehDetails(), NetworkGameWindow::DrawServerLine(), SettingEntry::DrawSetting(), DrawShipDetails(), DrawSmallOrderList(), DrawStationCoverageAreaText(), DrawString(), DrawStringMultiLine(), TimetableWindow::DrawSummaryPanel(), TimetableWindow::DrawTimetablePanel(), SmallMapWindow::DrawTowns(), DrawTrainDetails(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehiclePurchaseInfo(), DrawVehicleRefitWindow(), ReplaceVehicleWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), CompanyWindow::DrawWidget(), BuyCompanyWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), FramerateWindow::DrawWidget(), FrametimeGraphWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), BaseCargoGraphWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), SelectGameWindow::DrawWidget(), PerformanceLeagueWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), LandInfoWindow::DrawWidget(), MusicTrackSelectionWindow::DrawWidget(), MusicWindow::DrawWidget(), BaseNetworkContentDownloadStatusWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), NetworkAskRelayWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), NewsWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), OrdersWindow::DrawWidget(), ScriptListWindow::DrawWidget(), GameOptionsWindow::DrawWidget(), SignListWindow::DrawWidget(), SmallMapWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), StatusBarWindow::DrawWidget(), StoryBookWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), TownViewWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), DrawYearColumn(), EngineNameSorter(), ErrorUnknownCallbackResult(), BuildVehicleWindow::FilterByText(), GenerateCompanyName(), GeneratePresidentName(), BuildBridgeWindow::GetBridgeSelectString(), RefitWindow::GetCapacityString(), EncodedString::GetDecodedString(), VehicleGroupWindow::GetGroupNameString(), StoryBookWindow::GetHeadHeight(), BuildHouseWindow::GetHouseInformation(), BuildHouseWindow::GetHouseYear(), GetKeyboardLayout(), GetListLabel(), NIHVehicle::GetName(), NIHStation::GetName(), NIHHouse::GetName(), NIHIndustryTile::GetName(), NIHIndustry::GetName(), NIHObject::GetName(), NIHRailType::GetName(), NIHAirportTile::GetName(), NIHAirport::GetName(), NIHTown::GetName(), NIHRoadType< TRoadTramType >::GetName(), NIHRoadStop::GetName(), GetPreviewRunningCostString(), GetRailTypeDropDownList(), AIConfigWindow::GetSlotText(), GetStringBoundingBox(), GetStringHeight(), GSConfigWindow::GetText(), TownDirectoryWindow::GetTownString(), GetUnitNumberWidth(), Window::GetWidgetString(), AIConfigWindow::GetWidgetString(), BuildAirportWindow::GetWidgetString(), ReplaceVehicleWindow::GetWidgetString(), BuildVehicleWindow::GetWidgetString(), CompanyFinancesWindow::GetWidgetString(), SelectCompanyLiveryWindow::GetWidgetString(), CompanyInfrastructureWindow::GetWidgetString(), CompanyWindow::GetWidgetString(), BuyCompanyWindow::GetWidgetString(), SetDateWindow::GetWidgetString(), DepotWindow::GetWidgetString(), ErrmsgWindow::GetWidgetString(), FramerateWindow::GetWidgetString(), FrametimeGraphWindow::GetWidgetString(), GenerateLandscapeWindow::GetWidgetString(), CreateScenarioWindow::GetWidgetString(), GoalListWindow::GetWidgetString(), GoalQuestionWindow::GetWidgetString(), IndustryProductionGraphWindow::GetWidgetString(), TownCargoGraphWindow::GetWidgetString(), VehicleGroupWindow::GetWidgetString(), GameManualTextfileWindow::GetWidgetString(), BuildIndustryWindow::GetWidgetString(), IndustryViewWindow::GetWidgetString(), IndustryDirectoryWindow::GetWidgetString(), IndustryCargoesWindow::GetWidgetString(), AboutWindow::GetWidgetString(), QueryStringWindow::GetWidgetString(), MusicTrackSelectionWindow::GetWidgetString(), NetworkChatWindow::GetWidgetString(), ContentTextfileWindow::GetWidgetString(), NetworkStartServerWindow::GetWidgetString(), NetworkClientListWindow::GetWidgetString(), SpriteAlignerWindow::GetWidgetString(), NewGRFParametersWindow::GetWidgetString(), NewGRFTextfileWindow::GetWidgetString(), NewGRFWindow::GetWidgetString(), NewsWindow::GetWidgetString(), BuildObjectWindow::GetWidgetString(), OrdersWindow::GetWidgetString(), OskWindow::GetWidgetString(), BuildRailToolbarWindow::GetWidgetString(), BuildSignalWindow::GetWidgetString(), BuildRoadToolbarWindow::GetWidgetString(), ScriptListWindow::GetWidgetString(), ScriptSettingsWindow::GetWidgetString(), ScriptTextfileWindow::GetWidgetString(), ScriptDebugWindow::GetWidgetString(), BaseSetTextfileWindow::GetWidgetString(), GameOptionsWindow::GetWidgetString(), CustomCurrencyWindow::GetWidgetString(), SignListWindow::GetWidgetString(), SignWindow::GetWidgetString(), SmallMapWindow::GetWidgetString(), CompanyStationsWindow::GetWidgetString(), StationViewWindow::GetWidgetString(), StoryBookWindow::GetWidgetString(), TimetableWindow::GetWidgetString(), ScenarioEditorToolbarWindow::GetWidgetString(), TownAuthorityWindow::GetWidgetString(), TownViewWindow::GetWidgetString(), TownDirectoryWindow::GetWidgetString(), RefitWindow::GetWidgetString(), VehicleListWindow::GetWidgetString(), VehicleDetailsWindow::GetWidgetString(), VehicleViewWindow::GetWidgetString(), ExtraViewportWindow::GetWidgetString(), WaypointWindow::GetWidgetString(), BaseGraphWindow::GetYLabelWidth(), IndustryTypeNameSorter(), BuildIndustryWindow::MakeCargoListString(), NetworkDrawChatMessage(), NetworkHandlePauseChange(), NetworkServerDoMove(), NetworkServerSendChat(), BuildVehicleWindow::OnClick(), CompanyWindow::OnClick(), DepotWindow::OnClick(), GSConfigWindow::OnClick(), GenerateLandscapeWindow::OnClick(), CreateScenarioWindow::OnClick(), IndustryViewWindow::OnClick(), NetworkStartServerWindow::OnClick(), NewGRFParametersWindow::OnClick(), OrdersWindow::OnClick(), ScriptSettingsWindow::OnClick(), CustomCurrencyWindow::OnClick(), StationViewWindow::OnClick(), TextfileWindow::OnClick(), TimetableWindow::OnClick(), TownViewWindow::OnClick(), VehicleViewWindow::OnClick(), WaypointWindow::OnClick(), GenerateLandscapeWindow::OnDropdownSelect(), LandInfoWindow::OnInit(), SignListWindow::OnInit(), SmallMapWindow::OnInit(), BuildAirportWindow::OnPaint(), IConsoleWindow::OnPaint(), GoalListWindow::OnPaint(), EndGameWindow::OnPaint(), HighScoreWindow::OnPaint(), GameOptionsWindow::OnPaint(), StationViewWindow::OnPaint(), CompanyWindow::OnResize(), SelectGameWindow::OnResize(), NewsWindow::OnResize(), GameOptionsWindow::OnResize(), openttd_main(), ReadLanguagePack(), ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(), ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(), StoryBookWindow::RefreshSelectedPage(), SaveHighScoreValue(), SaveHighScoreValueNetwork(), Script_CreateDummy(), ServerNetworkAdminSocketHandler::SendCompanyInfo(), ServerNetworkAdminSocketHandler::SendCompanyUpdate(), ServerNetworkAdminSocketHandler::SendError(), ServerNetworkGameSocketHandler::SendError(), SetDateWindow::ShowDateDropDown(), ShowNewGrfVehicleError(), ShowRefitOptionsList(), ToolbarScenDatePanel(), TownActionRoadRebuild(), TrainDetailsCapacityTab(), TrainDetailsCargoTab(), TrainDetailsInfoTab(), TranslateGRFStrings(), TypeTagNameFilter(), SettingEntry::UpdateFilterState(), SettingsPage::UpdateFilterState(), Sign::UpdateVirtCoord(), Town::UpdateVirtCoord(), Station::UpdateVirtCoord(), Waypoint::UpdateVirtCoord(), ReplaceVehicleWindow::UpdateWidgetSize(), BuildBridgeWindow::UpdateWidgetSize(), BuildVehicleWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), CompanyInfrastructureWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), BuyCompanyWindow::UpdateWidgetSize(), SetDateWindow::UpdateWidgetSize(), DepotWindow::UpdateWidgetSize(), EnginePreviewWindow::UpdateWidgetSize(), SaveLoadWindow::UpdateWidgetSize(), FramerateWindow::UpdateWidgetSize(), FrametimeGraphWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), GenerateProgressWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), BaseCargoGraphWindow::UpdateWidgetSize(), PerformanceRatingDetailWindow::UpdateWidgetSize(), VehicleGroupWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), IndustryDirectoryWindow::UpdateWidgetSize(), PerformanceLeagueWindow::UpdateWidgetSize(), ScriptLeagueWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), MusicTrackSelectionWindow::UpdateWidgetSize(), MusicWindow::UpdateWidgetSize(), BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize(), NetworkGameWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), NetworkJoinStatusWindow::UpdateWidgetSize(), NetworkAskRelayWindow::UpdateWidgetSize(), SpriteAlignerWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), NewGRFWindow::UpdateWidgetSize(), ScanProgressWindow::UpdateWidgetSize(), NewsWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), CustomCurrencyWindow::UpdateWidgetSize(), SignListWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), SelectStationWindow< T >::UpdateWidgetSize(), StatusBarWindow::UpdateWidgetSize(), TimetableWindow::UpdateWidgetSize(), ScenarioEditorToolbarWindow::UpdateWidgetSize(), TownAuthorityWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), VehicleListWindow::UpdateWidgetSize(), VehicleDetailsWindow::UpdateWidgetSize(), VehicleNameSorter(), ViewportAddSignStrings(), ViewportAddStationStrings(), and ViewportAddTownStrings().

## ◆ GetStringPtr()

std::string_view GetStringPtr | ( | StringID | string | ) |

Definition at line 313 of file strings.cpp.

## ◆ GetStringWithArgs() [1/4]

void GetStringWithArgs | ( | StringBuilder & | builder,
|  | StringID | string,
|  | std::span< StringParameter > | params,
|  | uint | case_index,
|  | bool | game_script
| ) |  |

Get a parsed string with most special stringcodes replaced by the string parameters.

Parameters

  builder | The builder of the string.
  string | The ID of the string to parse.
  args | Span of arguments for the string.
  case_index | The "case index". This will only be set when FormatString wants to print the string in a different case.
  game_script | The string is coming directly from a game script.

Definition at line 413 of file strings.cpp.

References GetStringWithArgs().

## ◆ GetStringWithArgs() [2/4]

void GetStringWithArgs | ( | StringBuilder & | builder,
|  | StringID | string,
|  | StringParameters & | args,
|  | uint | case_index,
|  | bool | game_script
| ) |  |

Get a parsed string with most special stringcodes replaced by the string parameters.

Parameters

  builder | The builder of the string.
  string | The ID of the string to parse.
  args | Arguments for the string.
  case_index | The "case index". This will only be set when FormatString wants to print the string in a different case.
  game_script | The string is coming directly from a game script.

Definition at line 336 of file strings.cpp.

References Debug, FormatString(), GenerateTownNameString(), GetGameStringPtr(), GetGRFStringPtr(), StringParameters::GetNextParameter(), GetStringIndex(), GetStringTab(), GetStringWithArgs(), IsInsideMM(), LoadedLanguagePack::langtab_num, SPECSTR_TOWNNAME_START, TEXT_TAB_GAMESCRIPT_START, and TEXT_TAB_NEWGRF_START.

Referenced by AppendStringInPlace(), DecodeEncodedString(), SmallMapWindow::DrawWidget(), FormatString(), GenerateDefaultSaveName(), GetGRFStringWithTextStack(), IndustryDirectoryWindow::GetIndustryString(), GetString(), GetString(), GetStringWithArgs(), GetStringWithArgs(), GetStringWithArgs(), GetTownName(), NetworkHandlePauseChange(), LandInfoWindow::OnInit(), and VehicleDetailsWindow::UpdateWidgetSize().

## ◆ GetStringWithArgs() [3/4]

std::string GetStringWithArgs | ( | StringID | string,
|  | std::span< StringParameter > | args
| ) |  |

Definition at line 461 of file strings.cpp.

## ◆ GetStringWithArgs() [4/4]

std::string GetStringWithArgs | ( | StringID | string,
|  | StringParameters & | args
| ) |  |

Get a parsed string with most special stringcodes replaced by the string parameters.

Parameters

  string | The ID of the string to parse.
  args | Arguments for the string.

Returns
  The parsed string.

Definition at line 453 of file strings.cpp.

References GetStringWithArgs().

## ◆ GetSurname()

static std::string_view GetSurname | ( | uint32_t | seed | ) |
| static

Get the surname of the president with the given seed.

Parameters

  seed | The seed the surname was generated from.

Returns
  The surname.

Definition at line 1933 of file strings.cpp.

References GB().

## ◆ GetSurnameOptions()

static std::span< const std::string_view > GetSurnameOptions | ( |  | ) |
| static

Definition at line 1922 of file strings.cpp.

## ◆ GetVelocityUnits()

static const Units GetVelocityUnits | ( | VehicleType | type | ) |
| static

Get the correct velocity units depending on the vehicle type and whether we're using real-time units.

Parameters

  type | VehicleType to convert velocity for.

Returns
  The Units for the proper vehicle and time mode.

Definition at line 951 of file strings.cpp.

References _settings_game, _units_velocity_calendar, _units_velocity_realtime, lengthof, GameSettings::locale, LocaleSettings::units_velocity, LocaleSettings::units_velocity_nautical, TimerGameEconomy::UsingWallclockUnits(), VEH_AIRCRAFT, and VEH_SHIP.

Referenced by ConvertDisplaySpeedToKmhishSpeed(), ConvertDisplaySpeedToSpeed(), ConvertKmhishSpeedToDisplaySpeed(), ConvertSpeedToDisplaySpeed(), and FormatString().

## ◆ InitializeLanguagePacks()

void InitializeLanguagePacks | ( |  | ) |

Make a list of the available language packs.

Put the data in _languages list.

< Matching the language in the configuration 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 2222 of file strings.cpp.

References _config_language_file, _languages, LanguageMetadata::file, FillLanguageList(), FS2OTTD(), GetCurrentLocale(), LanguagePackHeader::isocode, LANG_DIR, and ReadLanguagePack().

Referenced by openttd_main().

## ◆ ParseStringChoice()

static void ParseStringChoice | ( | StringConsumer & | consumer,
|  | uint | form,
|  | StringBuilder & | builder
| ) |  |
| static

Definition at line 787 of file strings.cpp.

## ◆ ReadLanguagePack()

bool ReadLanguagePack | ( | const LanguageMetadata * | lang | ) |

Read a particular language.

Parameters

  lang | The metadata about the language.

Returns
  Whether the loading went okay or not.

Definition at line 2021 of file strings.cpp.

References _config_language_file, _current_collator, _current_language, _current_text_dir, BuildContentTypeStringList(), BuildIndustriesLegend(), LoadedLanguagePack::ellipsis, LanguageMetadata::file, FS2OTTD(), GetString(), Layouter::Initialize(), InitializeSortedCargoSpecs(), InvalidateWindowClassesData(), LanguagePackHeader::isocode, LoadedLanguagePack::langtab_num, LoadedLanguagePack::langtab_start, LoadedLanguagePack::list_separator, MacOSSetCurrentLocaleName(), LanguagePackHeader::newgrflangid, ReadFileToMem(), ReconsiderGameScriptLanguage(), SetCurrentGrfLangID(), SortIndustryTypes(), TAB_SIZE, LanguagePackHeader::text_dir, TEXT_TAB_END, WC_AIRCRAFT_LIST, WC_BUILD_VEHICLE, WC_INDUSTRY_DIRECTORY, WC_ROADVEH_LIST, WC_SHIPS_LIST, WC_STATION_LIST, and WC_TRAINS_LIST.

Referenced by InitializeLanguagePacks(), and GameOptionsWindow::OnDropdownSelect().

## ◆ SkipStringChoice()

static void SkipStringChoice | ( | StringConsumer & | consumer | ) |
| static

Definition at line 777 of file strings.cpp.

## ◆ StationGetSpecialString()

static void StationGetSpecialString | ( | StringBuilder & | builder,
|  | StationFacilities | x
| ) |  |
| static

Definition at line 1845 of file strings.cpp.

## Variable Documentation

## ◆ _config_language_file

std::string _config_language_file

The file (name) stored in the configuration.

Definition at line 52 of file strings.cpp.

Referenced by InitializeLanguagePacks(), and ReadLanguagePack().

## ◆ _current_collator

std::unique_ptr<icu::Collator> _current_collator

Collator for the language currently in use.

Definition at line 59 of file strings.cpp.

Referenced by ICUStringContains(), ReadLanguagePack(), and StrNaturalCompare().

## ◆ _current_language

const LanguageMetadata* _current_language = nullptr

The currently loaded language.

Definition at line 54 of file strings.cpp.

Referenced by GameOptionsWindow::BuildDropDownList(), SelectGameWindow::DrawWidget(), UnmappedChoiceList::Flush(), GameOptionsWindow::GetWidgetString(), ICUParagraphLayoutFactory::InitializeLayouter(), SelectGameWindow::OnInit(), SelectGameWindow::OnResize(), ReadLanguagePack(), ReconsiderGameScriptLanguage(), ICURun::Shape(), SurveyConfiguration(), and UniscribeItemizeString().

## ◆ _current_text_dir

TextDirection _current_text_dir

Text direction of the currently selected language.

Definition at line 56 of file strings.cpp.

Referenced by AddCargoIconOverlay(), AlignInitialConstructionToolbar(), NWidgetLeaf::ButtonHit(), IndustryCargoesWindow::CalculatePositionInWidget(), CheckForMissingGlyphs(), ClickSliderWidget(), NWidgetMatrix::Draw(), NWidgetLeaf::Draw(), BaseSettingEntry::Draw(), CargoesField::Draw(), CompanyButtonLine::Draw(), ClientButtonLine::Draw(), DrawAircraftImage(), DrawArrowButtons(), DrawBadgeColumn(), DrawBoolButton(), DrawButtonDropdown(), ButtonLine::DrawButtons(), StationViewWindow::DrawCargoIcons(), StationViewWindow::DrawCargoRatings(), DrawCategory(), DrawEngineList(), StationViewWindow::DrawEntries(), DrawFrame(), BaseGraphWindow::DrawGraph(), VehicleGroupWindow::DrawGroupInfo(), DrawImageTextButtons(), IndustryViewWindow::DrawInfo(), DrawLayoutLine(), GoalListWindow::DrawListColumn(), NetworkContentListWindow::DrawMatrix(), DrawOrderString(), TownAuthorityWindow::DrawRatings(), DrawRoadVehImage(), NetworkGameWindow::DrawServerLine(), SettingEntry::DrawSetting(), SettingsPage::DrawSetting(), DrawShipImage(), DrawSliderWidget(), DrawSmallOrderList(), Window::DrawSortButtonState(), TimetableWindow::DrawTimetablePanel(), DrawTrainDetails(), DrawTrainImage(), DrawUpDownButtons(), NewGRFInspectWindow::DrawVehicleChainWidget(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DrawVehicleRefitWindow(), BuildBridgeWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), SelectCompanyManagerFaceWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), DepotWindow::DrawWidget(), GSConfigWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), BaseCargoGraphWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), IndustryCargoesWindow::DrawWidget(), PerformanceLeagueWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), BaseNetworkContentDownloadStatusWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), NewGRFWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), OrdersWindow::DrawWidget(), ScriptSettingsWindow::DrawWidget(), SignListWindow::DrawWidget(), SmallMapWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TextfileWindow::DrawWidget(), TownViewWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), RefitWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), VehicleViewWindow::DrawWidget(), GetAlignedPosition(), GetAutoPlacePosition(), QueryString::GetBoundingRect(), ButtonLine::GetButton(), QueryString::GetCaretPosition(), QueryString::GetCharAtPosition(), Layouter::GetCharPosition(), SmallMapWindow::GetPositionOnLegend(), NWidgetMatrix::GetScrollOffsets(), GetSingleVehicleWidth(), GetToolbarAlignedWindowPosition(), ClientButtonLine::GetTooltip(), NWidgetMatrix::GetWidgetFromPos(), HandleScrollbarHittest(), HandleScrollbarScrolling(), HighlightDragPosition(), Window::InitializeData(), IsGoodAutoPlace2(), ItemizeBidi(), LocalGetWindowPlacement(), Textbuf::MovePos(), ReplaceVehicleWindow::OnClick(), BuildVehicleWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), GSConfigWindow::OnClick(), VehicleGroupWindow::OnClick(), IndustryViewWindow::OnClick(), NewGRFParametersWindow::OnClick(), ScriptSettingsWindow::OnClick(), RefitWindow::OnPaint(), ReadLanguagePack(), Window::ReInit(), ResizeWindow(), ScrollbarClickPositioning(), ScrollRect(), SetMouseCursorVehicle(), NWidgetLeaf::SetupSmallestSize(), ShowDropDownList(), ShowTerraformToolbar(), UniscribeItemizeString(), Textbuf::UpdateCaretPosition(), VehicleGroupWindow::UpdateColumnRects(), DropdownWindow::UpdateSizeAndPosition(), PerformanceRatingDetailWindow::UpdateWidgetSize(), and MusicWindow::UpdateWidgetSize().

## ◆ _initial_name_letters

const char _initial_name_letters[]
| static

Initial value:
= {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W',
}

Definition at line 1917 of file strings.cpp.

## ◆ _langpack

LoadedLanguagePack _langpack
| static

Definition at line 291 of file strings.cpp.

## ◆ _languages

LanguageList _languages

The actual list of language meta data.

Definition at line 53 of file strings.cpp.

Referenced by GameOptionsWindow::BuildDropDownList(), FillLanguageList(), GetLanguage(), InitializeLanguagePacks(), and GameOptionsWindow::OnDropdownSelect().

## ◆ _scan_for_gender_data

bool _scan_for_gender_data = false
| static

Are we scanning for the gender of the current string? (instead of formatting it)

Definition at line 293 of file strings.cpp.

Referenced by FormatString().

## ◆ _silly_company_names

const std::string_view _silly_company_names[]
| static

Initial value:
= {
"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 1854 of file strings.cpp.

## ◆ _silly_surname_list

const std::string_view _silly_surname_list[]
| static

Initial value:
= {
"Grumpy",
"Dozy",
"Speedy",
"Nosey",
"Dribble",
"Mushroom",
"Cabbage",
"Sniffle",
"Fishy",
"Swindle",
"Sneaky",
"Nutkins"
}

Definition at line 1902 of file strings.cpp.

## ◆ _surname_list

const std::string_view _surname_list[]
| static

Definition at line 1870 of file strings.cpp.

## ◆ _units_force

const Units _units_force[]
| static

Initial value:
= {
{ { 0.224809 }, STR_UNITS_FORCE_IMPERIAL, 0 },
{ { 0.101972 }, STR_UNITS_FORCE_METRIC, 0 },
{ { 0.001 }, STR_UNITS_FORCE_SI, 0 },
}

Unit conversions for force.

Definition at line 908 of file strings.cpp.

Referenced by FormatString().

## ◆ _units_height

const Units _units_height[]
| static

Initial value:
= {
{ { 3.0 }, STR_UNITS_HEIGHT_IMPERIAL, 0 },
{ { 1.0 }, STR_UNITS_HEIGHT_METRIC, 0 },
{ { 1.0 }, STR_UNITS_HEIGHT_SI, 0 },
{ { .02 }, STR_UNITS_HEIGHT_GAMEUNITS,0 },
}

Unit conversions for height.

Definition at line 915 of file strings.cpp.

Referenced by FormatString().

## ◆ _units_power

const Units _units_power[]
| static

Initial value:
= {
{ { 1.0 }, STR_UNITS_POWER_IMPERIAL, 0 },
{ { 1.01387 }, STR_UNITS_POWER_METRIC, 0 },
{ { 0.745699 }, STR_UNITS_POWER_SI, 0 },
}

Unit conversions for power.

Definition at line 874 of file strings.cpp.

Referenced by FormatString().

## ◆ _units_power_to_weight

const Units _units_power_to_weight[]
| static

Initial value:
= {
{ { 0.907185 }, STR_UNITS_POWER_IMPERIAL_TO_WEIGHT_IMPERIAL, 1 },
{ { 1.0 }, STR_UNITS_POWER_IMPERIAL_TO_WEIGHT_METRIC, 1 },
{ { 1.0 }, STR_UNITS_POWER_IMPERIAL_TO_WEIGHT_SI, 1 },
{ { 0.919768 }, STR_UNITS_POWER_METRIC_TO_WEIGHT_IMPERIAL, 1 },
{ { 1.01387 }, STR_UNITS_POWER_METRIC_TO_WEIGHT_METRIC, 1 },
{ { 1.01387 }, STR_UNITS_POWER_METRIC_TO_WEIGHT_SI, 1 },
{ { 0.676487 }, STR_UNITS_POWER_SI_TO_WEIGHT_IMPERIAL, 1 },
{ { 0.745699 }, STR_UNITS_POWER_SI_TO_WEIGHT_METRIC, 1 },
{ { 0.745699 }, STR_UNITS_POWER_SI_TO_WEIGHT_SI, 1 },
}

Unit conversions for power to weight.

Definition at line 881 of file strings.cpp.

Referenced by FormatString().

## ◆ _units_time_days_or_seconds

const Units _units_time_days_or_seconds[]
| static

Initial value:
= {
{ { 1 }, STR_UNITS_DAYS, 0 },
{ { 2 }, STR_UNITS_SECONDS, 0 },
}

Unit conversions for time in calendar days or wallclock seconds.

Definition at line 923 of file strings.cpp.

Referenced by FormatString().

## ◆ _units_time_months_or_minutes

const Units _units_time_months_or_minutes[]
| static

Initial value:
= {
{ { 1 }, STR_UNITS_MONTHS, 0 },
{ { 1 }, STR_UNITS_MINUTES, 0 },
}

Unit conversions for time in calendar months or wallclock minutes.

Definition at line 929 of file strings.cpp.

Referenced by FormatString().

## ◆ _units_time_years_or_minutes

const Units _units_time_years_or_minutes[]
| static

Initial value:
= {
{ { 1 }, STR_UNITS_YEARS, 0 },
{ { 12 }, STR_UNITS_MINUTES, 0 },
}

Unit conversions for time in calendar years or wallclock minutes.

Definition at line 941 of file strings.cpp.

Referenced by FormatString().

## ◆ _units_time_years_or_periods

const Units _units_time_years_or_periods[]
| static

Initial value:
= {
{ { 1 }, STR_UNITS_YEARS, 0 },
{ { 1 }, STR_UNITS_PERIODS, 0 },
}

Unit conversions for time in calendar years or economic periods.

Definition at line 935 of file strings.cpp.

Referenced by FormatString().

## ◆ _units_velocity_calendar

const Units _units_velocity_calendar[]
| static

Initial value:
= {
{ { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 },
{ { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 },
{ { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 },
{ { 0.578125 }, STR_UNITS_VELOCITY_GAMEUNITS_DAY, 1 },
{ { 0.868976 }, STR_UNITS_VELOCITY_KNOTS, 0 },
}

Unit conversions for velocity.

Definition at line 856 of file strings.cpp.

Referenced by GetVelocityUnits().

## ◆ _units_velocity_realtime

const Units _units_velocity_realtime[]
| static

Initial value:
= {
{ { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 },
{ { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 },
{ { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 },
{ { 0.289352 }, STR_UNITS_VELOCITY_GAMEUNITS_SEC, 1 },
{ { 0.868976 }, STR_UNITS_VELOCITY_KNOTS, 0 },
}

Unit conversions for velocity.

Definition at line 865 of file strings.cpp.

Referenced by GetVelocityUnits().

## ◆ _units_volume

const UnitsLong _units_volume[]
| static

Initial value:
= {
{ { 264.172 }, STR_UNITS_VOLUME_SHORT_IMPERIAL, STR_UNITS_VOLUME_LONG_IMPERIAL, 0 },
{ { 1000.0 }, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, 0 },
{ { 1.0 }, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI, 0 },
}

Unit conversions for volume.

Definition at line 901 of file strings.cpp.

Referenced by FormatString().

## ◆ _units_weight

const UnitsLong _units_weight[]
| static

Initial value:
= {
{ { 1.102311 }, STR_UNITS_WEIGHT_SHORT_IMPERIAL, STR_UNITS_WEIGHT_LONG_IMPERIAL, 0 },
{ { 1.0 }, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC, 0 },
{ { 1000.0 }, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI, 0 },
}

Unit conversions for weight.

Definition at line 894 of file strings.cpp.

Referenced by FormatString().