User Tools

Site Tools


plugins:i18n

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
plugins:i18n [2013/04/19 15:04]
127.0.0.1 external edit
plugins:i18n [2016/06/30 19:29] (current)
mvlcek [Multi-language 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 83: Line 83:
 If your plugin has to display texts on the front-end (the internet site itself) and you just support typical GetSimple installations,​ where the content is displayed in one language and the admin back-end is set to this language, you do it the same way as described above. If your plugin has to display texts on the front-end (the internet site itself) and you just support typical GetSimple installations,​ where the content is displayed in one language and the admin back-end is set to this language, you do it the same way as described above.
  
-The only difference is that you must provide language support, because where it might be acceptable for administrators and editors to see some information in english instead of their own language, it is unacceptable on the front-end. Without language support you basically limit your plugin to use in countries with the same language as your's.+The only difference is that you must provide language support, because where it might be acceptable for administrators and editors to see some information in english instead of their own language, it is unacceptable on the front-end. Without language support you basically limit your plugin to use in countries with the same language as yours.
  
 **GetSimple 3.0:** **GetSimple 3.0:**
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'​);​
Line 126: Line 126:
 Note: The I18N plugin currently only supports language codes without country, so you must have language files like ''​en.php'',​ ''​de.php''​ etc. instead of ''​en_US.php'',​ etc. Note: The I18N plugin currently only supports language codes without country, so you must have language files like ''​en.php'',​ ''​de.php''​ etc. instead of ''​en_US.php'',​ etc.
  
 +NOte: The I18N plugin'​s current i18n_load_texts function might not be perfect yet. For a complete guide to using language files in the frontend, check out http://​get-simple.info/​forums/​showthread.php?​tid=1221&​pid=56863#​pid56863
plugins/i18n.1366383886.txt.gz ยท Last modified: 2014/02/13 13:12 (external edit)