fixed translations on client-side: server sends now currentapp and langRequire to client, which uses that to translate phrases, langRequire is only stored in egw object for matching app-name and window!

This commit is contained in:
Ralf Becker 2013-10-07 17:00:03 +00:00
parent a6311fa1a3
commit 0bb8093426
5 changed files with 55 additions and 27 deletions

View File

@ -127,6 +127,25 @@ class etemplate_new extends etemplate_widget_template
// some apps (eg. InfoLog) set app_header only in get_rows depending on filter settings // some apps (eg. InfoLog) set app_header only in get_rows depending on filter settings
self::$request->app_header = $GLOBALS['egw_info']['flags']['app_header']; self::$request->app_header = $GLOBALS['egw_info']['flags']['app_header'];
// compile required translations translations
translation::add_app('etemplate');
$currentapp = $GLOBALS['egw_info']['flags']['currentapp'];
$langRequire = array('common' => array(), 'etemplate' => array()); // keep that order
foreach(translation::$loaded_apps as $l_app => $lang)
{
if (!in_array($l_app, array($currentapp, 'custom')))
{
$langRequire[$l_app] = array('app' => $l_app, 'lang' => $lang);
}
}
foreach(array($currentapp, 'custom') as $l_app)
{
if (isset(translation::$loaded_apps[$l_app]))
{
$langRequire[$l_app] = array('app' => $l_app, 'lang' => translation::$loaded_apps[$l_app]);
}
}
$data = array( $data = array(
'etemplate_exec_id' => self::$request->id(), 'etemplate_exec_id' => self::$request->id(),
'app_header' => self::$request->app_header, 'app_header' => self::$request->app_header,
@ -135,6 +154,8 @@ class etemplate_new extends etemplate_widget_template
'readonlys' => self::$request->readonlys, 'readonlys' => self::$request->readonlys,
'modifications' => self::$request->modifications, 'modifications' => self::$request->modifications,
'validation_errors' => self::$validation_errors, 'validation_errors' => self::$validation_errors,
'langRequire' => array_values($langRequire),
'currentapp' => $currentapp,
); );
// Info required to load the etemplate client-side // Info required to load the etemplate client-side
@ -143,7 +164,7 @@ class etemplate_new extends etemplate_widget_template
'name' => $this->name, 'name' => $this->name,
'url' => $GLOBALS['egw_info']['server']['webserver_url'].$this->rel_path, 'url' => $GLOBALS['egw_info']['server']['webserver_url'].$this->rel_path,
'data' => $data, 'data' => $data,
'DOMNodeID' => $dom_id 'DOMNodeID' => $dom_id,
); );
if (self::$response) // call is within an ajax event / form submit if (self::$response) // call is within an ajax event / form submit
{ {
@ -168,15 +189,6 @@ class etemplate_new extends etemplate_widget_template
egw_framework::validate_file('.','app',$app,false); egw_framework::validate_file('.','app',$app,false);
} }
// load translations
translation::add_app('etemplate');
$langRequire = array();
foreach(translation::$loaded_apps as $l_app => $lang)
{
$langRequire[] = array('app' => $l_app, 'lang' => $lang);
}
$header = $GLOBALS['egw']->framework->header(array( $header = $GLOBALS['egw']->framework->header(array(
'etemplate' => $load_array 'etemplate' => $load_array
)); ));

View File

@ -81,14 +81,6 @@ var et2_template = et2_DOMWidget.extend(
{ {
var template_name = this.options.template || this.id; var template_name = this.options.template || this.id;
// Set the api instance to the first part of the name of the
// template, if it's in app.function.template format
var splitted = template_name.split('.');
if(splitted.length >= 3)
{
this.setApiInstance(egw(splitted[0], this._parent.egw().window));
}
// Check to see if XML is known // Check to see if XML is known
var xml = null; var xml = null;
var templates = this.getRoot().getInstanceManager().templates; var templates = this.getRoot().getInstanceManager().templates;
@ -98,7 +90,7 @@ var et2_template = et2_DOMWidget.extend(
// eg: row instead of app.something.row // eg: row instead of app.something.row
for(var key in templates) for(var key in templates)
{ {
splitted = key.split('.'); var splitted = key.split('.');
if(splitted[splitted.length-1] == template_name) if(splitted[splitted.length-1] == template_name)
{ {
xml = templates[key]; xml = templates[key];
@ -108,7 +100,7 @@ var et2_template = et2_DOMWidget.extend(
if(!xml) if(!xml)
{ {
// Ask server // Ask server
splitted = template_name.split('.'); var splitted = template_name.split('.');
var path = this.egw().webserverUrl + "/" + splitted.shift() + "/templates/default/" + splitted.join('.') + ".xet"; var path = this.egw().webserverUrl + "/" + splitted.shift() + "/templates/default/" + splitted.join('.') + ".xet";
if(splitted.length) if(splitted.length)

View File

@ -189,8 +189,14 @@ etemplate2.prototype._createArrayManagers = function(_data)
*/ */
etemplate2.prototype.load = function(_name, _url, _data, _callback) etemplate2.prototype.load = function(_name, _url, _data, _callback)
{ {
egw().debug("info", "Loaded data", _data); egw().debug("info", "Loaded data", _data);
var currentapp = _data.currentapp || window.egw_appName;
// require necessary translations from server, if not already loaded
if ($j.isArray(_data.langRequire))
{
egw(currentapp, window).langRequire(window, _data.langRequire);
}
// Appname should be first part of the template name // Appname should be first part of the template name
var split = _name.split('.'); var split = _name.split('.');
@ -221,7 +227,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
// Create the basic widget container and attach it to the DOM // Create the basic widget container and attach it to the DOM
this.widgetContainer = new et2_container(null); this.widgetContainer = new et2_container(null);
this.widgetContainer.setApiInstance(egw(appname, egw.elemWindow(this.DOMContainer))); this.widgetContainer.setApiInstance(egw(currentapp, egw.elemWindow(this.DOMContainer)));
this.widgetContainer.setInstanceManager(this); this.widgetContainer.setInstanceManager(this);
this.widgetContainer.setParentDOMNode(this.DOMContainer); this.widgetContainer.setParentDOMNode(this.DOMContainer);
@ -265,7 +271,6 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
}; };
// Load & process // Load & process
if(!this.templates[_name]) if(!this.templates[_name])
{ {
@ -643,6 +648,12 @@ function etemplate2_handle_load(_type, _response)
window.focus(); window.focus();
} }
// handle framework.setSidebox calls
if (window.framework && jQuery.isArray(data['setSidebox']))
{
window.framework.setSidebox.apply(window, JSON.parse(data['setSidebox']));
}
// regular et2 re-load // regular et2 re-load
if (typeof data.url == "string" && typeof data.data === 'object') if (typeof data.url == "string" && typeof data.data === 'object')
{ {

View File

@ -331,10 +331,13 @@ class translation
//error_log(__METHOD__."('$app', '$lang') caching now ".(is_array($loaded)?'Array('.count($loaded).')':array2string($loaded))." egw_cache::setCache() returned ".array2string($ok)); //error_log(__METHOD__."('$app', '$lang') caching now ".(is_array($loaded)?'Array('.count($loaded).')':array2string($loaded))." egw_cache::setCache() returned ".array2string($ok));
} }
} }
if ($loaded) self::$lang_arr = array_merge(self::$lang_arr, $loaded); if ($loaded)
self::$loaded_apps[$app] = $l; {
self::$lang_arr = array_merge(self::$lang_arr, $loaded);
self::$loaded_apps[$app] = $l; // dont set something not existing to $loaded_apps, no need to load client-side
}
} }
//error_log(__METHOD__.'('.array2string($apps).", '$lang') took ".(1000*(microtime(true)-$start))." ms, loaded ".count($loaded)." phrases -> total=".count(self::$lang_arr));//.": ".function_backtrace()); //error_log(__METHOD__.'('.array2string($apps).", '$lang') took ".(1000*(microtime(true)-$start))." ms, loaded_apps=".array2string(self::$loaded_apps).", loaded ".count($loaded)." phrases -> total=".count(self::$lang_arr));//.": ".function_backtrace());
} }
/** /**

View File

@ -18,6 +18,9 @@
egw_ready; egw_ready;
*/ */
/**
* @augments Class
*/
egw.extend('lang', egw.MODULE_GLOBAL, function() { egw.extend('lang', egw.MODULE_GLOBAL, function() {
/** /**
@ -34,6 +37,7 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
* *
* @param string _app * @param string _app
* @param object _message message => translation pairs * @param object _message message => translation pairs
* @memberOf egw
*/ */
set_lang_arr: function(_app, _messages) set_lang_arr: function(_app, _messages)
{ {
@ -60,7 +64,7 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
_msg = _msg.toLowerCase(); _msg = _msg.toLowerCase();
// search apps in given order for a replacement // search apps in given order for a replacement
var apps = ['custom', this.getAppName(), 'etemplate', 'common']; var apps = this.lang_order || ['custom', this.getAppName(), 'etemplate', 'common'];
for(var i = 0; i < apps.length; ++i) for(var i = 0; i < apps.length; ++i)
{ {
if (typeof lang_arr[apps[i]] != "undefined" && if (typeof lang_arr[apps[i]] != "undefined" &&
@ -105,6 +109,7 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
// Build the file names which should be included // Build the file names which should be included
var jss = []; var jss = [];
var apps = [];
for (var i = 0; i < _apps.length; i++) for (var i = 0; i < _apps.length; i++)
{ {
if (typeof lang_arr[_apps[i].app] === "undefined") if (typeof lang_arr[_apps[i].app] === "undefined")
@ -113,6 +118,11 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
+ '/phpgwapi/lang.php?app=' + '/phpgwapi/lang.php?app='
+ _apps[i].app + '&lang=' + _apps[i].lang); + _apps[i].app + '&lang=' + _apps[i].lang);
} }
apps.push(_apps[i].app);
}
if (this !== egw)
{
this.lang_order = apps.reverse();
} }
// Only continue if we need to include a language // Only continue if we need to include a language