cw.lang class
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
cw.lang.fileList.Methods
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:88Returns 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
nilValues that replace#1,#2...; converted withtostring
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
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