Skip to content

Language Module

George Petrou edited this page Aug 4, 2018 · 10 revisions

About this module

This module handles all text localizations used in the gamemode.

Adding a Language:

  • Place the file in garrysmod/addons/[AddonName]/lua/ttt/languages/
  • Name the file with only letters and no spaces, numbers, etc. The file name is used as the unique language identifier so this must be kept simple.
  • To add a phrase and a translation simply do the following: L.myphrase = "text"
    • Note: Put a %s wherever you will be substituting in for text like so:
    • L.myname = "The local player's name is %s"

Overwriting a Language:

  • To completely replace a language simply follow the same steps for adding a language but name the file the same thing as a pre-existing language.
  • Languages built in with the gamemode can be found at terrortwo/gamemode/library/languages/languages/

Adding phrases to a language:

  • Use TTT.Languages.AddPhrase in the TTT.PostLibraryLoaded hook to add a phrase to an already existing language. This can also be used to override existing phrases.

TTT.Languages.AddPhrase("insult", "english", "You smell, why don't you take a shower nerd.")

Using a phrase:

  • To retrieve a translated phrase use TTT.Languages.GetPhrase like so: TTT.Languages.GetPhrase("sb_missing") Translates to "Missing in action" in English.
  • You can also pass varargs as the second parameter to sub in for %s like so: TTT.Languages.GetPhrase("tbutton_help", "K") Translates to "Press K to activate" in English.

Hooks

TTT.Languages.ChangedDefaultLanguage - Client

  • Desc: Ran when the client changes their game's language.
  • Arg One: String, the new language they are using.

TTT.Languages.ChangedServerLanguage - Server

  • Desc: Ran when the server sets what it's default language is.
  • Arg One: String, the new language the server is defaulting to.

Functions

TTT.Languages.GetClientLanguage - Client

  • Returns: String of client's currently set language.

TTT.Languages.GetTable - Client

  • Returns: Table of all available language phrases and their translations for the client's current language.

TTT.Languages.GetPhrase - Client

  • Desc: Given a phrase, gives back a corresponding string of text according to the client's current language.
  • Arg One: String, phrase id.
  • Arg Two: Vararg, if the phrase has any %s in it, these will substitute into the string.
  • Returns: String, translated and with any substitutions.

TTT.Languages.AddPhrase - Client

  • Desc: Adds a new phrase to a given language, needs to be re-added after map changes.
  • Arg One: String, phrase for the translation.
  • Arg Two: String, language ID for what language this phrase is for. You can use the ttt_language_list command to find the available language IDs.
  • Arg Three: String, translated phrase.

TTT.Languages.PhraseExists - Client

  • Desc: Sees if the given phrase exists in the users set language and if their language isn't set to english, optionally also check for an english translation.
  • Arg One: String, phrase to check for existence.
  • Arg Two: (Optional=true) Boolean, if the client's default language isn't English, should we also check English for the given translation.
  • Returns: Boolean, does the given phrase exist.

TTT.Languages.SetServerDefaultLanguage - Server

  • Desc: Sets the server default language.
  • Arg One: String, language ID.
  • Note: Preferably use the ttt_language_default command instead as this has no error checking.

TTT.Languages.IsValid - Shared

  • Desc: Sees if the given language ID is valid.
  • Arg One: String, language ID.
  • Returns: Boolean, is the language ID valid on this server.

TTT.Languages.Initialize - Shared

  • Desc: Initializes the language system. You can call this to update any changes to language files.

TTT.Languages.GetServerDefaultLanguage - Shared

  • Returns: String of current server default language.

Commands

ttt_language - Client

  • Desc: Lets the client's current language. Use 'ttt_language_list' to see available languages.

ttt_language_list - Shared

  • Desc: Prints all available languages on the server.

ttt_language_default - Server

  • Desc: If given no arg, returns the server's default language. If given an arg, sets the server's default language.
  • Arg One: (Optional) If supplied with a valid language ID, this will become the new server default language.

Home

Modules

Clone this wiki locally