User Tools

Site Tools


dev:plugin:core

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

dev:plugin:core [2013/02/24 18:27]
reaby
dev:plugin:core [2013/07/17 10:08] (current)
Line 11: Line 11:
 </​code>​ </​code>​
  
-Function for all localized messages is **_**(), that is defined in BasicPlugin class, which registers the function to general namespace. Core plugin handles loading and setting the default language. +Function for all localized messages is <​code>​__()</​code>​, that is defined in BasicPlugin class, which registers the function to general namespace. Core plugin handles loading and setting the default language. 
-When invoked, the _() function then calls the i18n singleton and passes all parameters to sprintf which formats the text.+When invoked, the <​code>​__()</​code> ​function then calls the i18n singleton and passes all parameters to sprintf which formats the text.
  
 To use multiple language support, just do this: To use multiple language support, just do this:
 <code php> <code php>
-_("your string to display goes here"​);​ // string without parameters+__("your string to display goes here", $login); // string without parameters, with the login tho whom you will display the message
  
-_("​admin %s kicked the player %s", $admin, $player); // string with parameters+__("​admin %s kicked the player %s", $login, $admin, $player); // string with parameters ​and with the login tho whom you will display the message
 </​code>​ </​code>​
  
 +Even if this method is good, it might be slow, The Core will need to search for translations of the text. Ideally you should do that once. 
 +You can improve by simply doing this : 
 +<code php>
 +public static $msg_needBeAdmin;​
 +public static $msg_adminkicked;​
 +public function exp_onLoad() {
 +        self::​$msg_needBeAdmin= exp_getMessage('#​admin_error#​You need to be an Admin to use that command'​);​
 +        self::​$msg_adminkicked = exp_getMessage("​admin %s kicked the player %s");
 +        //More stuff
 +}
 +</​code>​
 +exp_getMessage will return an object containing all the translations of the text. That way you wan't need to search for them again. Then you use it just like before
  
 +<code php>
 +__(self::​$msg_needBeAdmin,​ $login); // string without parameters, with the login tho whom you will display the message
 +
 +__(self::​$msg_adminkicked,​ $login, $admin, $player); // string with parameters and with the login tho whom you will display the message
 +</​code>​
 ==== Color Codes ==== ==== Color Codes ====
  
dev/plugin/core.txt · Last modified: 2013/07/17 10:08 (external edit)