Difference between revisions of "Lua:translate"
Jump to navigation
Jump to search
(Created page with ''''function''' translate(''String'') Returns a translation of the string. Returns the same string if it can't be found. === Function Parameters === {|width="85%" cellpadding="…') |
m (Syntax Highlighting.) |
||
| (6 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | '''function''' translate('' | + | [[Category:Lua]] |
| + | {{CodeBox|'''function''' translate(''string'') ''':''' string}} | ||
| − | Returns a translation of the string | + | Returns a translation of the given string. |
| − | + | If no translation can be found, this function returns the original string unchanged. | |
| − | {|width="85%" cellpadding="10 | + | ===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 | ||
| − | + | |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> | ||
| − | + | {{LuaSeeAlso}} | |
| − | |||
| − | |||
| − | + | {{Strings}} | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 19:22, 25 June 2026
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
String and Encoding Related Lua Functions
Translation and Encoding
String Memory Access
Byte Table Conversions