OpenTTD
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 <stdarg.h>
#include <memory>
#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 CDECL strgen_warning (const char *s,...)
 
void CDECL strgen_error (const char *s,...)
 
void NORETURN CDECL strgen_fatal (const char *s,...)
 
std::unique_ptr< LanguageStringsReadRawLanguageStrings (const char *file)
 Read all the raw language strings from the given file. More...
 
GameStringsLoadTranslations ()
 Load all translations that we know of. More...
 
const char * GetGameStringPtr (uint id)
 Get the string pointer of a particular game string. More...
 
void RegisterGameTranslation (Squirrel *engine)
 Register the current translation to the Squirrel engine. More...
 
void ReconsiderGameScriptLanguage ()
 Reconsider the game script language, so we use the right one.
 

Variables

GameStrings_current_data = nullptr
 The currently loaded game strings. More...
 

Detailed Description

Implementation of handling translated strings.

Definition in file game_text.cpp.

Function Documentation

◆ GetGameStringPtr()

const char* GetGameStringPtr ( uint  id)

Get the string pointer of a particular game string.

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

Definition at line 335 of file game_text.cpp.

References GameStrings::cur_language.

◆ LoadTranslations()

GameStrings* LoadTranslations ( )

Load all translations that we know of.

Returns
Container with all (compiled) translations.

Definition at line 249 of file game_text.cpp.

References Game::GetInfo(), ScriptInfo::GetMainScript(), lastof, and strecpy().

Referenced by RegisterGameTranslation().

◆ ReadRawLanguageStrings()

std::unique_ptr<LanguageStrings> ReadRawLanguageStrings ( const char *  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 82 of file game_text.cpp.

References FioFOpenFile(), and GAME_DIR.

Referenced by LanguageScanner::AddFile().

◆ RegisterGameTranslation()

void RegisterGameTranslation ( Squirrel engine)

Register the current translation to the Squirrel engine.

Parameters
engineThe engine to update/

Definition at line 345 of file game_text.cpp.

References _current_data, Squirrel::GetVM(), LoadTranslations(), ReconsiderGameScriptLanguage(), and GameStrings::string_names.

Referenced by GameInstance::RegisterAPI().

Variable Documentation

◆ _current_data

GameStrings* _current_data = nullptr

The currently loaded game strings.

Definition at line 328 of file game_text.cpp.

Referenced by RegisterGameTranslation().