Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

Used for string localisation (translation in to other languages)...

 

Syntax

Code Block
themeRDark
languagejavascript
linenumberstrue
var localisedStr = _("string");

Parameters

ParameterTypeMandatoryNotesGame Version
"string"String literal(tick)

The string to translate. Must be a primitive, string literal.

See Notes section below for more details as to why.

3.1 Beta 1

Return values

ValueTypeNotesGame Version
<localisedStr>String

The localised version of the str.

If no localised version of str exists, str will be returned.

3.1 Beta 1

Notes

Localisation happens in two stages.

The first stage is part of the design/build process, and uses _() merely as a marker for strings that need localisation:

  • A 'gettext' script parses files looking for occurrences of _("some string") – it adds each string it finds to a .po file
  • The .po files are used by translators to create localised versions of the strings
  • The .po files are then compiled in to .mo files that are bundled with the game

For this reason, you can't use variables or constants inside of _(), because that would confuse the gettext script.

Then, at run-time, the _() actually does the localisation:

  • Looks for the string in the relevant .mo file
  • If found, returns the localised string
  • If not found, returns the original string

Currently there's no way to determine what language other players in an MP game speak, and there's no way to specify a target locale in the _() function. See related forum topics for more information.

If you want to know more about localising Warzone 2100, view the official translations topic in the forums.

Example

Code Block
themeRDark
languagejavascript
linenumberstrue
console(_("hello world")); // translate "hello world" in to user's language
Div
classbox suggest

Thanks to everyone in the forums who helped explain the workings of this function!

Div
classbox
Availability
Status
colourYellow
title3.1 b1+

Requires:

  • Warzone 3.1 Beta 1 or above
Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5