Difference between revisions of "Lua:translate"

From Cheat Engine
Jump to navigation Jump to search
m (Syntax Highlighting.)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''function''' translate(''String'') ''':''' string
+
[[Category:Lua]]
 +
{{CodeBox|'''function''' translate(''string'') ''':''' string}}
  
Returns a translation of the string. Returns the same string if it can't be found.
+
Returns a translation of the given string.
  
=== Function Parameters ===
+
If no translation can be found, this function returns the original string unchanged.
  
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
===Function Parameters===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
 
!style="width: 80%;background-color:white;" align="left"|Description
 
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
 +
|string
 
|String
 
|String
|string
+
|The string to translate.
|The string to translate
 
 
|}
 
|}
  
 +
===Returns===
 +
string — The translated string, or the original string if no translation could be found.
 +
 +
===Examples===
 +
<syntaxhighlight lang="lua" line>
 +
local text = translate("Health")
 +
 +
print(text)
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="lua" line>
 +
local originalText = "Mana"
 +
local translatedText = translate(originalText)
 +
 +
if translatedText == originalText then
 +
  print("No translation found")
 +
else
 +
  print("Translation: " .. translatedText)
 +
end
 +
</syntaxhighlight>
  
== See also ==
+
{{LuaSeeAlso}}
* [[Lua]]
 
* [[Help_File:Script engine|Script engine]]
 
  
=== Related Functions ===
+
{{Strings}}
* [[translateID]]
 
* [[getTranslationFolder]]
 
* [[loadPOFile]]
 
* [[ansiToUtf8]]
 
* [[utf8ToAnsi]]
 
* [[readString]]
 
* [[writeString]]
 
* [[readStringLocal]]
 
* [[writeStringLocal]]
 
* [[stringToByteTable]]
 
* [[wideStringToByteTable]]
 
* [[byteTableToString]]
 
* [[byteTableToWideString]]
 

Latest revision as of 19:22, 25 June 2026

<> Lua API Reference

function translate(string) : string

Returns a translation of the given string.

If no translation can be found, this function returns the original string unchanged.

Function Parameters[edit]

Parameter Type Description
string String The string to translate.

Returns[edit]

string — The translated string, or the original string if no translation could be found.

Examples[edit]

1 local text = translate("Health")
2 
3 print(text)
1 local originalText = "Mana"
2 local translatedText = translate(originalText)
3 
4 if translatedText == originalText then
5   print("No translation found")
6 else
7   print("Translation: " .. translatedText)
8 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine

String and Encoding Related Lua Functions