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/23 18:35]
oliverde8
dev:plugin:core [2013/07/17 10:08] (current)
Line 1: Line 1:
-This plugin is required by all plugins part of the **eXpansion** pack. This plugin doesen'​t have a lot to do it basically has main roles +This plugin is required by all plugins part of the **eXpansion** pack. This plugin doesen'​t have a lot to do it basically has main roles 
  
 ====== Roles ====== ====== Roles ======
Line 5: Line 5:
 ===== Load Configuration ===== ===== Load Configuration =====
  
 +==== Multiple Language Support (i18n) ====
 +If you are hosting a server for specific language, you can enable the new default language in config file:
 +<​code>​
 +ManiaLivePlugins\eXpansion\Core\Config.defaultLanguage = language
 +</​code>​
 +
 +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 <​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:
 +<code php>
 +__("​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", $login, $admin, $player); // string with parameters and with the login tho whom you will display the message
 +</​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.1361640949.txt.gz ยท Last modified: 2013/07/17 10:08 (external edit)