OpenTTD Source 20260218-master-g2123fca5ea
game_text.cpp File Reference

Implementation of handling translated strings. More...

#include "../stdafx.h"
#include "../strgen/strgen.h"
#include "../debug.h"
#include "../fileio_func.h"
#include "../tar_type.h"
#include "../script/squirrel_class.hpp"
#include "../strings_func.h"
#include "game_text.hpp"
#include "game.hpp"
#include "game_info.hpp"
#include "table/strings.h"
#include "../table/strgen_tables.h"
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

struct  StringListReader
 A reader that simply reads using fopen. More...
struct  TranslationWriter
 Class for writing an encoded language. More...
struct  StringNameWriter
 Class for writing the string IDs. More...
class  LanguageScanner
 Scanner to find language files in a GameScript directory. More...

Functions

void StrgenWarningI (const std::string &msg)
void StrgenErrorI (const std::string &msg)
void StrgenFatalI (const std::string &msg)
LanguageStrings ReadRawLanguageStrings (const std::string &file)
 Read all the raw language strings from the given file.
static std::shared_ptr< GameStringsLoadTranslations ()
 Load all translations that we know of.
static StringParam::ParamType GetParamType (const CmdStruct *cs)
static void ExtractStringParams (const StringData &data, StringParamsList &params)
std::string_view GetGameStringPtr (StringIndexInTab id)
 Get the string pointer of a particular game string.
const StringParams & GetGameStringParams (StringIndexInTab id)
 Get the string parameters of a particular game string.
const std::string & GetGameStringName (StringIndexInTab id)
 Get the name of a particular game string.
void RegisterGameTranslation (Squirrel &engine)
 Register the current translation to the Squirrel engine.
void ReconsiderGameScriptLanguage ()
 Reconsider the game script language, so we use the right one.

Variables

std::shared_ptr< GameStrings_current_gamestrings_data = nullptr
 The currently loaded game strings.

Detailed Description

Implementation of handling translated strings.

Definition in file game_text.cpp.

Function Documentation

◆ ExtractStringParams()

void ExtractStringParams ( const StringData & data,
StringParamsList & params )
static

Definition at line 262 of file game_text.cpp.

◆ GetGameStringName()

const std::string & GetGameStringName ( StringIndexInTab id)

Get the name of a particular game string.

Parameters
idThe ID of the game string.
Returns
The name of the string.

Definition at line 345 of file game_text.cpp.

References _current_gamestrings_data.

◆ GetGameStringParams()

const StringParams & GetGameStringParams ( StringIndexInTab id)

Get the string parameters of a particular game string.

Parameters
idThe ID of the game string.
Returns
The string parameters.

Definition at line 331 of file game_text.cpp.

References _current_gamestrings_data.

◆ GetGameStringPtr()

std::string_view GetGameStringPtr ( StringIndexInTab id)

Get the string pointer of a particular game string.

Parameters
idThe ID of the game string.
Returns
The encoded string.

Definition at line 320 of file game_text.cpp.

References _current_gamestrings_data.

Referenced by GetStringWithArgs().

◆ GetParamType()

StringParam::ParamType GetParamType ( const CmdStruct * cs)
static

Definition at line 255 of file game_text.cpp.

◆ LoadTranslations()

std::shared_ptr< GameStrings > LoadTranslations ( )
static

Load all translations that we know of.

Returns
Container with all (compiled) translations.

Definition at line 205 of file game_text.cpp.

References LanguageScanner::AddFile(), FioCheckFileExists(), GAME_DIR, Game::GetInfo(), ScriptInfo::GetMainScript(), ScriptInfo::GetTarFile(), ReadRawLanguageStrings(), and LanguageScanner::Scan().

Referenced by RegisterGameTranslation().

◆ ReadRawLanguageStrings()

LanguageStrings ReadRawLanguageStrings ( const std::string & file)

Read all the raw language strings from the given file.

Parameters
fileThe file to read from.
Returns
The raw strings, or nullptr upon error.

Definition at line 49 of file game_text.cpp.

References FioFOpenFile(), GAME_DIR, LanguageStrings::lines, and StringConsumer::WHITESPACE_OR_NEWLINE.

Referenced by LanguageScanner::AddFile(), and LoadTranslations().

◆ ReconsiderGameScriptLanguage()

void ReconsiderGameScriptLanguage ( )

Reconsider the game script language, so we use the right one.

Definition at line 386 of file game_text.cpp.

References _current_gamestrings_data, _current_language, and FS2OTTD().

Referenced by GSTRChunkHandler::Load(), ReadLanguagePack(), and RegisterGameTranslation().

◆ RegisterGameTranslation()

void RegisterGameTranslation ( Squirrel & engine)

Register the current translation to the Squirrel engine.

Parameters
engineThe engine to update/

Definition at line 358 of file game_text.cpp.

References _current_gamestrings_data, Squirrel::GetVM(), LoadTranslations(), and ReconsiderGameScriptLanguage().

Referenced by GameInstance::RegisterAPI().

◆ StrgenErrorI()

void StrgenErrorI ( const std::string & msg)

Definition at line 32 of file game_text.cpp.

◆ StrgenFatalI()

void StrgenFatalI ( const std::string & msg)

Definition at line 38 of file game_text.cpp.

◆ StrgenWarningI()

void StrgenWarningI ( const std::string & msg)

Definition at line 26 of file game_text.cpp.

Variable Documentation

◆ _current_gamestrings_data

std::shared_ptr<GameStrings> _current_gamestrings_data = nullptr