Translation
It is possible to translate all the text in TTT to a different language. The translation system predates Gmod’s current translation system, so it’s entirely separate. When a translation is installed on the server, all players can then select the language of their preference in-game without a need to reconnect or restart.
This page explains some things about language files, and the practical side of translating.
I’m writing this under the assumption that you don’t have Lua or programming experience. If you do, you probably don’t need this guide.
Getting started
I’ll be calling a translation of TTT a language in this guide, for convenience. A TTT language is a Lua file containing all the text in the game.
Editor
Translating involves changing a lot of text between quotes ("
), so it can be easy to accidentally delete a quote, which will cause errors in-game. An editor that knows about Lua can help you keep track of the quotes, for example Notepad++. It will color the text so you can easily see it when something is wrong. Other editors are VSCode, Atom, Sublime, etc.
It’s free and easy to install and use, so from here on I will assume you are either using an editor like Notepad++, or you really know what you’re doing (ie. you are already familiar with Lua etc).
Language file
It’s convenient to start from the English language file, and just replace all the English text with translations. If you have a server or know someone who does, you can get the English language file from: \garrysmod\gamemodes\terrortown\gamemode\lang\english.lua
You can also find it in the Gmod github here.
So to start your translation, copy and rename that file. Open it in Notepad++ and read on.
Language basics
Defining a language
You will notice this line at the beginning:
local L = LANG.CreateLanguage("English")
It essentially tells TTT that there is a language in this file, namely English. Change the “English” to the name of your language. This is also the language name that players will see in the settings menu. I’ll use “Dutch” here for the example:
local L = LANG.CreateLanguage("Dutch")
You could now skip to the “Installation” section and select your language in-game. The above is all you need for the language to exist. Of course, all the text will still be English.
One last thing of note before we start translating: certain lines start with a bunch of dashes. Notepad++ will color them green. For example:
--- General text used in various places
These are comments that are ignored by the game, they’re only there as information for you. You can modify them, delete them, whatever you want.
Translating basic text
All the lines with pieces of text that make up the language start with something like:
L.traitor = ...
That part you should not touch. The text you should translate is between quotes, like Traitor
below:
L.traitor = "Traitor"
This is probably obvious. I’m just making sure. Here I’ve translated it to Dutch:
L.traitor = "Verrader"
That’s all there is to it.
Translating with parameters
Certain pieces of text have a bit more to them, however. Like the ones with parameters in curly brackets, such as {amount}
. TTT will search for those and replace them with a piece of dynamic information when it shows the text in-game, like the name of a player, or a time, or the number of credits involved. You can move them around, change their order, and even delete them (not sure why you’d do that). However: don’t translate them. TTT won’t be able to find and use them if you do.
Let’s look at an example:
L.credit_kill = "You have received {num} credit(s) for killing a {role}."
Two parameters: {num}
and {role}
. The first is the number of credits the player received, and the second is the role of the player he killed (like “Traitor”). Both Detectives and Traitors can get credits for killing one of the other side. If a Detective kills a Traitor, and the server has configured that he’ll get 2 credits, then {num}
becomes 2, and {role}
becomes Traitor.
Translating to Dutch:
L.credit_kill = "Je hebt een {role} gedood, daar krijg je {num} credit(s) voor!"
Note how I changed the order of the parameters. That’s just for the example, but some languages are very specific about word order, so it may come in useful there. Of course, the parameters are still in curly brackets and not translated.
Just to see parameters at work, this is how it would appear in-game with that Detective-killing-Traitor scenario I described above:
Je hebt een Verrader gedood, daar krijg je 2 credit(s) voor!
Notice how for the {role}
parameter it automatically used the translation of Traitor that I made earlier in the guide (“Verrader”).
Translating longer text
Some text in TTT spans a few lines and still has to fit in a menu properly. We want to be able to specify where it should start a new line, so we can have two blank lines and such. We can’t do that nicely with plain quotes, because Lua will be hard to deal with. Instead, we have to use square brackets like so:
L.item_armor_desc = [[
Reduces bullet damage by 30% when
you get hit.
Default equipment for Detectives.]]
Instead of “some text” it is now [[some text]]. Additionally, you may recognize how it looks similar to the way the Body Armor item description looks in the equipment menu in the game. The area for the description in that menu is a bit narrow, so a new line starts after ‘when’. Then below that there’s a blank line, which will also be there in-game. What you see is what you get.
Perceptive readers may notice that the first line break, right after [[, is not shown in-game. That’s a handy Lua feature, it ignores the line break if it comes right after opening brackets.
If you translate text in square brackets, you can experiment a bit with how long a line of text can be before it gets cut off in-game. Or you can try and keep the lines the same length as the English text.
There are only a few places where you need to bother with manual line breaks, mainly the equipment menu descriptions. It’s a hassle but you have full control on how it will look in-game.
Special characters (accents, umlauts, etc)
If you use special characters like “äéöü” and such in your language, then you need to make sure the file has the correct encoding for Source to be able to display them. If you don’t already know what encodings and unicode and such is, then believe me: you don’t want to know. Let’s just look at the setting you need to change.
In Notepad++, if you open the “Encoding” menu at the top, you should see a menu with various “Encode in …” and “Convert to …” options. One of them is shown as selected, most likely “Encode in ANSI”. If you use special characters, the encoding needs to be “UTF-8 without BOM”, so select “Convert to UTF-8 without BOM”. Then save your file. Now if you open the Encoding menu again you should see “Encode in UTF-8 without BOM” selected. If not, your file probably does not have special characters in it.
You will be able to do similar things in other code editors as long as you can find a way to save the file encoded as UTF-8 without BOM (you may have to look at the documentation).
Installation
You should now have a file called something like “dutch.lua”, but with a different language name. The filename doesn’t really matter, but it’s convenient. You can make it “dutch_by_xOxrobbie1991xOx.lua” as well, the game won’t care.
That file needs to be on the server, in this directory:
\garrysmod\gamemodes\terrortown\gamemode\lang\english.lua
The server’s Lua cache will be re-generated when you start the server, so if you use FastDL/sv_downloadurl, then you should upload the new cache there.
Now, if you join the server, you can press F1 and switch to the settings tab, where the dropdown box will have your language in it. Select it and close the menu, and your language is now active. HUD text, like the “traitor/innocent/detective” text in the bottom left, should change immediately.
Server configuration
Servers can specify a default language. All players that have their language setting set to “Server default” (which is TTT’s default setting) will automatically use the language you specify. This allows you to run, for example, a French server where all newbies that join automatically see everything in French.
Use this convar in your server.cfg:
ttt_lang_serverdefault "english"