User Tools

Site Tools


plugins:creation

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
plugins:creation [2014/02/07 09:51]
datiswous [Additional plugin files]
plugins:creation [2017/01/18 17:25]
lokothodida
Line 140: Line 140:
  
 Thus a sample plugin structure for a plugin ''​my_plugin''​ with additional php files and images that supports multiple languages might be: Thus a sample plugin structure for a plugin ''​my_plugin''​ with additional php files and images that supports multiple languages might be:
-<​code ​ini>+<​code>​
 - my_plugin.php - my_plugin.php
 - my_plugin (directory) - my_plugin (directory)
Line 155: Line 155:
       - delete.png       - delete.png
       - edit.png       - edit.png
 +</​code>​
 +
 +==== Internationalization (I18N) ====
 +If your plugin displays messages to your user/​administrator,​ you will want to allow those messages to be localised to the language of the installation. You do this by having a ''/​lang''​ folder, which has PHP files for each language:
 +
 +<​code>​
 + - lang (directory)
 +    - .htaccess (with one line: Deny from all)
 +    - en_US.php
 +    - de_DE.php
 +    - it_IT.php
 +</​code>​
 +
 +Each file should have one variable: an ''​$i18n''​ array, which has ''​key => value''​ mappings for the various messages:
 +
 +<code php>
 +<?php
 +// en_US.php
 +$i18n = array();
 +$i18n['​PLUGIN_TITLE'​] = 'My Plugin';​
 +...
 +</​code>​
 +
 +To register your i18n array, call ''​i18n_merge''​ with the ID of your plugin (**before the plugin is registered**):​
 +
 +<code php>
 +i18n_merge($plugin_id);​
 +</​code>​
 +
 +This registers ''​$i18n''​ for your plugin with the installation'​s language, but you might not have such a language file created. In order to set up a default language, you can register a fixed language if ''​i18n_merge''​ returns ''​false''​.
 +
 +<code php>
 +// Sets the default to English
 +if (!i18n_merge($plugin_id)) i18n_merge($plugin_id,​ '​en_US'​);​
 +</​code>​
 +
 +Or the clearer:
 +
 +<code php>
 +i18n_merge($plugin_id) || i18n_merge($plugin_id,​ '​en_US'​);​
 +</​code>​
 +
 +Once that is done, you can call a localised string by using ''​i18n_r''​ (to ''​return''​ the string) or ''​i18n''​ (to ''​echo''​ it). You do this by prefixing your key with your plugin'​s ID:
 +
 +<code php>
 +// Prints "My Plugin"​ if the language is English
 +i18n($plugin_id . '/​PLUGIN_TITLE'​);​
 </​code>​ </​code>​
  
plugins/creation.txt ยท Last modified: 2017/01/19 22:08 by lokothodida