# strings.cpp File Reference

Handling of translated strings. More...

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "currency.h"`
`#include "spritecache.h"`
`#include "namegen_func.h"`
`#include "station_base.h"`
`#include "town.h"`
`#include "screenshot.h"`
`#include "waypoint.h"`
`#include "industry.h"`
`#include "newgrf_text.h"`
`#include "music.h"`
`#include "fileio_func.h"`
`#include "group.h"`
`#include "newgrf_townname.h"`
`#include "signs_base.h"`
`#include "cargotype.h"`
`#include "fontcache.h"`
`#include "gui.h"`
`#include "strings_func.h"`
`#include "rev.h"`
`#include "core/endian_func.hpp"`
`#include "date_func.h"`
`#include "vehicle_base.h"`
`#include "company_func.h"`
`#include "video/video_driver.hpp"`
`#include "engine_base.h"`
`#include "strgen/strgen.h"`
`#include "gfx_func.h"`
`#include "table/strings.h"`
`#include "table/control_codes.h"`

Go to the source code of this file.

## Data Structures

struct | LanguagePack
struct | Units

## Functions

static char * | StationGetSpecialString (char *buff, int x, const char *last)
static char * | GetSpecialTownNameString (char *buff, int ind, uint32 seed, const char *last)
static char * | GetSpecialNameString (char *buff, int ind, const int64 *argv, const char *last)
static char * | FormatString (char *buff, const char *str, const int64 *argv, uint casei, const char *last)
static int64 | GetInt64 (const int64 **argv)
| Read an int64 from the argv array.
static int32 | GetInt32 (const int64 **argv)
| Read an int32 from the argv array.
static const int64 * | GetArgvPtr (const int64 **argv, int n)
| Read an array from the argv array.
const char * | GetStringPtr (StringID string)
static char * | GetStringWithArgs (char *buffr, uint string, const int64 *argv, const char *last)
| The highest 8 bits of string contain the "case index".
char * | GetString (char *buffr, StringID string, const char *last)
char * | InlineString (char *buf, StringID string)
void | SetDParamStr (uint n, const char *str)
| This function is used to "bind" a C string to a OpenTTD dparam slot.
void | InjectDParam (uint amount)
static char * | FormatCommaNumber (char *buff, int64 number, const char *last)
static char * | FormatNoCommaNumber (char *buff, int64 number, const char *last)
static char * | FormatHexNumber (char *buff, int64 number, const char *last)
static char * | FormatBytes (char *buff, int64 number, const char *last)
| Format a given number as a number of bytes with the SI prefix.
static char * | FormatYmdString (char *buff, Date date, const char *last)
static char * | FormatMonthAndYear (char *buff, Date date, const char *last)
static char * | FormatTinyOrISODate (char *buff, Date date, StringID str, const char *last)
static char * | FormatGenericCurrency (char *buff, const CurrencySpec *spec, Money number, bool compact, const char *last)
static int | DeterminePluralForm (int64 count)
static const char * | ParseStringChoice (const char *b, uint form, char *dst, int *dstlen)
uint | ConvertSpeedToDisplaySpeed (uint speed)
| Convert the given (internal) speed to the display speed.
uint | ConvertDisplaySpeedToSpeed (uint speed)
| Convert the given display speed to the (internal) speed.
static char * | GenAndCoName (char *buff, uint32 arg, const char *last)
static char * | GenPresidentName (char *buff, uint32 x, const char *last)
static void | SortNetworkLanguages ()
bool | ReadLanguagePack (int lang_index)
const char * | GetCurrentLocale (const char *param)
| Determine the current charset based on the environment First check some default values, after this one we passed ourselves and if none exist return the value for $LANG.
int CDECL | StringIDSorter (const void *a, const void *b)
static bool | UniqueLanguageFile (const Language *langs, uint max, const char *language)
| Checks whether the given language is already found.
static bool | GetLanguageFileHeader (const char *file, LanguagePack *hdr)
| Reads the language file header and checks compatability.
static int | GetLanguageList (Language *langs, int start, int max, const char *path)
| Gets a list of languages from the given directory.
void | InitializeLanguagePacks ()
| Make a list of the available language packs.
void | CheckForMissingGlyphsInLoadedLanguagePack ()
| Check whether the currently loaded language pack uses characters that the currently loaded font does not support.

## Variables

DynamicLanguages | _dynlang
uint64 | _decode_parameters [20]
static char ** | _langpack_offs
static LanguagePack * | _langpack
static uint | _langtab_num [32]
static uint | _langtab_start [32]
static const Units | units []
static const char *const | _silly_company_names []
static const char *const | _surname_list []
static const char *const | _silly_surname_list []
static const char | _initial_name_letters []

## Detailed Description

Handling of translated strings.

Definition in file strings.cpp.

## Function Documentation

void CheckForMissingGlyphsInLoadedLanguagePack | ( |  | ) |

Check whether the currently loaded language pack uses characters that the currently loaded font does not support.

If this is the case an error message will be shown in English. The error message will not be localized because that would mean it might use characters that are not in the font, which is the whole reason this check has been added.

Definition at line 1550 of file strings.cpp.

References GetGlyph(), INVALID_STRING_ID, LoadStringWidthTable(), SetDParamStr(), TD_LTR, and DynamicLanguages::text_dir.

uint ConvertDisplaySpeedToSpeed | ( | uint | speed | ) |

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

Parameters:

  | speed | the speed to convert

Returns:
  the converted speed.

Definition at line 577 of file strings.cpp.

References _settings_game, GameSettings::locale, and LocaleSettings::units.

uint ConvertSpeedToDisplaySpeed | ( | uint | speed | ) |

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

Parameters:

  | speed | the speed to convert

Returns:
  the converted speed.

Definition at line 567 of file strings.cpp.

References _settings_game, GameSettings::locale, and LocaleSettings::units.

static char* FormatBytes | ( | char * | buff,
|  | int64 | number,
|  | const char * | last |
| ) |  |  | `[static]`

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

Parameters:

  | buff | the buffer to write to
  | number | the number of bytes to write down
  | last | the last element in the buffer

Returns:
  till where we wrote

Definition at line 266 of file strings.cpp.

References lengthof, and seprintf().

static const int64* GetArgvPtr | ( | const int64 ** | argv,
|  | int | n |
| ) |  |  | `[inline, static]`

Read an array from the argv array.

Definition at line 71 of file strings.cpp.

const char* GetCurrentLocale | ( | const char * | param | ) |

Determine the current charset based on the environment First check some default values, after this one we passed ourselves and if none exist return the value for $LANG.

Parameters:

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

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

Definition at line 1364 of file strings.cpp.

Referenced by InitializeLanguagePacks().

static int32 GetInt32 | ( | const int64 ** | argv | ) | `[inline, static]`

Read an int32 from the argv array.

Definition at line 65 of file strings.cpp.

References GetInt64().

Referenced by GetStringWithArgs().

static int64 GetInt64 | ( | const int64 ** | argv | ) | `[inline, static]`

Read an int64 from the argv array.

Definition at line 58 of file strings.cpp.

Referenced by GetInt32().

static bool GetLanguageFileHeader | ( | const char * | file,
|  | LanguagePack * | hdr |
| ) |  |  | `[static]`

Reads the language file header and checks compatability.

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 1420 of file strings.cpp.

Referenced by GetLanguageList(), and InitializeLanguagePacks().

static int GetLanguageList | ( | Language * | langs,
|  | int | start,
|  | int | max,
|  | const char * | path |
| ) |  |  | `[static]`

Gets a list of languages from the given directory.

Parameters:

  | langs | the list to write to
  | start | the initial offset in the list
  | max | the length of the language list
  | path | the base directory to search in

Returns:
  the number of added languages

Definition at line 1445 of file strings.cpp.

References Language::file, FS2OTTD(), GetLanguageFileHeader(), ttd_opendir(), and UniqueLanguageFile().

Referenced by InitializeLanguagePacks().

static char* GetStringWithArgs | ( | char * | buffr,
|  | uint | string,
|  | const int64 * | argv,
|  | const char * | last |
| ) |  |  | `[static]`

The highest 8 bits of string contain the "case index".

These 8 bits will only be set when FormatString wants to print the string in a different case. No one else except FormatString should set those bits, therefore string CANNOT be StringID, but uint32.

Parameters:

  | buffr |
  | string |
  | argv |
  | last |

Returns:
  a formatted string of char

Definition at line 101 of file strings.cpp.

References error, GB(), GetGRFStringID(), GetInt32(), and HasBit().

void InitializeLanguagePacks | ( |  | ) |

Make a list of the available language packs.

put the data in _dynlang struct.

< Matching the language in the configuartion file or the current locale

< Using pt_PT for pt_BR locale when pt_BR is not available

< Fallback when no locale-matching language has been found

Definition at line 1482 of file strings.cpp.

References DynamicLanguages::curr_file, DynamicLanguages::ent, Language::file, FOR_ALL_SEARCHPATHS, GetCurrentLocale(), GetLanguageFileHeader(), GetLanguageList(), LANG_DIR, lengthof, MAX_LANG, Language::name, DynamicLanguages::num, and usererror().

void SetDParamStr | ( | uint | n,
|  | const char * | str |
| ) |  |  |

This function is used to "bind" a C string to a OpenTTD dparam slot.

Parameters:

  | n | slot of the string
  | str | string to bind

Definition at line 172 of file strings.cpp.

Referenced by CheckForMissingGlyphsInLoadedLanguagePack(), CmdCompanyCtrl(), GetSaveLoadErrorString(), IndustryProductionCallback(), NewGRFWindow::OnClick(), StationViewWindow::OnPaint(), NewGRFWindow::OnPaint(), AIConfigWindow::OnPaint(), AIListWindow::OnPaint(), SaveFileError(), ShowNewGrfVehicleError(), ShowRefitOptionsList(), StartScenario(), and WarnCorruptSprite().

static bool UniqueLanguageFile | ( | const Language * | langs,
|  | uint | max,
|  | const char * | language |
| ) |  |  | `[static]`

Checks whether the given language is already found.

Parameters:

  | langs | languages we've found so fa
  | max | the length of the language list
  | language | name of the language to check

Returns:
  true if and only if a language file with the same name has not been found

Definition at line 1404 of file strings.cpp.

Referenced by GetLanguageList().

## Variable Documentation

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 1188 of file strings.cpp.

const char* const _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 1125 of file strings.cpp.

const char* const _silly_surname_list[]`[static]`

Initial value:

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

Definition at line 1173 of file strings.cpp.

const Units units[]`[static]`

Initial value:

     {
      {
           1,  0, STR_UNITS_VELOCITY_IMPERIAL,
           1,  0, STR_UNITS_POWER_IMPERIAL,
           1,  0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
        1000,  0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
           1,  0, STR_UNITS_FORCE_SI,
      },
      {
         103,  6, STR_UNITS_VELOCITY_METRIC,
           1,  0, STR_UNITS_POWER_METRIC,
           1,  0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
        1000,  0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
           1,  0, STR_UNITS_FORCE_SI,
      },
      {
        1831, 12, STR_UNITS_VELOCITY_SI,
         764, 10, STR_UNITS_POWER_SI,
        1000,  0, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI,
           1,  0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI,
           1,  0, STR_UNITS_FORCE_SI,
      },
    }

Definition at line 538 of file strings.cpp.