The Translator class, located in data/scripts/translator.lua, provides a Gettext-based translator system. It also provides a variable LanguageTranslator of this type. The functions, unless specicially stated, are class functions.

Don’t Starve uses a custom and simplified Gettext parser and thus may not work as expected with gettext editors like POedit and Emacs. It only escapes \n, \r and ". Not even \\ is escaped, causing problems when you want a literal \n (luckily the need for it would be quite rare unless someone is writing a programming tutorials mod or so.)

The one-liner ksh/bash command tr '\a\b\f\t\v' $'\a\b\f\t\v' < foo.po > foo_dst.po should be able to translate common escape characters produced by the editor. For other escapes, try asking your editor to store them in raw UTF-8 literals.


The class constructer initializes a class Translator, with these properties:

  • languages: {}, k-v of lang to k-v of msgid to msgstr. msgid and msgstr are still escaped forms.
  • defaultlang: nil, string.
  • dbfile: nil,"debugfile.txt", "w") file descripter.

LoadPOFile(fname, lang)

This function loads a gettext po file of the given language, by appending (and overriding) the msgid msgstr pairs to the table. Note that it parses the gettext file by itself. It will finally set the defaultlang to the currently supplied lang, which should be taken special care of.

GetTranslatedString(strid, lang)

This function returns ConvertEscapeCharactersToRaw(self.languages[lang][strid]). If nothing is found in any step of it, it returns nil.


This functions uses naive gsubs to convert \n, \r and " to \\n, \\r, \\" respectively.


This function does the reverse, and is naive too.

Other functions defined in this file


This function is called by strings.lua and translates the STRINGS table to the supplied tbl, using the local function DoTranslateStringTable("STRINGS", tbl).

local DoTranslateStringTable(base, tbl)

This function takes the base as the top node, and recurses to each of its node to perform translation. When the node is not a table, it tries to get the translated string and add its value and position on tree to tbl if it’s not nil or "".