File: GetTranslatedString.xml

package info (click to toggle)
openclonk 8.1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 169,520 kB
  • sloc: cpp: 180,479; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 145; sh: 101; javascript: 34
file content (59 lines) | stat: -rw-r--r-- 2,398 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
  SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
  <func>
    <title>GetTranslatedString</title>
    <category>Script</category>
    <subcat>Strings</subcat>
    <version>8.0 OC</version>
    <syntax>
      <rtype>string</rtype>
      <params>
        <param>
          <type>any</type>
          <name>string_data</name>
          <desc>Either a string or a proplist containing multiple translations of a string. If a string or <code>nil</code> is passed, the parameter is returned directly. If a proplist is passed, the value corresponding to the selected language (or a fallback) is returned.</desc>
        </param>
      </params>
    </syntax>
    <desc>Returns a string corresponding to the user's selected language. For <code>string_data</code>, the expected format is <code>{ Function="Translate", DE="Hallo, Welt", US="Hello, World"}</code>. If no matching entry is found or it is <code>nil</code>, then another language string is returned as a fallback.</desc>
    <examples>
      <example>
        <code>Log(GetTranslatedString({ Function="Translate", DE="Dies ist ein Test.", US="This is a test."}));</code>
        <text>Logs either "Dies ist ein Test." or "This is a test." depending on the player's language setting.</text>
      </example>
      <example>
				<code>local inscription = "";

// Players can read the sign via the interaction bar.
public func IsInteractable() { return true; }

// Called on player interaction.
public func Interact(object clonk)
{
	if (!clonk) return false;
	Dialogue->MessageBox(GetTranslatedString(inscription), clonk, this, clonk->GetController(), true);
	return true;
}

public func SetInscription(to_text)
{
	inscription = to_text ?? "";
	return true;
}

public func Definition(def)
{
	// Inscription props
	if (!def.EditorProps) def.EditorProps = {};
	def.EditorProps.inscription = { Name="Inscription", Type="string", Set="SetInscription", Save="Inscription", Translatable=true };
}</code>
				<text>Code for a signpost. The string editor property with setting <code>Translatable=true</code> provides a translation proplist in the correct format automatically.</text>
      </example>
    </examples>
    <related><funclink>Translate</funclink></related>
  </func>
  <author>Sven2</author><date>2017-05</date>
</funcs>