This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
plugins:i18n [2014/02/13 13:12] Carlos [Front-end] typo |
plugins:i18n [2016/06/28 09:50] datiswous [Front-end] |
||
---|---|---|---|
Line 3: | Line 3: | ||
If you display texts in your plugin, the easiest way is hardcode the texts in your plugin, e.g.: | If you display texts in your plugin, the easiest way is hardcode the texts in your plugin, e.g.: | ||
- | <code> | + | <code php> |
<input type="submit" name="save" value="Save Settings"/> | <input type="submit" name="save" value="Save Settings"/> | ||
</code> | </code> | ||
Line 11: | Line 11: | ||
The easiest way is to reuse the translations of GetSimple itself. They can be found in the directory ''/path_to_getsimple/admin/lang'' and downloaded from [[http://get-simple.info/extend/|Extend]]. In our example you could use the key BTN_SAVESETTINGS: | The easiest way is to reuse the translations of GetSimple itself. They can be found in the directory ''/path_to_getsimple/admin/lang'' and downloaded from [[http://get-simple.info/extend/|Extend]]. In our example you could use the key BTN_SAVESETTINGS: | ||
- | <code> | + | <code php> |
<input type="submit" name="save" value="<?php i18n("BTN_SAVESETTINGS"); ?>"/> | <input type="submit" name="save" value="<?php i18n("BTN_SAVESETTINGS"); ?>"/> | ||
</code> | </code> | ||
Line 17: | Line 17: | ||
If your plugin also supports GetSimple 2.03, you would rather have to use: | If your plugin also supports GetSimple 2.03, you would rather have to use: | ||
- | <code> | + | <code php> |
<?php global $i18n; ?> | <?php global $i18n; ?> | ||
<input type="submit" name="save" value="<?php $i18n["BTN_SAVESETTINGS"]; ?>"/> | <input type="submit" name="save" value="<?php $i18n["BTN_SAVESETTINGS"]; ?>"/> | ||
Line 26: | Line 26: | ||
If you need additional texts not found in the standard GetSimple translation files, you need to create translation files yourself. They should look like the GetSimple translation files, e.g. de_DE.php: | If you need additional texts not found in the standard GetSimple translation files, you need to create translation files yourself. They should look like the GetSimple translation files, e.g. de_DE.php: | ||
- | <code> | + | <code php> |
$i18n = array( | $i18n = array( | ||
'BTN_SAVEMYSETTINGS' => 'Meine Einstellungen speichern', | 'BTN_SAVEMYSETTINGS' => 'Meine Einstellungen speichern', | ||
Line 48: | Line 48: | ||
GetSimple 3.0 makes it easy to load these texts in your plugin, e.g.: | GetSimple 3.0 makes it easy to load these texts in your plugin, e.g.: | ||
- | <code> | + | <code php> |
i18n_merge('my_plugin') || i18n_merge('my_plugin','en_US'); | i18n_merge('my_plugin') || i18n_merge('my_plugin','en_US'); | ||
</code> | </code> | ||
Line 56: | Line 56: | ||
You then access them in the same way as standard GetSimple texts, but add your plugin name as prefix to the key, e.g. | You then access them in the same way as standard GetSimple texts, but add your plugin name as prefix to the key, e.g. | ||
- | <code> | + | <code php> |
<input type="submit" name="save" value="<?php i18n("my_plugin/BTN_SAVEMYSETTINGS"); ?>"/> | <input type="submit" name="save" value="<?php i18n("my_plugin/BTN_SAVEMYSETTINGS"); ?>"/> | ||
</code> | </code> | ||
Line 62: | Line 62: | ||
Note that //i18n()// echos the translation. If you need to use the translated text in php code you will have to use //i18n_r()// to return the string rather than echoing it, e.g. | Note that //i18n()// echos the translation. If you need to use the translated text in php code you will have to use //i18n_r()// to return the string rather than echoing it, e.g. | ||
- | <code> | + | <code php> |
$msg = '<div style="display: block;" class="updated">' . i18n_r("my_plugin/MSG_UPDATED") . '.</div>'; | $msg = '<div style="display: block;" class="updated">' . i18n_r("my_plugin/MSG_UPDATED") . '.</div>'; | ||
echo $msg; | echo $msg; | ||
Line 72: | Line 72: | ||
===== Language files without country ===== | ===== Language files without country ===== | ||
- | If you want to provide language files en.php, de.php, etc. (without country code), than use the following lines to load your texts: | + | If you want to provide language files en.php, de.php, etc. (without country code), then use the following lines to load your texts: |
- | <code> | + | <code php> |
global $LANG; | global $LANG; | ||
i18n_merge('my_plugin', substr($LANG,0,2)) || i18n_merge('my_plugin','en'); | i18n_merge('my_plugin', substr($LANG,0,2)) || i18n_merge('my_plugin','en'); | ||
Line 102: | Line 102: | ||
If your plugin should support multi-language sites using the I18N plugin, you must load the texts **only after the I18N initialization** (in the pretemplate hook) - in your function(s) that output text on the front end, with | If your plugin should support multi-language sites using the I18N plugin, you must load the texts **only after the I18N initialization** (in the pretemplate hook) - in your function(s) that output text on the front end, with | ||
- | <code> | + | <code php> |
global $LANG; | global $LANG; | ||
if (function_exists('i18n_load_texts')) { | if (function_exists('i18n_load_texts')) { | ||
Line 113: | Line 113: | ||
If you need back end template texts directly when loading the plugin, you need to check, if the plugin is loaded in the backend: | If you need back end template texts directly when loading the plugin, you need to check, if the plugin is loaded in the backend: | ||
- | <code> | + | <code php> |
if (basename($_SERVER['PHP_SELF']) != 'index.php') { // back end only - or do you know a better condition? | if (basename($_SERVER['PHP_SELF']) != 'index.php') { // back end only - or do you know a better condition? | ||
i18n_merge('my_plugin', substr($LANG,0,2)) || i18n_merge('my_plugin', 'en'); | i18n_merge('my_plugin', substr($LANG,0,2)) || i18n_merge('my_plugin', 'en'); |