OpenTTD Source: src/strings_func.h File Reference

OpenTTD Source 15.0-RC2

Data Structures | Functions | Variables
strings_func.h File Reference

Functions related to OTTD's strings. More...

`#include "strings_type.h"`
`#include "gfx_type.h"`
`#include "vehicle_type.h"`

Go to the source code of this file.

## Data Structures
class | MissingGlyphSearcher
| A searcher for missing glyphs. More...

## Functions
StringTab | GetStringTab (StringID str)
| Extract the StringTab from a StringID.
StringIndexInTab | GetStringIndex (StringID str)
| Extract the StringIndex from a StringID.
StringID | MakeStringID (StringTab tab, StringIndexInTab index)
| Create a StringID.
static void | PrepareArgsForNextRun (std::span< StringParameter > args)
| Prepare the string parameters for the next formatting run, resetting the type information.
std::string | GetStringWithArgs (StringID string, std::span< StringParameter > args)
std::string | GetString (StringID string)
| Resolve the given StringID into a std::string with formatting but no parameters.
std::string_view | GetStringPtr (StringID string)
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)
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.
int64_t | PackVelocity (uint speed, VehicleType type)
| Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
uint64_t | GetParamMaxValue (uint64_t max_value, uint min_count=0, FontSize size=FS_NORMAL)
| Get some number that is suitable for string size computations.
uint64_t | GetParamMaxDigits (uint count, FontSize size=FS_NORMAL)
| Get some number that is suitable for string size computations.
void | InitializeLanguagePacks ()
| Make a list of the available language packs.
std::string_view | GetCurrentLanguageIsoCode ()
| Get the ISO language code of the currently loaded language.
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.
template<typename... Args>
auto | MakeParameters (Args &&... args)
| Helper to create the StringParameters with its own buffer with the given parameter values.
template<typename... Args>
std::string | GetString (StringID string, Args &&... args)
| Get a parsed string with most special stringcodes replaced by the string parameters.
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.
static EncodedString | GetEncodedStringIfValid (StringID str)
| Encode a string with no parameters into an encoded string, if the string id is valid.
template<typename... Args>
EncodedString | GetEncodedString (StringID string, const Args &... args)
| Get an encoded string with parameters.
void | CheckForMissingGlyphs (MissingGlyphSearcher *search=nullptr)
| Check whether the currently loaded language pack uses characters that the currently loaded font does not support.

## Variables
TextDirection | _current_text_dir
| Text direction of the currently selected language.

## Detailed Description

Functions related to OTTD's strings.

Definition in file strings_func.h.

## 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().

## ◆ 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().

## ◆ 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().

## ◆ 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() [1/2]

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().

## ◆ GetEncodedString() [2/2]

template<typename... Args>

EncodedString GetEncodedString | ( | StringID | string,
|  | const Args &... | args
| ) |  |

Get an encoded string with parameters.

Parameters

  string | String ID to encode.
  args | The parameters to set.

Returns
  The encoded string.

Definition at line 147 of file strings_func.h.

References GetEncodedStringWithArgs(), and MakeParameters().

## ◆ GetEncodedStringIfValid()

static EncodedString GetEncodedStringIfValid | ( | StringID | str | ) |
| inlinestatic

Encode a string with no parameters into an encoded string, if the string id is valid.

Note
  the return encoded string will be empty if the string id is not valid.

Parameters

  str | String to encode.

Returns
  an EncodedString.

Definition at line 134 of file strings_func.h.

References GetEncodedString(), and INVALID_STRING_ID.

Referenced by ShowErrorMessage().

## ◆ 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 116 of file strings.cpp.

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

## ◆ 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().

## ◆ GetString() [1/2]

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().

## ◆ GetString() [2/2]

template<typename... Args>

std::string GetString | ( | StringID | string,
|  | Args &&... | args
| ) |  |

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

Parameters

  string | String ID to format.
  args | The parameters to set.

Returns
  The parsed string.

Definition at line 119 of file strings_func.h.

References GetStringWithArgs(), and MakeParameters().

## ◆ GetStringIndex()

StringIndexInTab GetStringIndex | ( | StringID | str | ) |
| inline

Extract the StringIndex from a StringID.

Parameters

  str | String identifier

Returns
  StringIndex from str

Definition at line 35 of file strings_func.h.

References GetStringTab(), and TAB_SIZE_BITS.

Referenced by GetStringWithArgs().

## ◆ GetStringPtr()

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

Definition at line 313 of file strings.cpp.

## ◆ GetStringTab()

StringTab GetStringTab | ( | StringID | str | ) |
| inline

Extract the StringTab from a StringID.

Parameters

  str | String identifier

Returns
  StringTab from str

Definition at line 22 of file strings_func.h.

References TAB_SIZE_BITS, TEXT_TAB_GAMESCRIPT_START, and TEXT_TAB_NEWGRF_START.

Referenced by CopyFromOldName(), FormatString(), GetStringIndex(), GetStringWithArgs(), CITYChunkHandler::Load(), and PLYRChunkHandler::LoadCheck().

## ◆ GetStringWithArgs()

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

Definition at line 461 of file strings.cpp.

## ◆ 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().

## ◆ MakeParameters()

template<typename... Args>

auto MakeParameters | ( | Args &&... | args | ) |

Helper to create the StringParameters with its own buffer with the given parameter values.

Parameters

  args | The parameters to set for the to be created StringParameters.

Returns
  The constructed StringParameters.

Definition at line 107 of file strings_func.h.

Referenced by DrawRoadVehDetails(), FormatString(), GetEncodedString(), GetString(), GetTownName(), BuildIndustryWindow::MakeCargoListString(), DepotWindow::OnRightClick(), and VehicleDetailsWindow::UpdateWidgetSize().

## ◆ MakeStringID()

StringID MakeStringID | ( | StringTab | tab,
|  | StringIndexInTab | index
| ) |  |
| inline

Create a StringID.

Parameters

  tab | StringTab
  index | Index of the string within the given tab.

Returns
  StringID composed from tab and index

Definition at line 46 of file strings_func.h.

References TAB_SIZE, TAB_SIZE_BITS, TAB_SIZE_GAMESCRIPT, TAB_SIZE_NEWGRF, TEXT_TAB_END, TEXT_TAB_GAMESCRIPT_START, and TEXT_TAB_NEWGRF_START.

Referenced by AddGRFString(), DecodeEncodedString(), and GetGRFStringID().

## ◆ PackVelocity()

int64_t PackVelocity | ( | uint | speed,
|  | VehicleType | type
| ) |  |
| inline

Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.

Parameters

  speed | Display speed for parameter.
  type | Type of vehicle for parameter.

Returns
  Bit-packed velocity and vehicle type, for use with string parameters.

Definition at line 83 of file strings_func.h.

Referenced by DrawAircraftPurchaseInfo(), VehicleDetailsWindow::DrawWidget(), BuildBridgeWindow::GetBridgeSelectString(), BuildRailToolbarWindow::GetWidgetString(), BuildRoadToolbarWindow::GetWidgetString(), and LandInfoWindow::OnInit().

## ◆ PrepareArgsForNextRun()

static void PrepareArgsForNextRun | ( | std::span< StringParameter > | args | ) |
| inlinestatic

Prepare the string parameters for the next formatting run, resetting the type information.

This is only necessary if parameters are reused for multiple format runs.

Definition at line 63 of file strings_func.h.

Referenced by VehicleDetailsWindow::UpdateWidgetSize().

## Variable Documentation

## ◆ _current_text_dir

TextDirection _current_text_dir
| extern

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().