summaryrefslogtreecommitdiff
path: root/lib/exe/js.php
diff options
context:
space:
mode:
authorGabriel Birke <Gabriel.Birke@delti.com>2007-10-26 15:11:30 +0200
committerGabriel Birke <Gabriel.Birke@delti.com>2007-10-26 15:11:30 +0200
commit9f01cf6a532f98b10f726bbbac3228880f6c3d41 (patch)
treeced5342765aabd4318bbd18dccbc1be6718d6595 /lib/exe/js.php
parent279c0a2e9325ca2a3bdf36e8849d132c6ae51559 (diff)
downloadrpg-9f01cf6a532f98b10f726bbbac3228880f6c3d41.tar.gz
rpg-9f01cf6a532f98b10f726bbbac3228880f6c3d41.tar.bz2
Translatable JavaScript strings for plugins
Strings to be used in plugin provided JavaScript can now be put into the plugin's lang.php files. It has to be stored as subkeys of $lang['js']. Eg the following in lib/plugins/blah/lang/en/lang.php $lang['js']['foo'] darcs-hash:20071026131130-79ce3-75ab69b1ba527c823e0e5ef0fde031032aaa2548.gz
Diffstat (limited to 'lib/exe/js.php')
-rw-r--r--lib/exe/js.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/exe/js.php b/lib/exe/js.php
index 17f9c5ae1..c4fd81616 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -85,6 +85,9 @@ function js_out(){
print "var notSavedYet = '".js_escape($lang['notsavedyet'])."';";
print "var reallyDel = '".js_escape($lang['del_confirm'])."';";
+ // load JS strings form plugins
+ $lang['js']['plugins'] = js_pluginstrings();
+
// load JS specific translations
$json = new JSON();
echo 'LANG = '.$json->encode($lang['js']).";\n";
@@ -237,6 +240,34 @@ function js_pluginscripts(){
}
/**
+ * Return an two-dimensional array with strings from the language file of each plugin.
+ *
+ * - $lang['js'] must be an array.
+ * - Nothing is returned for plugins without an entry for $lang['js']
+ *
+ * @author Gabriel Birke <birke@d-scribe.de>
+ */
+function js_pluginstrings()
+{
+ global $conf;
+ $pluginstrings = array();
+ $plugins = plugin_list();
+ foreach ($plugins as $p){
+ if (isset($lang)) unset($lang);
+ if (@file_exists(DOKU_PLUGIN."$p/lang/en/lang.php")) {
+ include DOKU_PLUGIN."$p/lang/en/lang.php";
+ }
+ if (isset($conf['lang']) && $conf['lang']!='en' && @file_exists(DOKU_PLUGIN."$p/lang/".$conf['lang']."/lang.php")) {
+ include DOKU_PLUGIN."$p/lang/".$conf['lang']."/lang.php";
+ }
+ if (isset($lang['js'])) {
+ $pluginstrings[$p] = $lang['js'];
+ }
+ }
+ return $pluginstrings;
+}
+
+/**
* Escapes a String to be embedded in a JavaScript call, keeps \n
* as newline
*