sloodle_translation_en.lslp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Standard translation script for Sloodle.
  4. // Contains the common, re-usable words and phrases.
  5. //
  6. // The "locstrings" list is pairs of strings.
  7. // The first of each pair is the name, and second is the translation.
  8. //
  9. // This script is part of the Sloodle project.
  10. // Copyright (c) 2008-9 Sloodle (various contributors)
  11. // Released under the GNU GPL v3
  12. //
  13. // Contributors:
  14. // Peter R. Bloomfield
  15. //
  16. // Note: where a translation string contains {{x}} (where x is a number),
  17. // it means that a parameter can be inserted. Please make sure to include these
  18. // parameters in the appropriate location in your translation.
  19. // It may be sensible to add comments after your string to indicate what its parameters mean.
  20. // NOTE: parameter numbering starts at 0 (unlike previous versions, which started at 1).
  21. // Translations can be requested by sending a link message on the SLOODLE_CHANNEL_TRANSLATION_REQUEST channel.
  22. // It is advisable simply to use the "sloodle_translation_request" function provided in this script.
  23. ///// TRANSLATION /////
  24. // Localization batch - indicates the purpose of this file
  25. string mybatch = ""; // Blank - this is the common Sloodle batch
  26. // List of string names and translation pairs.
  27. // The name is the first of each pair, and should not be translated.
  28. // The second of each pair is the translation.
  29. // Additional comments are sometimes given afterward to aid translations.
  30. list locstrings = [
  31. // Common terms
  32. "yes", "Yes",
  33. "no", "No",
  34. "on", "On",
  35. "off", "Off",
  36. "enabled", "Enabled",
  37. "disabled", "Disabled",
  38. // Web-configuration
  39. "webconfigmenu", "Sloodle Web-Configuration Menu\n\n{{0}} = Access web-configuration page\n{{1}} = Download configuration", // Parameters are button labels
  40. "configlink", "Use this link to configure the object.",
  41. "chatserveraddress", "Please chat the address of your Moodle site, without a trailing slash. For example: http://www.yoursite.blah/moodle",
  42. "waitingforserveraddress", "Waiting for Moodle site address.\nPlease chat it on channel 0 or 1.",
  43. "checkingserverat", "Checking Moodle site at:\n{{0}}", // Parameter gives the address of a Moodle site
  44. "sendingconfig", "Sending configuration data...",
  45. "touchforwebconfig", "Touch me to start web-configuration",
  46. // User-centric authorisation
  47. "userauthurl", "Please login to Moodle with this URL to authorize the object for your own use.",
  48. // General connection and authorisation
  49. "readynotconnected", "Ready\n[Not connected]",
  50. "shutdown", "Shutdown",
  51. "connected", "Connected successfully",
  52. "readyconnectedto", "Ready\n[Connected to: {{0}}]", // Parameter should identify what is connected to (e.g. URL of website)
  53. "readyconnectedto:sitecourse", "Ready\n[Site: {{0}}]\n[Course: {{1}}]", // Parameters: site address, course name
  54. "connectionfailed", "Connection failed",
  55. "httperror", "ERROR: HTTP request failed",
  56. "httperror:code", "ERROR: HTTP request failed with code {{0}}",
  57. "httpempty", "ERROR: HTTP response empty",
  58. "httptimeout", "ERROR: HTTP request timed out.",
  59. "servererror", "ERROR: server responded with status code {{0}}",
  60. "notypeid", "ERROR: failed to identify object type ID",
  61. "gottype", "Identified object type as {{0}}", // Parameter gives an object type ID
  62. "failedcheckcompatibility", "ERROR: failed to check compatibility with site",
  63. "badresponseformat", "ERROR: response from server was badly formatted",
  64. "objectauthfailed:code", "ERROR: object authorisation failed with code {{0}}",
  65. "objectconfigfailed:code", "ERROR: object configuration failed with code {{0}}",
  66. "initobjectauth", "Initiating object authorisation...",
  67. "autoreg:newaccount", "A new Moodle account has been automatically generated for you.\nWebsite: {{0}} \nUsername: {{1}}\nPassword: {{2}}", // Parameters: site address, username, password
  68. "configurationreceived", "Ready",
  69. "configdatamissing", "ERROR: some required data was missing from the configuration {{0}}",
  70. "readingconfignotecard", "Reading configuration notecard...",
  71. "checkingcourse", "Checking course...",
  72. "errortouchtoreset", "ERROR\nTouch me to reset",
  73. "notconfiguredyet", "Sorry {{0}}. I am not configured yet.", // Parameter: avatar name
  74. "resetting", "Resetting...",
  75. "noconfigavailable", "There is no configuration available to download. Please visit the configuration web-page first.",
  76. "checkingauth", "Checking authorisation...",
  77. "usedescriptioninstead", "If you can't see the shared media screen, please enter your Moodle URL (http://...) in the description field of the rezzer and press \"Reset\"",
  78. "openrezzerurl", "Click the URL below to open the rezzer screen in your browser: \n{{0}}",
  79. // Sloodle installation/version
  80. "sloodlenotinstalled", "ERROR: Sloodle is not installed on specified site.",
  81. "sloodleversioninstalled", "Sloodle version installed on server: {{0}}", // Parameter gives a Sloodle version number
  82. "sloodleversionrequired", "ERROR: you require at least Sloodle version {{0}}", // Parameter gives a Sloodle version number
  83. // Permissions
  84. "nopermission:use", "Sorry {{0}}. You do not have permission to use this object.", // Parameter should be the name of an avatar
  85. "nopermission:ctrl", "Sorry {{0}}. You do not have permission to control this object.", // Parameter should be the name of an avatar
  86. "nopermission:authobjects", "Sorry {{0}}. You do not have permission to authorise objects on this course.", // Parameter should be the name of an avatar
  87. // Layout (duplicated deliberately)
  88. "layout:failedretrying", "Failed to store layout position. Retrying...",
  89. "layout:failedaborting", "Failed to store layout position. Aborting.",
  90. "layout:toofar", "Failed to store layout position - too far from rezzer.",
  91. "layout:storedobject", "Object stored in layout.",
  92. // General error
  93. "sloodleerror", "SLOODLE error ({{0}}): please lookup SLOODLE wiki for error information", // Parameters: status code of error
  94. "sloodleerror:desc", "SLOODLE error ({{0}}): {{1}}" // Parameters: status code of error, text description of error
  95. ];
  96. ///// ----------- /////
  97. // Link message channels
  98. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  99. integer SLOODLE_CHANNEL_TRANSLATION_RESPONSE = -1928374652;
  100. // Translation output methods
  101. string SLOODLE_TRANSLATE_LINK = "link"; // No output parameters - simply returns the translation on SLOODLE_TRANSLATION_RESPONSE link message channel
  102. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  103. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  104. string SLOODLE_TRANSLATE_SHOUT = "shout"; // 1 output parameter: chat channel number
  105. string SLOODLE_TRANSLATE_REGION_SAY = "regionsay"; // 1 output parameter: chat channel number
  106. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  107. string SLOODLE_TRANSLATE_DIALOG = "dialog"; // Recipient avatar should be identified in link message keyval. At least 2 output parameters: first the channel number for the dialog, and then 1 to 12 button label strings.
  108. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  109. string SLOODLE_TRANSLATE_LOAD_URL_PARALLEL = "loadurlpar"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  110. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  111. string SLOODLE_TRANSLATE_HOVER_TEXT_LINKED_PRIM= "hovertext_linked_prim"; // 3 output parameters: colour <r,g,b>, alpha value, link number
  112. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  113. string SLOODLE_TRANSLATE_TEXTBOX="textbox";//asks via a text box
  114. // Used for sending parallel URL loading messages
  115. integer SLOODLE_CHANNEL_OBJECT_LOAD_URL = -1639270041;
  116. ///// FUNCTIONS /////
  117. // Send a translation request link message
  118. // (Here for reference only)
  119. // Parameter: output_method = should identify an output method, as given by the "SLOODLE_TRANSLATE_..." constants above
  120. // Parameter: output_params = a list of parameters which controls the output, such as chat channel or buttons for a dialog
  121. // Parameter: string_name = the name of the localization string to output
  122. // Parameter: string_params = a list of parameters which will be included in the translated string (or an empty list if none)
  123. // Parameter: keyval = a key to send in the link message
  124. // Parameter: batch = the name of the localization batch which should handle this request
  125. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  126. {
  127. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  128. }
  129. // Send a translation response link message
  130. sloodle_translation_response(integer target, string name, string translation)
  131. {
  132. llMessageLinked(target, SLOODLE_CHANNEL_TRANSLATION_RESPONSE, name + "|" + translation + "|" + mybatch, NULL_KEY);
  133. }
  134. // Get the translation of a particular string
  135. string sloodle_get_string(string name)
  136. {
  137. // Attempt to find the string name
  138. integer numstrings = llGetListLength(locstrings);
  139. integer pos = llListFindList(locstrings, [name]);
  140. // IMPORTANT: we must be careful not to match a translations instead of a name.
  141. // If this was an even number, then we have a string name.
  142. if ((pos % 2) == 0) {
  143. // Make sure there is a subsequent translation in the list
  144. if ((pos + 1) < numstrings) return llList2String(locstrings, pos + 1);
  145. // The translation is not there
  146. pos = -1;
  147. }
  148. // If we could not find the string, then return a placeholder
  149. if (pos < 0) return "[[" + name + "]]";
  150. // If we got here, then we matched a translation instead of a string name.
  151. // As such, we need to resort to searching through the list manually (which can be very slow).
  152. // To saved time, we can start from the position just beyond where we got to.
  153. // We advance by 2 each time to skip the translations completely.
  154. //pos += 1;
  155. for (pos += 1; pos < numstrings; pos += 2) {
  156. // Do we have a match?
  157. if (llList2String(locstrings, pos) == name) {
  158. // Yes - make sure there is a translation following it
  159. if ((pos + 1) < numstrings) return llList2String(locstrings, pos + 1);
  160. // The translation is not there - skip the rest of the search
  161. pos = numstrings;
  162. }
  163. }
  164. // If we reached this point, then the string is not available. Return a placeholder.
  165. return "[[" + name + "]]";
  166. }
  167. // Send a debug link message
  168. sloodle_debug(string msg)
  169. {
  170. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  171. }
  172. // Get a formatted translation of a string
  173. string sloodle_get_string_f(string name, list params)
  174. {
  175. // Get the string itself
  176. string str = sloodle_get_string(name);
  177. // How many parameters do we have?
  178. integer numparams = llGetListLength(params);
  179. // Go through each parameter we have been provided
  180. integer curparamnum;
  181. string curparamtok = "{{x}}";
  182. integer curparamtoklength = 0;
  183. string curparamstr = "";
  184. integer tokpos = -1;
  185. for (curparamnum=0; curparamnum < numparams; curparamnum++) {
  186. // Construct this parameter token
  187. curparamtok = "{{" + (string)(curparamnum) + "}}";
  188. curparamtoklength = llStringLength(curparamtok);
  189. // Fetch the parameter text
  190. curparamstr = llList2String(params, curparamnum);
  191. // Ensure the parameter text does NOT contain double braces (this avoids an infinite loop!)
  192. if (llSubStringIndex(curparamstr, "{{") < 0 && llSubStringIndex(curparamstr, "}}") < 0) {
  193. // Go through every instance of this parameter's token
  194. while ((tokpos = llSubStringIndex(str, curparamtok)) >= 0) {
  195. // Replace the token with the parameter string
  196. str = llDeleteSubString(str, tokpos, tokpos + curparamtoklength - 1);
  197. str = llInsertString(str, tokpos, curparamstr);
  198. }
  199. }
  200. }
  201. return str;
  202. }
  203. ///// STATES /////
  204. default
  205. {
  206. state_entry()
  207. {
  208. }
  209. link_message(integer sender_num, integer num, string str, key id)
  210. {
  211. // Check the channel
  212. if (num == SLOODLE_CHANNEL_TRANSLATION_REQUEST) {
  213. // // PROCESS REQUEST // //
  214. // Split the incoming message into fields
  215. list fields = llParseStringKeepNulls(str, ["|"], []);
  216. integer numfields = llGetListLength(fields);
  217. // Extract and check the localization batch
  218. string batch = "";
  219. if (numfields > 4) batch = llList2String(fields, 4);
  220. if (batch != mybatch) return;
  221. // We expect at least 3 fields
  222. // ... or 4 if there are insertion parameters...
  223. // ... anybody up for a 6th parameter? :)
  224. if (numfields < 3) {
  225. sloodle_debug("ERROR: Insufficient fields for translation of string.");
  226. return;
  227. }
  228. // Extract the key parts of the request
  229. string output_method = llList2String(fields, 0);
  230. list output_params = llCSV2List(llList2String(fields, 1));
  231. integer num_output_params = llGetListLength(output_params);
  232. string string_name = llList2String(fields, 2);
  233. list string_params = [];
  234. if (numfields > 3) {
  235. // Extract the string parameters (extra text added to the output)
  236. string string_param_text = llList2String(fields, 3);
  237. if (string_param_text != "") string_params = llCSV2List(string_param_text);
  238. }
  239. // // TRANSLATE STRING // //
  240. // This string will store the translation
  241. string trans = "";
  242. // Do nothing if the string name is empty
  243. if (string_name != "") {
  244. // If there are no string parameters, then it is only a basic translation
  245. if (llGetListLength(string_params) == 0) {
  246. // Get the basic translation
  247. trans = sloodle_get_string(string_name);
  248. } else {
  249. // Construct the formatted string
  250. trans = sloodle_get_string_f(string_name, string_params);
  251. }
  252. }
  253. // // OUTPUT STRING // //
  254. // Check what output method has been requested
  255. if (output_method == SLOODLE_TRANSLATE_LINK) {
  256. // Return the string via link message
  257. sloodle_translation_response(sender_num, string_name, trans);
  258. } else if (output_method == SLOODLE_TRANSLATE_SAY) {
  259. // Say the string
  260. if (num_output_params > 0) llSay(llList2Integer(output_params, 0), trans);
  261. else sloodle_debug("ERROR: Insufficient output parameters to say string \"" + string_name + "\".");
  262. } else if (output_method == SLOODLE_TRANSLATE_WHISPER) {
  263. // Whisper the string
  264. if (num_output_params > 0) llWhisper(llList2Integer(output_params, 0), trans);
  265. else sloodle_debug("ERROR: Insufficient output parameters to whisper string \"" + string_name + "\".");
  266. } else if (output_method == SLOODLE_TRANSLATE_SHOUT) {
  267. // Shout the string
  268. if (num_output_params > 0) llShout(llList2Integer(output_params, 0), trans);
  269. else sloodle_debug("ERROR: Insufficient output parameters to shout string \"" + string_name + "\".");
  270. } else if (output_method == SLOODLE_TRANSLATE_REGION_SAY) {
  271. // RegionSay the string
  272. if (num_output_params > 0) llRegionSay(llList2Integer(output_params, 0), trans);
  273. else sloodle_debug("ERROR: Insufficient output parameters to region-say string \"" + string_name + "\".");
  274. } else if (output_method == SLOODLE_TRANSLATE_OWNER_SAY) {
  275. // Ownersay the string
  276. llOwnerSay(trans);
  277. } else if (output_method == SLOODLE_TRANSLATE_DIALOG) {
  278. // Display a dialog - we need a valid key
  279. if (id == NULL_KEY) {
  280. sloodle_debug("ERROR: Non-null key value required to show dialog with string \"" + string_name + "\".");
  281. return;
  282. }
  283. // We need at least 2 additional output parameters (channel, and at least 1 button)
  284. if (num_output_params >= 2) {
  285. // Extract the channel number
  286. integer channel = llList2Integer(output_params, 0);
  287. // Extract up to 12 button values
  288. list buttons = llList2List(output_params, 1, 12);
  289. // Display the dialog
  290. llDialog(id, trans, buttons, channel);
  291. } else sloodle_debug("ERROR: Insufficient output parameters to show dialog with string \"" + string_name + "\".");
  292. } else if (output_method == SLOODLE_TRANSLATE_LOAD_URL) {
  293. // Display a URL - we need a valid key
  294. if (id == NULL_KEY) {
  295. sloodle_debug("ERROR: Non-null key value required to load URL with string \"" + string_name + "\".");
  296. return;
  297. }
  298. // We need 1 additional parameter, containing the URL to load
  299. if (num_output_params >= 1) llLoadURL(id, trans, llList2String(output_params, 0));
  300. else sloodle_debug("ERROR: Insufficient output parameters to load URL with string \"" + string_name + "\".");
  301. } else if (output_method == SLOODLE_TRANSLATE_LOAD_URL_PARALLEL) {
  302. // Display a URL - we need a valid key
  303. if (id == NULL_KEY) {
  304. sloodle_debug("ERROR: Non-null key value required to load URL with string \"" + string_name + "\".");
  305. return;
  306. }
  307. // NOTE: currently the parallel URL loaders will drop any text.
  308. // TODO: make parallel URL loaders use text as well.
  309. // We need 1 additional parameter, containing the URL to load
  310. if (num_output_params >= 1) llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_LOAD_URL, llList2String(output_params, 0), id);
  311. else sloodle_debug("ERROR: Insufficient output parameters to load URL with string \"" + string_name + "\".");
  312. } else if (output_method == SLOODLE_TRANSLATE_HOVER_TEXT) {
  313. //example usage: sloodle_translation_request(SLOODLE_TRANSLATE_HOVER_TEXT, [BLUE, 1.0], "quizname", [quiz_name], llGetOwner(), "quizzer");
  314. // We need 1 additional parameter, containing the URL to load
  315. if (num_output_params >= 2) llSetText(trans, (vector)llList2String(output_params, 0), (float)llList2String(output_params, 1));
  316. else sloodle_debug("ERROR: Insufficient output parameters to show hover text with string \"" + string_name + "\".");
  317. } else if (output_method == SLOODLE_TRANSLATE_HOVER_TEXT_LINKED_PRIM) {
  318. //example usage: sloodle_translation_request(SLOODLE_TRANSLATE_HOVER_TEXT_LINKED_PRIM, [BLUE, 1.0,7], "quizname", [quiz_name], llGetOwner(), "quizzer");
  319. // We need 1 additional parameter, containing the URL to load
  320. if (num_output_params >= 3) {
  321. list rules = [ PRIM_TEXT, trans, (vector)llList2String(output_params, 0), (float)llList2String(output_params, 1) ];
  322. llSetLinkPrimitiveParamsFast( llList2Integer(output_params, 2), rules );
  323. }
  324. else sloodle_debug("ERROR: Insufficient output parameters to show hover text with string \"" + string_name + "\". Expecting translation text, color vector, alpha float.");
  325. }
  326. else if (output_method == SLOODLE_TRANSLATE_IM) {
  327. // Send an IM - we need a valid key
  328. if (id == NULL_KEY) {
  329. sloodle_debug("ERROR: Non-null key value required to send IM with string \"" + string_name + "\".");
  330. return;
  331. }
  332. // Send the IM
  333. llInstantMessage(id, trans);
  334. } else {
  335. // Don't know the output method
  336. sloodle_debug("ERROR: unrecognised output method \"" + output_method + "\".");
  337. }
  338. }
  339. }
  340. }
  341. // Please leave the following line intact to show where the script lives in Git:
  342. // SLOODLE LSL Script Git Location: assets/lang/en/sloodle_translation_en.lslp