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 oflang
to k-v ofmsgid
tomsgstr
.msgid
andmsgstr
are still escaped forms. - defaultlang:
nil
, string. - dbfile:
nil
,io.open("debugfile.txt", "w")
file descripter.
This function loads a gettext po file of the given language. 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.
This function returns ConvertEscapeCharactersToRaw(self.languages[lang][strid])
. If nothing is found in any step of it, it returns nil
.
This functions uses naive gsub
s to convert \\n
, \\r
, \\"
to \n
, \r
and "
respectively.
This function does the reverse, and is naive too.
This function is called by strings.lua
and translates the STRINGS
table to the supplied tbl
,
using the local function DoTranslateStringTable("STRINGS", 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 ""
.