Defines the cw.lang library and the global L function, which translate #Phrase identifiers into the player's language.

Language files fill the table returned by cw.lang:GetTable. On the client L translates directly, and surface.DrawText, surface.GetTextSize and Panel:SetText are wrapped to translate phrases automatically; on the server L only builds a #Identifier:arg1,arg2; string for the client to translate. The language follows the cwLanguage console variable, or the game's language when it is empty.

Summary

Methods

Records a language file name for a language in cw.lang.fileList.
GetAll()shared
Returns every language's phrase table.
Returns the language the interface is shown in.
Returns the translation of a phrase in a language.
Returns the phrase table of a language, creating it if it does not exist.
Does nothing; kept so existing calls do not error.
Translates every phrase in a text.

Methods

cw.lang:Add(language, fileName)

shared gamemodes/catwork/gamemode/core/libraries/sh_lang.lua:66

Records a language file name for a language in cw.lang.fileList.

The file is not loaded.

Parameters

  • language String Language code
  • fileName String Path of the language file

Returns every language's phrase table.

Returns

  • Map<Map> Phrase tables keyed by language code

Returns the language the interface is shown in.

Uses the cwLanguage client setting, or the game's gmod_language when it is empty.

Returns

  • String The language code

cw.lang:GetString(language, identifier, arguments)

shared gamemodes/catwork/gamemode/core/libraries/sh_lang.lua:88

Returns the translation of a phrase in a language.

Falls back to English, then to the identifier itself. Each argument replaces the first #key in the text (#1 for the first argument), and every ; is removed from the result.

Parameters

  • language String Language code
  • identifier String Phrase identifier, including the leading #
  • arguments List optional, defaults to nil Values that replace #1, #2...; converted with tostring

Returns

  • String The translated text

Returns the phrase table of a language, creating it if it does not exist.

Language files fill this table with phrases.

local lang = cw.lang:GetTable('en')

lang.name = 'English'
lang['#Gender_Female'] = 'Female'
lang['#RequestFrom'] = 'Request from #1: #2'

Parameters

  • name String Language code, such as 'en' or 'ru'

Returns

  • Map The language's phrase table

Does nothing; kept so existing calls do not error.

Parameters

  • language String Language code, ignored

cw.lang:TranslateText(sText)

client gamemodes/catwork/gamemode/core/libraries/sh_lang.lua:205

Translates every phrase in a text.

Phrases are # followed by letters, digits, _ or .. A phrase followed by : takes its arguments up to the next ;; otherwise it ends at the next space. This always translates, even while surface.NoTranslate is on.

Parameters

  • sText String Text containing phrases

Returns

  • String The text with every phrase translated

Defined in