aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/grum_plugins_classes-2/google_translate.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xplugins/grum_plugins_classes-2/google_translate.js56
1 files changed, 55 insertions, 1 deletions
diff --git a/plugins/grum_plugins_classes-2/google_translate.js b/plugins/grum_plugins_classes-2/google_translate.js
index 2798150e2..98b5507f5 100755
--- a/plugins/grum_plugins_classes-2/google_translate.js
+++ b/plugins/grum_plugins_classes-2/google_translate.js
@@ -12,7 +12,8 @@
------------------------------------------------------------------------------
HISTORY VERSION
- v2.0.0 +
+ v2.0.0 + adapted for piwigo
+ + add of a 5th&6th parameters for the google_translate function
-------------------------------------------------------------------------- */
@@ -21,15 +22,57 @@
var global_google_translate_plugin_objdest;
var global_google_translate_plugin_objproperty;
+ var global_google_translate_plugin_objcallback;
+ var global_google_translate_plugin_objcallback_param;
function google_translate(text, pfrom, pto, objdest, objproperty)
{
+ /*
+ ** args needed **
+ 1st arg : text to translate
+ 2nd arg : translate from lang ("en", "fr", "es", ...)
+ 3rd arg : translate to lang ("en", "fr", "es", ...)
+ 4th arg : target of result (id)
+ 5th arg : affected propertie ('value' or 'innerHTML')
+ ** facultative args **
+ 6th arg : pointer on a function definition (callback is made when
+ translation is done ; notice that translation is made asynchronous)
+ 7th arg : arg for the callback (or array of arg if callbakc need more than
+ one parameter)
+ */
+ if(arguments.length>=6)
+ {
+ global_google_translate_plugin_objcallback=arguments[5];
+ }
+ else
+ {
+ global_google_translate_plugin_objcallback=null;
+ }
+
+ if(arguments.length>=7)
+ {
+ if(arguments[6].pop)
+ {
+ global_google_translate_plugin_objcallback_param=arguments[6];
+ }
+ else
+ {
+ global_google_translate_plugin_objcallback_param=new Array(arguments[6]);
+ }
+ }
+ else
+ {
+ global_google_translate_plugin_objcallback_param=null;
+ }
+
+
global_google_translate_plugin_objdest = objdest;
global_google_translate_plugin_objproperty = objproperty;
google.language.translate(text, pfrom, pto, google_translate_do);
}
+
function google_translate_do(result)
{
if (!result.error)
@@ -42,6 +85,17 @@
{
global_google_translate_plugin_objdest.innerHTML = result.translation;
}
+ if(global_google_translate_plugin_objcallback!=null)
+ {
+ if(global_google_translate_plugin_objcallback_param!=null)
+ {
+ global_google_translate_plugin_objcallback.apply(null, global_google_translate_plugin_objcallback_param);
+ }
+ else
+ {
+ global_google_translate_plugin_objcallback();
+ }
+ }
}
}